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