pcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
$this->get_loader()->register_scripts();
/**
* Before editor enqueue scripts.
*
* Fires before Elementor editor scripts are enqueued.
*
* @since 1.0.0
*/
do_action( 'elementor/editor/before_enqueue_scripts' );
// Tweak for WP Admin menu icons
wp_print_styles( 'editor-buttons' );
$this->get_loader()->print_client_settings();
$this->get_loader()->enqueue_scripts();
$this->get_loader()->load_scripts_translations();
Plugin::$instance->controls_manager->enqueue_control_scripts();
/**
* After editor enqueue scripts.
*
* Fires after Elementor editor scripts are enqueued.
*
* @since 1.0.0
*/
do_action( 'elementor/editor/after_enqueue_scripts' );
}
/**
* Enqueue styles.
*
* Registers all the editor styles and enqueues them.
*
* @since 1.0.0
* @access public
*/
public function enqueue_styles() {
/**
* Before editor enqueue styles.
*
* Fires before Elementor editor styles are enqueued.
*
* @since 1.0.0
*/
do_action( 'elementor/editor/before_enqueue_styles' );
$this->get_loader()->register_styles();
$this->get_loader()->enqueue_styles();
$this->enqueue_theme_ui_styles();
$breakpoints = Plugin::$instance->breakpoints->get_breakpoints();
// The two breakpoints under 'tablet' need to be checked for values.
if ( $breakpoints[ Breakpoints_Manager::BREAKPOINT_KEY_MOBILE ]->is_custom() || $breakpoints[ Breakpoints_Manager::BREAKPOINT_KEY_MOBILE_EXTRA ]->is_enabled() ) {
wp_add_inline_style(
'elementor-editor',
'.elementor-device-tablet #elementor-preview-responsive-wrapper { width: ' . Plugin::$instance->breakpoints->get_device_min_breakpoint( Breakpoints_Manager::BREAKPOINT_KEY_TABLET ) . 'px; }'
);
}
/**
* After editor enqueue styles.
*
* Fires after Elementor editor styles are enqueued.
*
* @since 1.0.0
*/
do_action( 'elementor/editor/after_enqueue_styles' );
}
private function enqueue_theme_ui_styles() {
$ui_theme_selected = SettingsManager::get_settings_managers( 'editorPreferences' )->get_model()->get_settings( 'ui_theme' );
$ui_themes = [
'light',
'dark',
];
if ( 'auto' === $ui_theme_selected || ! in_array( $ui_theme_selected, $ui_themes, true ) ) {
$ui_light_theme_media_queries = '(prefers-color-scheme: light)';
$ui_dark_theme_media_queries = '(prefers-color-scheme: dark)';
} else {
$ui_light_theme_media_queries = 'none';
$ui_dark_theme_media_queries = 'none';
if ( 'light' === $ui_theme_selected ) {
$ui_light_theme_media_queries = 'all';
} elseif ( 'dark' === $ui_theme_selected ) {
$ui_dark_theme_media_queries = 'all';
}
}
$this->enqueue_theme_ui( 'light', $ui_light_theme_media_queries );
$this->enqueue_theme_ui( 'dark', $ui_dark_theme_media_queries );
}
private function enqueue_theme_ui( $ui_theme, $ui_theme_media_queries = 'all' ) {
$suffix = Utils::is_script_debug() ? '' : '.min';
wp_enqueue_style(
'e-theme-ui-' . $ui_theme,
ELEMENTOR_ASSETS_URL . 'css/theme-' . $ui_theme . $suffix . '.css',
[],
ELEMENTOR_VERSION,
$ui_theme_media_queries
);
}
/**
* Editor head trigger.
*
* Fires the 'elementor/editor/wp_head' action in the head tag in Elementor
* editor.
*
* @since 1.0.0
* @access public
*/
public function editor_head_trigger() {
/**
* Elementor editor head.
*
* Fires on Elementor editor head tag.
*
* Used to prints scripts or any other data in the head tag.
*
* @since 1.0.0
*/
do_action( 'elementor/editor/wp_head' );
}
/**
* WP footer.
*
* Prints Elementor editor with all the editor templates, and render controls,
* widgets and content elements.
*
* Fired by `wp_footer` action.
*
* @since 1.0.0
* @access public
*/
public function wp_footer() {
$plugin = Plugin::$instance;
$plugin->controls_manager->render_controls();
$plugin->widgets_manager->render_widgets_content();
$plugin->elements_manager->render_elements_content();
$plugin->schemes_manager->print_schemes_templates();
$plugin->dynamic_tags->print_templates();
$this->get_loader()->register_additional_templates();
/**
* Elementor editor footer.
*
* Fires on Elementor editor before closing the body tag.
*
* Used to prints scripts or any other HTML before closing the body tag.
*
* @since 1.0.0
*/
do_action( 'elementor/editor/footer' );
}
/**
* Set edit mode.
*
* Used to update the edit mode.
*
* @since 1.0.0
* @access public
*
* @param bool $edit_mode Whether the edit mode is active.
*/
public function set_edit_mode( $edit_mode ) {
$this->is_edit_mode = $edit_mode;
}
/**
* Editor constructor.
*
* Initializing Elementor editor and redirect from old URL structure of
* Elementor editor.
*
* @since 1.0.0
* @access public
*/
public function __construct() {
Plugin::$instance->data_manager_v2->register_controller( new Data\Globals\Controller() );
$this->notice_bar = new Notice_Bar();
$this->promotion = new Promotion();
add_action( 'admin_action_elementor', [ $this, 'init' ] );
add_action( 'template_redirect', [ $this, 'redirect_to_new_url' ] );
$this->register_editor_v2_experiment();
// Handle autocomplete feature for URL control.
add_filter( 'wp_link_query_args', [ $this, 'filter_wp_link_query_args' ] );
add_filter( 'wp_link_query', [ $this, 'filter_wp_link_query' ] );
}
/**
* @since 2.2.0
* @access public
*/
public function filter_wp_link_query_args( $query ) {
$library_cpt_key = array_search( Source_Local::CPT, $query['post_type'], true );
if ( false !== $library_cpt_key ) {
unset( $query['post_type'][ $library_cpt_key ] );
}
return $query;
}
/**
* @since 2.2.0
* @access public
*/
public function filter_wp_link_query( $results ) {
// PHPCS - The user data is not used.
if ( isset( $_POST['editor'] ) && 'elementor' === $_POST['editor'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
$post_type_object = get_post_type_object( 'post' );
$post_label = $post_type_object->labels->singular_name;
foreach ( $results as & $result ) {
if ( 'post' === get_post_type( $result['ID'] ) ) {
$result['info'] = $post_label;
}
}
}
return $results;
}
public function set_post_id( $post_id ) {
$this->post_id = $post_id;
}
/**
* Get loader.
*
* @return Editor_Loader
*/
private function get_loader() {
if ( ! $this->loader ) {
$this->loader = new Editor_Loader( Config_Provider_Factory::create() );
$this->loader->register_hooks();
}
return $this->loader;
}
/**
* Adding Editor V2 experiment.
*
* @return void
* @throws \Exception
*/
private function register_editor_v2_experiment() {
Plugin::$instance->experiments->add_feature( [
'name' => static::EDITOR_V2_EXPERIMENT_NAME,
'title' => esc_html__( 'Editor Top Bar', 'elementor' ),
'description' => sprintf(
esc_html__(
'Get a sneak peek of the new Editor powered by React. The beautiful design and experimental layout of the Top bar are just some of the exciting tools on their way. %s',
'elementor'
),
'' . esc_html__( 'Learn more', 'elementor' ) . ''
),
'default' => Experiments_Manager::STATE_INACTIVE,
'status' => Experiments_Manager::RELEASE_STATUS_ALPHA,
] );
}
}