Skip to content

Instantly share code, notes, and snippets.

@wppunk
Created February 27, 2021 16:25
Show Gist options
  • Save wppunk/717a9469b92dee200092ea157c19ad51 to your computer and use it in GitHub Desktop.
Save wppunk/717a9469b92dee200092ea157c19ad51 to your computer and use it in GitHub Desktop.
Make the Elementor as default editor
<?php
/**
* Make the Elementor as default editor.
*
* @since 1.0.0
* @author wppunk
* @link https://github.com/wppunk/
*/
namespace wppunk\Elementor;
/**
* Class DefaultEditor.
*
* @package wppunk\Elementor
*/
class DefaultEditor {
/**
* Hooks.
*/
public function hooks() {
add_filter( 'get_edit_post_link', [ $this, 'modify_edit_link' ], 1000, 3 );
add_filter( 'page_row_actions', [ $this, 'remove_quick_link' ], 1000 );
add_filter( 'post_row_actions', [ $this, 'remove_quick_link' ], 1000 );
}
/**
* Modify edit link.
*
* @param string $link The edit link.
* @param int $post_id Post ID.
* @param string $context The link context. If set to 'display' then ampersands are encoded.
*
* @return string
*/
public function modify_edit_link( $link, $post_id, $context ) {
if ( ! $link || 'display' !== $context || ! function_exists( 'get_post_type' ) ) {
return $link;
}
$post_type = get_post_type( $post_id );
$post_types_for_elementor = array_merge(
get_option( 'elementor_cpt_support', [ 'page', 'post' ] ),
[ 'elementor_library' ]
);
if ( ! in_array( $post_type, $post_types_for_elementor, true ) ) {
return $link;
}
return admin_url(
sprintf(
'post.php?post=%d&action=elementor',
absint( $post_id )
)
);
}
/**
* Remove the `Edit with Elementor` quick action.
*
* @param array $actions An array of row action links. Defaults are
* 'Edit', 'Quick Edit', 'Restore', 'Trash',
* 'Delete Permanently', 'Preview', and 'View'.
*
* @return array
*/
public function remove_quick_link( $actions ) {
unset( $actions['edit_with_elementor'] );
return $actions;
}
}
( new DefaultEditor() )->hooks();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment