| @@ -3,10 +3,11 @@ | ||
| 3 | 3 | |
| 4 | 4 | use Elementor\Core\Breakpoints\Manager as Breakpoints_Manager; |
| 5 | 5 | use Elementor\Core\Common\Modules\Ajax\Module; |
| 6 | 6 | use Elementor\Core\Debug\Loading_Inspection_Manager; |
| 7 | -use Elementor\Core\Editor\Loader\Editor_Loader_Factory; | |
| 8 | -use Elementor\Core\Editor\Loader\Editor_Loader_Interface; | |
| 7 | +use Elementor\Core\Editor\Loader\Editor_Loader; | |
| 8 | +use Elementor\Core\Utils\Assets_Config_Provider; | |
| 9 | +use Elementor\Core\Utils\Collection; | |
| 9 | 10 | use Elementor\Core\Settings\Manager as SettingsManager; |
| 10 | 11 | use Elementor\Plugin; |
| 11 | 12 | use Elementor\TemplateLibrary\Source_Local; |
| 12 | 13 | use Elementor\Utils; |
| @@ -65,9 +66,9 @@ | ||
| 65 | 66 | */ |
| 66 | 67 | public $promotion; |
| 67 | 68 | |
| 68 | 69 | /** |
| 69 | - * @var Editor_Loader_Interface | |
| 70 | + * @var Editor_Loader | |
| 70 | 71 | */ |
| 71 | 72 | private $loader; |
| 72 | 73 | |
| 73 | 74 | /** |
| @@ -211,8 +212,67 @@ | ||
| 211 | 212 | die; |
| 212 | 213 | } |
| 213 | 214 | |
| 214 | 215 | /** |
| 216 | + * Whether the current request targets the Elementor editor. | |
| 217 | + * | |
| 218 | + * Unlike `is_edit_mode()`, this is not affected by temporary `set_edit_mode()` overrides. | |
| 219 | + * | |
| 220 | + * @since 4.1.0 | |
| 221 | + * @access public | |
| 222 | + * | |
| 223 | + * @return bool Whether the current request targets the Elementor editor. | |
| 224 | + */ | |
| 225 | + public function is_editor_request() { | |
| 226 | + $common = Plugin::$instance->common; | |
| 227 | + | |
| 228 | + if ( $common ) { | |
| 229 | + /** @var Module ajax */ | |
| 230 | + $ajax_data = $common->get_component( 'ajax' )->get_current_action_data(); | |
| 231 | + | |
| 232 | + if ( ! empty( $ajax_data ) && 'get_document_config' === $ajax_data['action'] ) { | |
| 233 | + return true; | |
| 234 | + } | |
| 235 | + } | |
| 236 | + | |
| 237 | + if ( $this->is_editor_admin_screen() ) { | |
| 238 | + return true; | |
| 239 | + } | |
| 240 | + | |
| 241 | + return $this->is_editor_ajax_request(); | |
| 242 | + } | |
| 243 | + | |
| 244 | + private function is_editor_admin_screen(): bool { | |
| 245 | + if ( ! function_exists( 'get_current_screen' ) ) { | |
| 246 | + return false; | |
| 247 | + } | |
| 248 | + | |
| 249 | + $screen = get_current_screen(); | |
| 250 | + | |
| 251 | + if ( ! $screen ) { | |
| 252 | + return false; | |
| 253 | + } | |
| 254 | + | |
| 255 | + return isset( $_GET['action'] ) && 'elementor' === $_GET['action'] && in_array( $screen->base, [ 'post', 'toplevel_page_elementor' ], true ); | |
| 256 | + } | |
| 257 | + | |
| 258 | + private function is_editor_ajax_request(): bool { | |
| 259 | + $actions = apply_filters( 'elementor/editor/ajax_actions', [ | |
| 260 | + 'elementor', | |
| 261 | + | |
| 262 | + // Templates | |
| 263 | + 'elementor_get_templates', | |
| 264 | + 'elementor_save_template', | |
| 265 | + 'elementor_get_template', | |
| 266 | + 'elementor_delete_template', | |
| 267 | + 'elementor_import_template', | |
| 268 | + 'elementor_library_direct_actions', | |
| 269 | + ] ); | |
| 270 | + | |
| 271 | + return isset( $_REQUEST['action'] ) && in_array( $_REQUEST['action'], $actions, true ); | |
| 272 | + } | |
| 273 | + | |
| 274 | + /** | |
| 215 | 275 | * Whether the edit mode is active. |
| 216 | 276 | * |
| 217 | 277 | * Used to determine whether we are in the edit mode. |
| 218 | 278 | * |
| @@ -660,13 +720,24 @@ | ||
| 660 | 720 | |
| 661 | 721 | /** |
| 662 | 722 | * Get loader. |
| 663 | 723 | * |
| 664 | - * @return Editor_Loader_Interface | |
| 724 | + * @return Editor_Loader | |
| 665 | 725 | */ |
| 666 | 726 | private function get_loader() { |
| 667 | 727 | if ( ! $this->loader ) { |
| 668 | - $this->loader = Editor_Loader_Factory::create(); | |
| 728 | + $this->loader = new Editor_Loader( | |
| 729 | + new Collection( [ | |
| 730 | + 'assets_url' => ELEMENTOR_ASSETS_URL, | |
| 731 | + 'min_suffix' => ( Utils::is_script_debug() || Utils::is_elementor_tests() ) ? '' : '.min', | |
| 732 | + 'direction_suffix' => is_rtl() ? '-rtl' : '', | |
| 733 | + ] ), | |
| 734 | + ( new Assets_Config_Provider() )->set_path_resolver( | |
| 735 | + function ( $name ) { | |
| 736 | + return ELEMENTOR_ASSETS_PATH . "js/packages/{$name}/{$name}.asset.php"; | |
| 737 | + } | |
| 738 | + ) | |
| 739 | + ); | |
| 669 | 740 | |
| 670 | 741 | $this->loader->init(); |
| 671 | 742 | } |
| 672 | 743 | |