ripts() { remove_action( 'wp_enqueue_scripts', [ $this, __FUNCTION__ ], 999999 ); global $wp_styles, $wp_scripts; // Reset global variable $wp_styles = new \WP_Styles(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited $wp_scripts = new \WP_Scripts(); // phpcs: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()->enqueue_scripts(); 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->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' ] ); // 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_Interface */ private function get_loader() { if ( ! $this->loader ) { $this->loader = Editor_Loader_Factory::create(); $this->loader->init(); } return $this->loader; } /** * Get elements presets. * * @return array */ public function get_elements_presets() { $element_types = Plugin::$instance->elements_manager->get_element_types(); $presets = []; foreach ( $element_types as $el_type => $element ) { $this->check_element_for_presets( $element, $el_type, $presets ); } return $presets; } /** * @return void */ private function check_element_for_presets( $element, $el_type, &$presets ) { $element_presets = $element->get_panel_presets(); if ( empty( $element_presets ) ) { return; } foreach ( $element_presets as $key => $preset ) { $this->maybe_add_preset( $el_type, $preset, $key, $presets ); } } /** * @return void */ private function maybe_add_preset( $el_type, $preset, $key, &$presets ) { if ( $this->is_valid_preset( $el_type, $preset ) ) { $presets[ $key ] = $preset; } } /** * @return boolean */ private function is_valid_preset( $el_type, $preset ) { return isset( $preset['replacements']['custom']['originalWidget'] ) && $el_type === $preset['replacements']['custom']['originalWidget']; } }