namespace Elementor\Core\Admin;
use Elementor\Beta_Testers;
use Elementor\App\Modules\Onboarding\Module as Onboarding_Module;
use Elementor\Core\Base\App;
use Elementor\Core\Upgrade\Manager as Upgrade_Manager;
use Elementor\Core\Utils\Assets_Config_Provider;
use Elementor\Core\Utils\Collection;
use Elementor\Modules\FloatingButtons\Module as Floating_Buttons_Module;
use Elementor\Core\Utils\Hints;
use Elementor\Core\DocumentTypes\Page;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
class Admin extends App {
* Retrieve the module name.
* @return string Module name.
public function get_name() {
* Check if current page is an Elementor admin page.
* @param \WP_Screen|null $current_screen Optional. Screen object to check. Defaults to current screen.
* @return bool Whether current page is an Elementor admin page.
public static function is_elementor_admin_page( $current_screen = null ) {
if ( ! $current_screen ) {
$current_screen = get_current_screen();
if ( ! $current_screen ) {
$screen_id = $current_screen->id ?? '';
$post_type = $current_screen->post_type ?? '';
$is_elementor_screen = strpos( $screen_id, 'elementor' ) !== false
|| strpos( $screen_id, Floating_Buttons_Module::CPT_FLOATING_BUTTONS ) !== false;
$is_elementor_post_type = strpos( $post_type, 'elementor' ) !== false
|| strpos( $post_type, Floating_Buttons_Module::CPT_FLOATING_BUTTONS ) !== false;
return $is_elementor_screen || $is_elementor_post_type;
public function maybe_redirect_to_getting_started() {
if ( ! get_transient( 'elementor_activation_redirect' ) ) {
delete_transient( 'elementor_activation_redirect' );
if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
$already_had_onboarding = get_option( Onboarding_Module::ONBOARDING_OPTION );
// Get the latest installation from Elementor's Install log in the DB.
$latest_install = key( Upgrade_Manager::get_installs_history() );
if ( ! empty( $latest_install ) ) {
$is_new_install = version_compare( $latest_install, '3.6.0-beta', '>=' );
// If `$latest_install` is not set, Elementor was never installed on this site.
if ( $already_had_onboarding || ! $is_new_install ) {
wp_safe_redirect( admin_url( 'admin.php?page=elementor-app#onboarding' ) );
private function register_packages() {
$assets_config_provider = ( new Assets_Config_Provider() )
->set_path_resolver( function ( $name ) {
return ELEMENTOR_ASSETS_PATH . "js/packages/{$name}/{$name}.asset.php";
Collection::make( [ 'ui', 'icons', 'query' ] )
->each( function( $package ) use ( $assets_config_provider ) {
$suffix = Utils::is_script_debug() ? '' : '.min';
$config = $assets_config_provider->load( $package )->get( $package );
ELEMENTOR_ASSETS_URL . "js/packages/{$package}/{$package}{$suffix}.js",
* Registers all the admin scripts and enqueues them.
* Fired by `admin_enqueue_scripts` action.
public function enqueue_scripts() {
'elementor-admin-modules',
$this->get_js_assets_url( 'admin-modules' ),
$this->register_packages();
// Temporary solution for the admin.
$this->get_js_assets_url( 'ai-admin' ),
$this->get_js_assets_url( 'admin' ),
'elementor-admin-modules',
wp_enqueue_script( 'elementor-admin' );
wp_set_script_translations( 'elementor-admin', 'elementor' );
$this->maybe_enqueue_hints();
* Registers all the admin styles and enqueues them.
* Fired by `admin_enqueue_scripts` action.
public function enqueue_styles() {
$this->get_css_assets_url( 'admin' ),
wp_enqueue_style( 'elementor-admin' );
// It's for upgrade notice.
// TODO: enqueue this just if needed.
* Print switch mode button.
* Adds a switch button in post edit screen (which has cpt support). To allow
* the user to switch from the native WordPress editor to Elementor builder.
* Fired by `edit_form_after_title` action.
* @param \WP_Post $post The current post object.
public function print_switch_mode_button( $post ) {
// Exit if Gutenberg are active.
if ( did_action( 'enqueue_block_editor_assets' ) ) {
$document = Plugin::$instance->documents->get( $post->ID );
if ( ! $document || ! $document->is_editable_by_current_user() ) {
wp_nonce_field( basename( __FILE__ ), '_elementor_edit_mode_nonce' );
<div id="elementor-switch-mode">
<input id="elementor-switch-mode-input" type="hidden" name="_elementor_post_mode" value="<?php echo esc_attr( $document->is_built_with_elementor() ); ?>" />
<button id="elementor-switch-mode-button" type="button" class="button button-primary button-hero">
<span class="elementor-switch-mode-on">
<i class="eicon-arrow-<?php echo ( is_rtl() ) ? 'right' : 'left'; ?>" aria-hidden="true"></i>
<?php echo esc_html__( 'Back to WordPress Editor', 'elementor' ); ?>
<span class="elementor-switch-mode-off">
<i class="eicon-elementor-square" aria-hidden="true"></i>
<?php echo esc_html__( 'Edit with Elementor', 'elementor' ); ?>
<div id="elementor-editor">
<a id="elementor-go-to-edit-page-link" href="<?php echo esc_url( $document->get_edit_url() ); ?>">
<div id="elementor-editor-button" class="button button-primary button-hero">
<i class="eicon-elementor-square" aria-hidden="true"></i>
<?php echo esc_html__( 'Edit with Elementor', 'elementor' ); ?>
<div class="elementor-loader-wrapper">
<div class="elementor-loader">
<div class="elementor-loader-boxes">
<div class="elementor-loader-box"></div>
<div class="elementor-loader-box"></div>
<div class="elementor-loader-box"></div>
<div class="elementor-loader-box"></div>
<div class="elementor-loading-title"><?php echo esc_html__( 'Loading', 'elementor' ); ?></div>
* Flag the post mode when the post is saved.
* Fired by `save_post` action.
* @param int $post_id Post ID.
public function save_post( $post_id ) {
if ( ! wp_verify_nonce( Utils::get_super_global_value( $_POST, '_elementor_edit_mode_nonce' ), basename( __FILE__ ) ) ) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
Plugin::$instance->documents->get( $post_id )->set_is_built_with_elementor( ! empty( $_POST['_elementor_post_mode'] ) );
* Add Elementor post state.
* Adds a new "Elementor" post state to the post table.
* Fired by `display_post_states` filter.
* @param array $post_states An array of post display states.
* @param \WP_Post $post The current post object.
* @return array A filtered array of post display states.
public function add_elementor_post_state( $post_states, $post ) {
$document = Plugin::$instance->documents->get( $post->ID );
if ( $document && $document->is_built_with_elementor() && $document->is_editable_by_current_user() ) {
$post_states['elementor'] = esc_html__( 'Elementor', 'elementor' );
* Adds CSS classes to the admin body tag.
* Fired by `admin_body_class` filter.
* @param string $classes Space-separated list of CSS classes.
* @return string Space-separated list of CSS classes.
public function body_status_classes( $classes ) {
if ( in_array( $pagenow, [ 'post.php', 'post-new.php' ], true ) && Utils::is_post_support() ) {
$document = Plugin::$instance->documents->get( $post->ID );
$mode_class = $document && $document->is_built_with_elementor() ? 'elementor-editor-active' : 'elementor-editor-inactive';
$classes .= ' ' . $mode_class;
* Adds action links to the plugin list table
* Fired by `plugin_action_links` filter.
* @param array $links An array of plugin action links.
* @return array An array of plugin action links.
public function plugin_action_links( $links ) {
$settings_link = sprintf( '<a href="%1$s">%2$s</a>', admin_url( 'admin.php?page=' . Settings::PAGE_ID ), esc_html__( 'Settings', 'elementor' ) );
array_unshift( $links, $settings_link );
$go_pro_text = esc_html__( 'Get Elementor Pro', 'elementor' );
if ( Utils::is_sale_time() ) {
$go_pro_text = esc_html__( 'Discounted Upgrades Now!', 'elementor' );
$links['go_pro'] = sprintf( '<a href="%1$s" target="_blank" class="elementor-plugins-gopro">%2$s</a>', 'https://go.elementor.com/go-pro-wp-plugins/', $go_pro_text );
* Adds row meta links to the plugin list table
* Fired by `plugin_row_meta` filter.
* @param array $plugin_meta An array of the plugin's metadata, including
* the version, author, author URI, and plugin URI.
* @param string $plugin_file Path to the plugin file, relative to the plugins
* @return array An array of plugin row meta links.
public function plugin_row_meta( $plugin_meta, $plugin_file ) {
if ( ELEMENTOR_PLUGIN_BASE === $plugin_file ) {
'docs' => '<a href="https://go.elementor.com/docs-admin-plugins/" aria-label="' . esc_attr__( 'View Elementor Documentation', 'elementor' ) . '" target="_blank">' . esc_html__( 'Docs & FAQs', 'elementor' ) . '</a>',
'ideo' => '<a href="https://go.elementor.com/yt-admin-plugins/" aria-label="' . esc_attr__( 'View Elementor Video Tutorials', 'elementor' ) . '" target="_blank">' . esc_html__( 'Video Tutorials', 'elementor' ) . '</a>',
$plugin_meta = array_merge( $plugin_meta, $row_meta );
* Modifies the "Thank you" text displayed in the admin footer.
* Fired by `admin_footer_text` filter.
* @param string $footer_text The content that will be printed.
* @return string The content that will be printed.
public function admin_footer_text( $footer_text ) {
$current_screen = get_current_screen();
$is_elementor_screen = ( $current_screen && false !== strpos( $current_screen->id, 'elementor' ) );
if ( $is_elementor_screen ) {
/* translators: 1: Elementor, 2: Link to plugin review */
__( 'Enjoyed %1$s? Please leave us a %2$s rating. We really appreciate your support!', 'elementor' ),
'<strong>' . esc_html__( 'Elementor', 'elementor' ) . '</strong>',
'<a href="https://go.elementor.com/admin-review/" target="_blank">★★★★★</a>'
* Register dashboard widgets.
* Adds a new Elementor widgets to WordPress dashboard.
* Fired by `wp_dashboard_setup` action.
public function register_dashboard_widgets() {
wp_add_dashboard_widget( 'e-dashboard-overview', esc_html__( 'Elementor Overview', 'elementor' ), [ $this, 'elementor_dashboard_overview_widget' ] );
// Move our widget to top.
$dashboard = $wp_meta_boxes['dashboard']['normal']['core'];
'e-dashboard-overview' => $dashboard['e-dashboard-overview'],
$wp_meta_boxes['dashboard']['normal']['core'] = array_merge( $ours, $dashboard ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
* Displays the Elementor dashboard widget.
* Fired by `wp_add_dashboard_widget` function.
public function elementor_dashboard_overview_widget() {
<div class="e-dashboard-overview e-dashboard-widget">
self::elementor_dashboard_overview_header();
self::elementor_dashboard_overview_recently_edited();
self::elementor_dashboard_overview_news_updates();
self::elementor_dashboard_overview_footer();
* Displays the Elementor dashboard widget - header section.
* Fired by `elementor_dashboard_overview_widget` function.
* @param bool $show_versions
* @param bool $is_create_post_enabled
public static function elementor_dashboard_overview_header( bool $show_versions = true, bool $is_create_post_enabled = true ) {