| 1 |
<?php |
| 2 |
namespace Elementor\Core\Editor; |
| 3 |
|
| 4 |
use Elementor\Api; |
| 5 |
use Elementor\Core\Breakpoints\Breakpoint; |
| 6 |
use Elementor\Core\Breakpoints\Manager as Breakpoints_Manager; |
| 7 |
use Elementor\Core\Common\Modules\Ajax\Module; |
| 8 |
use Elementor\Core\Common\Modules\Ajax\Module as Ajax; |
| 9 |
use Elementor\Core\Debug\Loading_Inspection_Manager; |
| 10 |
use Elementor\Core\Files\Uploads_Manager; |
| 11 |
use Elementor\Core\Schemes\Manager as Schemes_Manager; |
| 12 |
use Elementor\Core\Settings\Manager as SettingsManager; |
| 13 |
use Elementor\Icons_Manager; |
| 14 |
use Elementor\Plugin; |
| 15 |
use Elementor\Settings; |
| 16 |
use Elementor\Shapes; |
| 17 |
use Elementor\TemplateLibrary\Source_Local; |
| 18 |
use Elementor\Tools; |
| 19 |
use Elementor\User; |
| 20 |
use Elementor\Utils; |
| 21 |
use Elementor\Core\Editor\Data; |
| 22 |
|
| 23 |
if ( ! defined( 'ABSPATH' ) ) { |
| 24 |
exit; // Exit if accessed directly. |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Elementor editor. |
| 29 |
* |
| 30 |
* Elementor editor handler class is responsible for initializing Elementor |
| 31 |
* editor and register all the actions needed to display the editor. |
| 32 |
* |
| 33 |
* @since 1.0.0 |
| 34 |
*/ |
| 35 |
class Editor { |
| 36 |
|
| 37 |
/** |
| 38 |
* User capability required to access Elementor editor. |
| 39 |
*/ |
| 40 |
const EDITING_CAPABILITY = 'edit_posts'; |
| 41 |
|
| 42 |
/** |
| 43 |
* Post ID. |
| 44 |
* |
| 45 |
* Holds the ID of the current post being edited. |
| 46 |
* |
| 47 |
* @since 1.0.0 |
| 48 |
* @access private |
| 49 |
* |
| 50 |
* @var int Post ID. |
| 51 |
*/ |
| 52 |
private $post_id; |
| 53 |
|
| 54 |
/** |
| 55 |
* Whether the edit mode is active. |
| 56 |
* |
| 57 |
* Used to determine whether we are in edit mode. |
| 58 |
* |
| 59 |
* @since 1.0.0 |
| 60 |
* @access private |
| 61 |
* |
| 62 |
* @var bool Whether the edit mode is active. |
| 63 |
*/ |
| 64 |
private $is_edit_mode; |
| 65 |
|
| 66 |
/** |
| 67 |
* @var Notice_Bar |
| 68 |
*/ |
| 69 |
public $notice_bar; |
| 70 |
|
| 71 |
/** |
| 72 |
* @var Promotion |
| 73 |
*/ |
| 74 |
public $promotion; |
| 75 |
|
| 76 |
/** |
| 77 |
* Init. |
| 78 |
* |
| 79 |
* Initialize Elementor editor. Registers all needed actions to run Elementor, |
| 80 |
* removes conflicting actions etc. |
| 81 |
* |
| 82 |
* Fired by `admin_action_elementor` action. |
| 83 |
* |
| 84 |
* @since 1.0.0 |
| 85 |
* @access public |
| 86 |
* |
| 87 |
* @param bool $die Optional. Whether to die at the end. Default is `true`. |
| 88 |
*/ |
| 89 |
public function init( $die = true ) { |
| 90 |
if ( empty( $_REQUEST['post'] ) ) { |
| 91 |
return; |
| 92 |
} |
| 93 |
|
| 94 |
$this->set_post_id( absint( $_REQUEST['post'] ) ); |
| 95 |
|
| 96 |
if ( ! $this->is_edit_mode( $this->post_id ) ) { |
| 97 |
return; |
| 98 |
} |
| 99 |
|
| 100 |
// BC: From 2.9.0, the editor shouldn't handle the global post / current document. |
| 101 |
// Use requested id and not the global in order to avoid conflicts with plugins that changes the global post. |
| 102 |
query_posts( [ |
| 103 |
'p' => $this->post_id, |
| 104 |
'post_type' => get_post_type( $this->post_id ), |
| 105 |
] ); |
| 106 |
|
| 107 |
Plugin::$instance->db->switch_to_post( $this->post_id ); |
| 108 |
|
| 109 |
$document = Plugin::$instance->documents->get( $this->post_id ); |
| 110 |
|
| 111 |
Plugin::$instance->documents->switch_to_document( $document ); |
| 112 |
|
| 113 |
// Change mode to Builder |
| 114 |
$document->set_is_built_with_elementor( true ); |
| 115 |
|
| 116 |
// End BC. |
| 117 |
|
| 118 |
Loading_Inspection_Manager::instance()->register_inspections(); |
| 119 |
|
| 120 |
// Send MIME Type header like WP admin-header. |
| 121 |
@header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) ); |
| 122 |
|
| 123 |
add_filter( 'show_admin_bar', '__return_false' ); |
| 124 |
|
| 125 |
// Remove all WordPress actions |
| 126 |
remove_all_actions( 'wp_head' ); |
| 127 |
remove_all_actions( 'wp_print_styles' ); |
| 128 |
remove_all_actions( 'wp_print_head_scripts' ); |
| 129 |
remove_all_actions( 'wp_footer' ); |
| 130 |
|
| 131 |
// Handle `wp_head` |
| 132 |
add_action( 'wp_head', 'wp_enqueue_scripts', 1 ); |
| 133 |
add_action( 'wp_head', 'wp_print_styles', 8 ); |
| 134 |
add_action( 'wp_head', 'wp_print_head_scripts', 9 ); |
| 135 |
add_action( 'wp_head', 'wp_site_icon' ); |
| 136 |
add_action( 'wp_head', [ $this, 'editor_head_trigger' ], 30 ); |
| 137 |
|
| 138 |
// Handle `wp_footer` |
| 139 |
add_action( 'wp_footer', 'wp_print_footer_scripts', 20 ); |
| 140 |
add_action( 'wp_footer', 'wp_auth_check_html', 30 ); |
| 141 |
add_action( 'wp_footer', [ $this, 'wp_footer' ] ); |
| 142 |
|
| 143 |
// Handle `wp_enqueue_scripts` |
| 144 |
remove_all_actions( 'wp_enqueue_scripts' ); |
| 145 |
|
| 146 |
// Also remove all scripts hooked into after_wp_tiny_mce. |
| 147 |
remove_all_actions( 'after_wp_tiny_mce' ); |
| 148 |
|
| 149 |
add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_scripts' ], 999999 ); |
| 150 |
add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_styles' ], 999999 ); |
| 151 |
|
| 152 |
// Setup default heartbeat options |
| 153 |
add_filter( 'heartbeat_settings', function( $settings ) { |
| 154 |
$settings['interval'] = 15; |
| 155 |
return $settings; |
| 156 |
} ); |
| 157 |
|
| 158 |
// Tell to WP Cache plugins do not cache this request. |
| 159 |
Utils::do_not_cache(); |
| 160 |
|
| 161 |
do_action( 'elementor/editor/init' ); |
| 162 |
|
| 163 |
$this->print_editor_template(); |
| 164 |
|
| 165 |
// From the action it's an empty string, from tests its `false` |
| 166 |
if ( false !== $die ) { |
| 167 |
die; |
| 168 |
} |
| 169 |
} |
| 170 |
|
| 171 |
/** |
| 172 |
* Retrieve post ID. |
| 173 |
* |
| 174 |
* Get the ID of the current post. |
| 175 |
* |
| 176 |
* @since 1.8.0 |
| 177 |
* @access public |
| 178 |
* |
| 179 |
* @return int Post ID. |
| 180 |
*/ |
| 181 |
public function get_post_id() { |
| 182 |
return $this->post_id; |
| 183 |
} |
| 184 |
|
| 185 |
/** |
| 186 |
* Redirect to new URL. |
| 187 |
* |
| 188 |
* Used as a fallback function for the old URL structure of Elementor page |
| 189 |
* edit URL. |
| 190 |
* |
| 191 |
* Fired by `template_redirect` action. |
| 192 |
* |
| 193 |
* @since 1.6.0 |
| 194 |
* @access public |
| 195 |
*/ |
| 196 |
public function redirect_to_new_url() { |
| 197 |
if ( ! isset( $_GET['elementor'] ) ) { |
| 198 |
return; |
| 199 |
} |
| 200 |
|
| 201 |
$document = Plugin::$instance->documents->get( get_the_ID() ); |
| 202 |
|
| 203 |
if ( ! $document ) { |
| 204 |
wp_die( esc_html__( 'Document not found.', 'elementor' ) ); |
| 205 |
} |
| 206 |
|
| 207 |
if ( ! $document->is_editable_by_current_user() || ! $document->is_built_with_elementor() ) { |
| 208 |
return; |
| 209 |
} |
| 210 |
|
| 211 |
wp_safe_redirect( $document->get_edit_url() ); |
| 212 |
die; |
| 213 |
} |
| 214 |
|
| 215 |
/** |
| 216 |
* Whether the edit mode is active. |
| 217 |
* |
| 218 |
* Used to determine whether we are in the edit mode. |
| 219 |
* |
| 220 |
* @since 1.0.0 |
| 221 |
* @access public |
| 222 |
* |
| 223 |
* @param int $post_id Optional. Post ID. Default is `null`, the current |
| 224 |
* post ID. |
| 225 |
* |
| 226 |
* @return bool Whether the edit mode is active. |
| 227 |
*/ |
| 228 |
public function is_edit_mode( $post_id = null ) { |
| 229 |
if ( null !== $this->is_edit_mode ) { |
| 230 |
return $this->is_edit_mode; |
| 231 |
} |
| 232 |
|
| 233 |
if ( empty( $post_id ) ) { |
| 234 |
$post_id = $this->post_id; |
| 235 |
} |
| 236 |
|
| 237 |
$document = Plugin::$instance->documents->get( $post_id ); |
| 238 |
|
| 239 |
if ( ! $document || ! $document->is_editable_by_current_user() ) { |
| 240 |
return false; |
| 241 |
} |
| 242 |
|
| 243 |
/** @var Module ajax */ |
| 244 |
$ajax_data = Plugin::$instance->common->get_component( 'ajax' )->get_current_action_data(); |
| 245 |
|
| 246 |
if ( ! empty( $ajax_data ) && 'get_document_config' === $ajax_data['action'] ) { |
| 247 |
return true; |
| 248 |
} |
| 249 |
|
| 250 |
// Ajax request as Editor mode |
| 251 |
$actions = [ |
| 252 |
'elementor', |
| 253 |
|
| 254 |
// Templates |
| 255 |
'elementor_get_templates', |
| 256 |
'elementor_save_template', |
| 257 |
'elementor_get_template', |
| 258 |
'elementor_delete_template', |
| 259 |
'elementor_import_template', |
| 260 |
'elementor_library_direct_actions', |
| 261 |
]; |
| 262 |
|
| 263 |
if ( isset( $_REQUEST['action'] ) && in_array( $_REQUEST['action'], $actions ) ) { |
| 264 |
return true; |
| 265 |
} |
| 266 |
|
| 267 |
return false; |
| 268 |
} |
| 269 |
|
| 270 |
/** |
| 271 |
* Lock post. |
| 272 |
* |
| 273 |
* Mark the post as currently being edited by the current user. |
| 274 |
* |
| 275 |
* @since 1.0.0 |
| 276 |
* @access public |
| 277 |
* |
| 278 |
* @param int $post_id The ID of the post being edited. |
| 279 |
*/ |
| 280 |
public function lock_post( $post_id ) { |
| 281 |
if ( ! function_exists( 'wp_set_post_lock' ) ) { |
| 282 |
require_once ABSPATH . 'wp-admin/includes/post.php'; |
| 283 |
} |
| 284 |
|
| 285 |
wp_set_post_lock( $post_id ); |
| 286 |
} |
| 287 |
|
| 288 |
/** |
| 289 |
* Get locked user. |
| 290 |
* |
| 291 |
* Check what user is currently editing the post. |
| 292 |
* |
| 293 |
* @since 1.0.0 |
| 294 |
* @access public |
| 295 |
* |
| 296 |
* @param int $post_id The ID of the post being edited. |
| 297 |
* |
| 298 |
* @return \WP_User|false User information or false if the post is not locked. |
| 299 |
*/ |
| 300 |
public function get_locked_user( $post_id ) { |
| 301 |
if ( ! function_exists( 'wp_check_post_lock' ) ) { |
| 302 |
require_once ABSPATH . 'wp-admin/includes/post.php'; |
| 303 |
} |
| 304 |
|
| 305 |
$locked_user = wp_check_post_lock( $post_id ); |
| 306 |
if ( ! $locked_user ) { |
| 307 |
return false; |
| 308 |
} |
| 309 |
|
| 310 |
return get_user_by( 'id', $locked_user ); |
| 311 |
} |
| 312 |
|
| 313 |
/** |
| 314 |
* Print Editor Template. |
| 315 |
* |
| 316 |
* Include the wrapper template of the editor. |
| 317 |
* |
| 318 |
* @since 2.2.0 |
| 319 |
* @access public |
| 320 |
*/ |
| 321 |
public function print_editor_template() { |
| 322 |
include ELEMENTOR_PATH . 'includes/editor-templates/editor-wrapper.php'; |
| 323 |
} |
| 324 |
|
| 325 |
/** |
| 326 |
* Enqueue scripts. |
| 327 |
* |
| 328 |
* Registers all the editor scripts and enqueues them. |
| 329 |
* |
| 330 |
* @since 1.0.0 |
| 331 |
* @access public |
| 332 |
*/ |
| 333 |
public function enqueue_scripts() { |
| 334 |
remove_action( 'wp_enqueue_scripts', [ $this, __FUNCTION__ ], 999999 ); |
| 335 |
|
| 336 |
global $wp_styles, $wp_scripts; |
| 337 |
|
| 338 |
$plugin = Plugin::$instance; |
| 339 |
|
| 340 |
// Reset global variable |
| 341 |
$wp_styles = new \WP_Styles(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 342 |
$wp_scripts = new \WP_Scripts(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 343 |
|
| 344 |
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG || defined( 'ELEMENTOR_TESTS' ) && ELEMENTOR_TESTS ) ? '' : '.min'; |
| 345 |
|
| 346 |
wp_register_script( |
| 347 |
'elementor-editor-modules', |
| 348 |
ELEMENTOR_ASSETS_URL . 'js/editor-modules' . $suffix . '.js', |
| 349 |
[ |
| 350 |
'elementor-common-modules', |
| 351 |
], |
| 352 |
ELEMENTOR_VERSION, |
| 353 |
true |
| 354 |
); |
| 355 |
|
| 356 |
wp_register_script( |
| 357 |
'elementor-editor-document', |
| 358 |
ELEMENTOR_ASSETS_URL . 'js/editor-document' . $suffix . '.js', |
| 359 |
[ |
| 360 |
'elementor-common-modules', |
| 361 |
], |
| 362 |
ELEMENTOR_VERSION, |
| 363 |
true |
| 364 |
); |
| 365 |
// Hack for waypoint with editor mode. |
| 366 |
wp_register_script( |
| 367 |
'elementor-waypoints', |
| 368 |
ELEMENTOR_ASSETS_URL . 'lib/waypoints/waypoints-for-editor.js', |
| 369 |
[ |
| 370 |
'jquery', |
| 371 |
], |
| 372 |
'4.0.2', |
| 373 |
true |
| 374 |
); |
| 375 |
|
| 376 |
wp_register_script( |
| 377 |
'perfect-scrollbar', |
| 378 |
ELEMENTOR_ASSETS_URL . 'lib/perfect-scrollbar/js/perfect-scrollbar' . $suffix . '.js', |
| 379 |
[], |
| 380 |
'1.4.0', |
| 381 |
true |
| 382 |
); |
| 383 |
|
| 384 |
wp_register_script( |
| 385 |
'jquery-easing', |
| 386 |
ELEMENTOR_ASSETS_URL . 'lib/jquery-easing/jquery-easing' . $suffix . '.js', |
| 387 |
[ |
| 388 |
'jquery', |
| 389 |
], |
| 390 |
'1.3.2', |
| 391 |
true |
| 392 |
); |
| 393 |
|
| 394 |
wp_register_script( |
| 395 |
'nprogress', |
| 396 |
ELEMENTOR_ASSETS_URL . 'lib/nprogress/nprogress' . $suffix . '.js', |
| 397 |
[], |
| 398 |
'0.2.0', |
| 399 |
true |
| 400 |
); |
| 401 |
|
| 402 |
wp_register_script( |
| 403 |
'tipsy', |
| 404 |
ELEMENTOR_ASSETS_URL . 'lib/tipsy/tipsy' . $suffix . '.js', |
| 405 |
[ |
| 406 |
'jquery', |
| 407 |
], |
| 408 |
'1.0.0', |
| 409 |
true |
| 410 |
); |
| 411 |
|
| 412 |
wp_register_script( |
| 413 |
'jquery-elementor-select2', |
| 414 |
ELEMENTOR_ASSETS_URL . 'lib/e-select2/js/e-select2.full' . $suffix . '.js', |
| 415 |
[ |
| 416 |
'jquery', |
| 417 |
], |
| 418 |
'4.0.6-rc.1', |
| 419 |
true |
| 420 |
); |
| 421 |
|
| 422 |
wp_register_script( |
| 423 |
'flatpickr', |
| 424 |
ELEMENTOR_ASSETS_URL . 'lib/flatpickr/flatpickr' . $suffix . '.js', |
| 425 |
[ |
| 426 |
'jquery', |
| 427 |
], |
| 428 |
'1.12.0', |
| 429 |
true |
| 430 |
); |
| 431 |
|
| 432 |
wp_register_script( |
| 433 |
'ace', |
| 434 |
'https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.5/ace.js', |
| 435 |
[], |
| 436 |
'1.2.5', |
| 437 |
true |
| 438 |
); |
| 439 |
|
| 440 |
wp_register_script( |
| 441 |
'ace-language-tools', |
| 442 |
'https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.5/ext-language_tools.js', |
| 443 |
[ |
| 444 |
'ace', |
| 445 |
], |
| 446 |
'1.2.5', |
| 447 |
true |
| 448 |
); |
| 449 |
|
| 450 |
wp_register_script( |
| 451 |
'jquery-hover-intent', |
| 452 |
ELEMENTOR_ASSETS_URL . 'lib/jquery-hover-intent/jquery-hover-intent' . $suffix . '.js', |
| 453 |
[], |
| 454 |
'1.0.0', |
| 455 |
true |
| 456 |
); |
| 457 |
|
| 458 |
wp_register_script( |
| 459 |
'nouislider', |
| 460 |
ELEMENTOR_ASSETS_URL . 'lib/nouislider/nouislider' . $suffix . '.js', |
| 461 |
[], |
| 462 |
'13.0.0', |
| 463 |
true |
| 464 |
); |
| 465 |
|
| 466 |
wp_register_script( |
| 467 |
'pickr', |
| 468 |
ELEMENTOR_ASSETS_URL . 'lib/pickr/pickr.min.js', |
| 469 |
[], |
| 470 |
'1.5.0', |
| 471 |
true |
| 472 |
); |
| 473 |
|
| 474 |
wp_register_script( |
| 475 |
'elementor-editor', |
| 476 |
ELEMENTOR_ASSETS_URL . 'js/editor' . $suffix . '.js', |
| 477 |
[ |
| 478 |
'elementor-common', |
| 479 |
'elementor-editor-modules', |
| 480 |
'elementor-editor-document', |
| 481 |
'wp-auth-check', |
| 482 |
'jquery-ui-sortable', |
| 483 |
'jquery-ui-resizable', |
| 484 |
'perfect-scrollbar', |
| 485 |
'nprogress', |
| 486 |
'tipsy', |
| 487 |
'imagesloaded', |
| 488 |
'heartbeat', |
| 489 |
'jquery-elementor-select2', |
| 490 |
'flatpickr', |
| 491 |
'ace', |
| 492 |
'ace-language-tools', |
| 493 |
'jquery-hover-intent', |
| 494 |
'nouislider', |
| 495 |
'pickr', |
| 496 |
'react', |
| 497 |
'react-dom', |
| 498 |
], |
| 499 |
ELEMENTOR_VERSION, |
| 500 |
true |
| 501 |
); |
| 502 |
|
| 503 |
/** |
| 504 |
* Before editor enqueue scripts. |
| 505 |
* |
| 506 |
* Fires before Elementor editor scripts are enqueued. |
| 507 |
* |
| 508 |
* @since 1.0.0 |
| 509 |
*/ |
| 510 |
do_action( 'elementor/editor/before_enqueue_scripts' ); |
| 511 |
|
| 512 |
// Tweak for WP Admin menu icons |
| 513 |
wp_print_styles( 'editor-buttons' ); |
| 514 |
|
| 515 |
$settings = SettingsManager::get_settings_managers_config(); |
| 516 |
// Moved to document since 2.9.0. |
| 517 |
unset( $settings['page'] ); |
| 518 |
|
| 519 |
$document = Plugin::$instance->documents->get_doc_or_auto_save( $this->post_id ); |
| 520 |
$kits_manager = Plugin::$instance->kits_manager; |
| 521 |
|
| 522 |
$page_title_selector = $kits_manager->get_current_settings( 'page_title_selector' ); |
| 523 |
|
| 524 |
$page_title_selector .= ', .elementor-page-title .elementor-heading-title'; |
| 525 |
|
| 526 |
$config = [ |
| 527 |
'initial_document' => $document->get_config(), |
| 528 |
'version' => ELEMENTOR_VERSION, |
| 529 |
'home_url' => home_url(), |
| 530 |
'admin_settings_url' => admin_url( 'admin.php?page=' . Settings::PAGE_ID ), |
| 531 |
'admin_tools_url' => admin_url( 'admin.php?page=' . Tools::PAGE_ID ), |
| 532 |
'autosave_interval' => AUTOSAVE_INTERVAL, |
| 533 |
'tabs' => $plugin->controls_manager->get_tabs(), |
| 534 |
'controls' => $plugin->controls_manager->get_controls_data(), |
| 535 |
'elements' => $plugin->elements_manager->get_element_types_config(), |
| 536 |
'schemes' => [ |
| 537 |
'items' => $plugin->schemes_manager->get_registered_schemes_data(), |
| 538 |
'enabled_schemes' => Schemes_Manager::get_enabled_schemes(), |
| 539 |
], |
| 540 |
'globals' => [ |
| 541 |
'defaults_enabled' => [ |
| 542 |
'colors' => $kits_manager->is_custom_colors_enabled(), |
| 543 |
'typography' => $kits_manager->is_custom_typography_enabled(), |
| 544 |
], |
| 545 |
], |
| 546 |
'icons' => [ |
| 547 |
'libraries' => Icons_Manager::get_icon_manager_tabs_config(), |
| 548 |
'goProURL' => 'https://go.elementor.com/go-pro-icon-library/', |
| 549 |
], |
| 550 |
'fa4_to_fa5_mapping_url' => ELEMENTOR_ASSETS_URL . 'lib/font-awesome/migration/mapping.js', |
| 551 |
'default_schemes' => $plugin->schemes_manager->get_schemes_defaults(), |
| 552 |
'settings' => $settings, |
| 553 |
'system_schemes' => $plugin->schemes_manager->get_system_schemes(), |
| 554 |
'wp_editor' => $this->get_wp_editor_config(), |
| 555 |
'settings_page_link' => Settings::get_url(), |
| 556 |
'tools_page_link' => Tools::get_url(), |
| 557 |
'tools_page_nonce' => wp_create_nonce( 'tools-page-from-editor' ), |
| 558 |
'elementor_site' => 'https://go.elementor.com/about-elementor/', |
| 559 |
'docs_elementor_site' => 'https://go.elementor.com/docs/', |
| 560 |
'help_the_content_url' => 'https://go.elementor.com/the-content-missing/', |
| 561 |
'help_flexbox_bc_url' => 'https://go.elementor.com/flexbox-layout-bc/', |
| 562 |
'elementPromotionURL' => 'https://go.elementor.com/go-pro-%s', |
| 563 |
'dynamicPromotionURL' => 'https://go.elementor.com/go-pro-dynamic-tag', |
| 564 |
'additional_shapes' => Shapes::get_additional_shapes_for_config(), |
| 565 |
'user' => [ |
| 566 |
'restrictions' => $plugin->role_manager->get_user_restrictions_array(), |
| 567 |
'is_administrator' => current_user_can( 'manage_options' ), |
| 568 |
'introduction' => User::get_introduction_meta(), |
| 569 |
'locale' => get_user_locale(), |
| 570 |
], |
| 571 |
'preview' => [ |
| 572 |
'help_preview_error_url' => 'https://go.elementor.com/preview-not-loaded/', |
| 573 |
'help_preview_http_error_url' => 'https://go.elementor.com/preview-not-loaded/#permissions', |
| 574 |
'help_preview_http_error_500_url' => 'https://go.elementor.com/500-error/', |
| 575 |
'debug_data' => Loading_Inspection_Manager::instance()->run_inspections(), |
| 576 |
], |
| 577 |
'locale' => get_locale(), |
| 578 |
'rich_editing_enabled' => filter_var( get_user_meta( get_current_user_id(), 'rich_editing', true ), FILTER_VALIDATE_BOOLEAN ), |
| 579 |
'page_title_selector' => $page_title_selector, |
| 580 |
'tinymceHasCustomConfig' => class_exists( 'Tinymce_Advanced' ) || class_exists( 'Advanced_Editor_Tools' ), |
| 581 |
'inlineEditing' => Plugin::$instance->widgets_manager->get_inline_editing_config(), |
| 582 |
'dynamicTags' => Plugin::$instance->dynamic_tags->get_config(), |
| 583 |
'ui' => [ |
| 584 |
'darkModeStylesheetURL' => ELEMENTOR_ASSETS_URL . 'css/editor-dark-mode' . $suffix . '.css', |
| 585 |
'defaultGenericFonts' => $kits_manager->get_current_settings( 'default_generic_fonts' ), |
| 586 |
], |
| 587 |
// Empty array for BC to avoid errors. |
| 588 |
'i18n' => [], |
| 589 |
// 'responsive' contains the custom breakpoints config introduced in Elementor v3.2.0 |
| 590 |
'responsive' => [ |
| 591 |
'breakpoints' => Plugin::$instance->breakpoints->get_breakpoints_config(), |
| 592 |
'icons_map' => Plugin::$instance->breakpoints->get_responsive_icons_classes_map(), |
| 593 |
], |
| 594 |
'promotion' => [ |
| 595 |
'elements' => $this->promotion->get_elements_promotion(), |
| 596 |
], |
| 597 |
]; |
| 598 |
|
| 599 |
if ( ! Utils::has_pro() && current_user_can( 'manage_options' ) ) { |
| 600 |
$config['promotionWidgets'] = Api::get_promotion_widgets(); |
| 601 |
} |
| 602 |
|
| 603 |
$this->bc_move_document_filters(); |
| 604 |
|
| 605 |
/** |
| 606 |
* Localize editor settings. |
| 607 |
* |
| 608 |
* Filters the editor localized settings. |
| 609 |
* |
| 610 |
* @since 1.0.0 |
| 611 |
* |
| 612 |
* @param array $config Editor configuration. |
| 613 |
* @param int $post_id The ID of the current post being edited. |
| 614 |
*/ |
| 615 |
$config = apply_filters( 'elementor/editor/localize_settings', $config ); |
| 616 |
|
| 617 |
Utils::print_js_config( 'elementor-editor', 'ElementorConfig', $config ); |
| 618 |
|
| 619 |
wp_enqueue_script( 'elementor-editor' ); |
| 620 |
|
| 621 |
wp_set_script_translations( 'elementor-editor', 'elementor' ); |
| 622 |
|
| 623 |
$plugin->controls_manager->enqueue_control_scripts(); |
| 624 |
|
| 625 |
/** |
| 626 |
* After editor enqueue scripts. |
| 627 |
* |
| 628 |
* Fires after Elementor editor scripts are enqueued. |
| 629 |
* |
| 630 |
* @since 1.0.0 |
| 631 |
*/ |
| 632 |
do_action( 'elementor/editor/after_enqueue_scripts' ); |
| 633 |
} |
| 634 |
|
| 635 |
/** |
| 636 |
* Enqueue styles. |
| 637 |
* |
| 638 |
* Registers all the editor styles and enqueues them. |
| 639 |
* |
| 640 |
* @since 1.0.0 |
| 641 |
* @access public |
| 642 |
*/ |
| 643 |
public function enqueue_styles() { |
| 644 |
/** |
| 645 |
* Before editor enqueue styles. |
| 646 |
* |
| 647 |
* Fires before Elementor editor styles are enqueued. |
| 648 |
* |
| 649 |
* @since 1.0.0 |
| 650 |
*/ |
| 651 |
do_action( 'elementor/editor/before_enqueue_styles' ); |
| 652 |
|
| 653 |
$suffix = Utils::is_script_debug() ? '' : '.min'; |
| 654 |
|
| 655 |
$direction_suffix = is_rtl() ? '-rtl' : ''; |
| 656 |
|
| 657 |
wp_register_style( |
| 658 |
'font-awesome', |
| 659 |
ELEMENTOR_ASSETS_URL . 'lib/font-awesome/css/font-awesome' . $suffix . '.css', |
| 660 |
[], |
| 661 |
'4.7.0' |
| 662 |
); |
| 663 |
|
| 664 |
wp_register_style( |
| 665 |
'elementor-select2', |
| 666 |
ELEMENTOR_ASSETS_URL . 'lib/e-select2/css/e-select2' . $suffix . '.css', |
| 667 |
[], |
| 668 |
'4.0.6-rc.1' |
| 669 |
); |
| 670 |
|
| 671 |
wp_register_style( |
| 672 |
'google-font-roboto', |
| 673 |
'https://fonts.googleapis.com/css?family=Roboto:300,400,500,700', |
| 674 |
[], |
| 675 |
ELEMENTOR_VERSION |
| 676 |
); |
| 677 |
|
| 678 |
wp_register_style( |
| 679 |
'flatpickr', |
| 680 |
ELEMENTOR_ASSETS_URL . 'lib/flatpickr/flatpickr' . $suffix . '.css', |
| 681 |
[], |
| 682 |
'1.12.0' |
| 683 |
); |
| 684 |
|
| 685 |
wp_register_style( |
| 686 |
'pickr', |
| 687 |
ELEMENTOR_ASSETS_URL . 'lib/pickr/themes/monolith.min.css', |
| 688 |
[], |
| 689 |
'1.5.0' |
| 690 |
); |
| 691 |
|
| 692 |
wp_register_style( |
| 693 |
'elementor-editor', |
| 694 |
ELEMENTOR_ASSETS_URL . 'css/editor' . $direction_suffix . $suffix . '.css', |
| 695 |
[ |
| 696 |
'elementor-common', |
| 697 |
'elementor-select2', |
| 698 |
'elementor-icons', |
| 699 |
'wp-auth-check', |
| 700 |
'google-font-roboto', |
| 701 |
'flatpickr', |
| 702 |
'pickr', |
| 703 |
], |
| 704 |
ELEMENTOR_VERSION |
| 705 |
); |
| 706 |
|
| 707 |
wp_enqueue_style( 'elementor-editor' ); |
| 708 |
|
| 709 |
$ui_theme = SettingsManager::get_settings_managers( 'editorPreferences' )->get_model()->get_settings( 'ui_theme' ); |
| 710 |
|
| 711 |
if ( 'light' !== $ui_theme ) { |
| 712 |
$ui_theme_media_queries = 'all'; |
| 713 |
|
| 714 |
if ( 'auto' === $ui_theme ) { |
| 715 |
$ui_theme_media_queries = '(prefers-color-scheme: dark)'; |
| 716 |
} |
| 717 |
|
| 718 |
wp_enqueue_style( |
| 719 |
'elementor-editor-dark-mode', |
| 720 |
ELEMENTOR_ASSETS_URL . 'css/editor-dark-mode' . $suffix . '.css', |
| 721 |
[ |
| 722 |
'elementor-editor', |
| 723 |
], |
| 724 |
ELEMENTOR_VERSION, |
| 725 |
$ui_theme_media_queries |
| 726 |
); |
| 727 |
} |
| 728 |
|
| 729 |
$breakpoints = Plugin::$instance->breakpoints->get_breakpoints(); |
| 730 |
|
| 731 |
// The two breakpoints under 'tablet' need to be checked for values. |
| 732 |
if ( $breakpoints[ Breakpoints_Manager::BREAKPOINT_KEY_MOBILE ]->is_custom() || $breakpoints[ Breakpoints_Manager::BREAKPOINT_KEY_MOBILE_EXTRA ]->is_enabled() ) { |
| 733 |
wp_add_inline_style( |
| 734 |
'elementor-editor', |
| 735 |
'.elementor-device-tablet #elementor-preview-responsive-wrapper { width: ' . Plugin::$instance->breakpoints->get_device_min_breakpoint( Breakpoints_Manager::BREAKPOINT_KEY_TABLET ) . 'px; }' |
| 736 |
); |
| 737 |
} |
| 738 |
|
| 739 |
/** |
| 740 |
* After editor enqueue styles. |
| 741 |
* |
| 742 |
* Fires after Elementor editor styles are enqueued. |
| 743 |
* |
| 744 |
* @since 1.0.0 |
| 745 |
*/ |
| 746 |
do_action( 'elementor/editor/after_enqueue_styles' ); |
| 747 |
} |
| 748 |
|
| 749 |
/** |
| 750 |
* Get WordPress editor config. |
| 751 |
* |
| 752 |
* Config the default WordPress editor with custom settings for Elementor use. |
| 753 |
* |
| 754 |
* @since 1.9.0 |
| 755 |
* @access private |
| 756 |
*/ |
| 757 |
private function get_wp_editor_config() { |
| 758 |
// Remove all TinyMCE plugins. |
| 759 |
remove_all_filters( 'mce_buttons', 10 ); |
| 760 |
remove_all_filters( 'mce_external_plugins', 10 ); |
| 761 |
|
| 762 |
if ( ! class_exists( '\_WP_Editors', false ) ) { |
| 763 |
require ABSPATH . WPINC . '/class-wp-editor.php'; |
| 764 |
} |
| 765 |
|
| 766 |
// WordPress 4.8 and higher |
| 767 |
if ( method_exists( '\_WP_Editors', 'print_tinymce_scripts' ) ) { |
| 768 |
\_WP_Editors::print_default_editor_scripts(); |
| 769 |
\_WP_Editors::print_tinymce_scripts(); |
| 770 |
} |
| 771 |
ob_start(); |
| 772 |
|
| 773 |
wp_editor( |
| 774 |
'%%EDITORCONTENT%%', |
| 775 |
'elementorwpeditor', |
| 776 |
[ |
| 777 |
'editor_class' => 'elementor-wp-editor', |
| 778 |
'editor_height' => 250, |
| 779 |
'drag_drop_upload' => true, |
| 780 |
] |
| 781 |
); |
| 782 |
|
| 783 |
$config = ob_get_clean(); |
| 784 |
|
| 785 |
// Don't call \_WP_Editors methods again |
| 786 |
remove_action( 'admin_print_footer_scripts', [ '_WP_Editors', 'editor_js' ], 50 ); |
| 787 |
remove_action( 'admin_print_footer_scripts', [ '_WP_Editors', 'print_default_editor_scripts' ], 45 ); |
| 788 |
|
| 789 |
\_WP_Editors::editor_js(); |
| 790 |
|
| 791 |
return $config; |
| 792 |
} |
| 793 |
|
| 794 |
/** |
| 795 |
* Editor head trigger. |
| 796 |
* |
| 797 |
* Fires the 'elementor/editor/wp_head' action in the head tag in Elementor |
| 798 |
* editor. |
| 799 |
* |
| 800 |
* @since 1.0.0 |
| 801 |
* @access public |
| 802 |
*/ |
| 803 |
public function editor_head_trigger() { |
| 804 |
/** |
| 805 |
* Elementor editor head. |
| 806 |
* |
| 807 |
* Fires on Elementor editor head tag. |
| 808 |
* |
| 809 |
* Used to prints scripts or any other data in the head tag. |
| 810 |
* |
| 811 |
* @since 1.0.0 |
| 812 |
*/ |
| 813 |
do_action( 'elementor/editor/wp_head' ); |
| 814 |
} |
| 815 |
|
| 816 |
/** |
| 817 |
* WP footer. |
| 818 |
* |
| 819 |
* Prints Elementor editor with all the editor templates, and render controls, |
| 820 |
* widgets and content elements. |
| 821 |
* |
| 822 |
* Fired by `wp_footer` action. |
| 823 |
* |
| 824 |
* @since 1.0.0 |
| 825 |
* @access public |
| 826 |
*/ |
| 827 |
public function wp_footer() { |
| 828 |
$plugin = Plugin::$instance; |
| 829 |
|
| 830 |
$plugin->controls_manager->render_controls(); |
| 831 |
$plugin->widgets_manager->render_widgets_content(); |
| 832 |
$plugin->elements_manager->render_elements_content(); |
| 833 |
|
| 834 |
$plugin->schemes_manager->print_schemes_templates(); |
| 835 |
|
| 836 |
$plugin->dynamic_tags->print_templates(); |
| 837 |
|
| 838 |
$this->init_editor_templates(); |
| 839 |
|
| 840 |
/** |
| 841 |
* Elementor editor footer. |
| 842 |
* |
| 843 |
* Fires on Elementor editor before closing the body tag. |
| 844 |
* |
| 845 |
* Used to prints scripts or any other HTML before closing the body tag. |
| 846 |
* |
| 847 |
* @since 1.0.0 |
| 848 |
*/ |
| 849 |
do_action( 'elementor/editor/footer' ); |
| 850 |
} |
| 851 |
|
| 852 |
/** |
| 853 |
* Set edit mode. |
| 854 |
* |
| 855 |
* Used to update the edit mode. |
| 856 |
* |
| 857 |
* @since 1.0.0 |
| 858 |
* @access public |
| 859 |
* |
| 860 |
* @param bool $edit_mode Whether the edit mode is active. |
| 861 |
*/ |
| 862 |
public function set_edit_mode( $edit_mode ) { |
| 863 |
$this->is_edit_mode = $edit_mode; |
| 864 |
} |
| 865 |
|
| 866 |
/** |
| 867 |
* Editor constructor. |
| 868 |
* |
| 869 |
* Initializing Elementor editor and redirect from old URL structure of |
| 870 |
* Elementor editor. |
| 871 |
* |
| 872 |
* @since 1.0.0 |
| 873 |
* @access public |
| 874 |
*/ |
| 875 |
public function __construct() { |
| 876 |
Plugin::$instance->data_manager_v2->register_controller( new Data\Globals\Controller() ); |
| 877 |
|
| 878 |
$this->notice_bar = new Notice_Bar(); |
| 879 |
$this->promotion = new Promotion(); |
| 880 |
|
| 881 |
add_action( 'admin_action_elementor', [ $this, 'init' ] ); |
| 882 |
add_action( 'template_redirect', [ $this, 'redirect_to_new_url' ] ); |
| 883 |
|
| 884 |
// Handle autocomplete feature for URL control. |
| 885 |
add_filter( 'wp_link_query_args', [ $this, 'filter_wp_link_query_args' ] ); |
| 886 |
add_filter( 'wp_link_query', [ $this, 'filter_wp_link_query' ] ); |
| 887 |
} |
| 888 |
|
| 889 |
/** |
| 890 |
* @since 2.2.0 |
| 891 |
* @access public |
| 892 |
*/ |
| 893 |
public function filter_wp_link_query_args( $query ) { |
| 894 |
$library_cpt_key = array_search( Source_Local::CPT, $query['post_type'], true ); |
| 895 |
if ( false !== $library_cpt_key ) { |
| 896 |
unset( $query['post_type'][ $library_cpt_key ] ); |
| 897 |
} |
| 898 |
|
| 899 |
return $query; |
| 900 |
} |
| 901 |
|
| 902 |
/** |
| 903 |
* @since 2.2.0 |
| 904 |
* @access public |
| 905 |
*/ |
| 906 |
public function filter_wp_link_query( $results ) { |
| 907 |
|
| 908 |
// PHPCS - The user data is not used. |
| 909 |
if ( isset( $_POST['editor'] ) && 'elementor' === $_POST['editor'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 910 |
$post_type_object = get_post_type_object( 'post' ); |
| 911 |
$post_label = $post_type_object->labels->singular_name; |
| 912 |
|
| 913 |
foreach ( $results as & $result ) { |
| 914 |
if ( 'post' === get_post_type( $result['ID'] ) ) { |
| 915 |
$result['info'] = $post_label; |
| 916 |
} |
| 917 |
} |
| 918 |
} |
| 919 |
|
| 920 |
return $results; |
| 921 |
} |
| 922 |
|
| 923 |
/** |
| 924 |
* Init editor templates. |
| 925 |
* |
| 926 |
* Initialize default elementor templates used in the editor panel. |
| 927 |
* |
| 928 |
* @since 1.7.0 |
| 929 |
* @access private |
| 930 |
*/ |
| 931 |
private function init_editor_templates() { |
| 932 |
$template_names = [ |
| 933 |
'global', |
| 934 |
'panel', |
| 935 |
'panel-elements', |
| 936 |
'repeater', |
| 937 |
'templates', |
| 938 |
'navigator', |
| 939 |
'hotkeys', |
| 940 |
'responsive-bar', |
| 941 |
]; |
| 942 |
|
| 943 |
foreach ( $template_names as $template_name ) { |
| 944 |
Plugin::$instance->common->add_template( ELEMENTOR_PATH . "includes/editor-templates/$template_name.php" ); |
| 945 |
} |
| 946 |
} |
| 947 |
|
| 948 |
private function bc_move_document_filters() { |
| 949 |
global $wp_filter; |
| 950 |
|
| 951 |
$old_tag = 'elementor/editor/localize_settings'; |
| 952 |
$new_tag = 'elementor/document/config'; |
| 953 |
|
| 954 |
if ( ! has_filter( $old_tag ) ) { |
| 955 |
return; |
| 956 |
} |
| 957 |
|
| 958 |
foreach ( $wp_filter[ $old_tag ] as $priority => $filters ) { |
| 959 |
foreach ( $filters as $filter_id => $filter_args ) { |
| 960 |
if ( 2 === $filter_args['accepted_args'] ) { |
| 961 |
remove_filter( $old_tag, $filter_id, $priority ); |
| 962 |
|
| 963 |
add_filter( $new_tag, $filter_args['function'], $priority, 2 ); |
| 964 |
|
| 965 |
// TODO: Hard deprecation |
| 966 |
// _deprecated_hook( '`' . $old_tag . ` is no longer using post_id', '2.9.0', $new_tag' ); |
| 967 |
} |
| 968 |
} |
| 969 |
} |
| 970 |
} |
| 971 |
|
| 972 |
public function set_post_id( $post_id ) { |
| 973 |
$this->post_id = $post_id; |
| 974 |
} |
| 975 |
} |
| 976 |
|