PluginProbe
Elementor Website Builder – more than just a page builder / 3.0.7
Elementor Website Builder – more than just a page builder v3.0.7
4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 All 452 releases
← All changes | core/kits/manager.php +49 -298 4.1.23.0.7 View file →
@@ -1,18 +1,16 @@
1 1 <?php
2 2 namespace Elementor\Core\Kits;
3 3
4 -use Elementor\Core\Base\Document;
5 4 use Elementor\Core\Kits\Controls\Repeater;
6 5 use Elementor\Core\Kits\Documents\Tabs\Global_Colors;
7 6 use Elementor\Core\Kits\Documents\Tabs\Global_Typography;
8 7 use Elementor\Plugin;
9 8 use Elementor\Core\Files\CSS\Post as Post_CSS;
10 -use Elementor\Core\Files\CSS\Post_Preview;
9 +use Elementor\Core\Files\CSS\Post_Preview as Post_Preview;
11 10 use Elementor\Core\Documents_Manager;
12 11 use Elementor\Core\Kits\Documents\Kit;
13 12 use Elementor\TemplateLibrary\Source_Local;
14 -use Elementor\Utils;
15 13
16 14 if ( ! defined( 'ABSPATH' ) ) {
17 15 exit; // Exit if accessed directly.
18 16 }
@@ -20,83 +18,35 @@
20 18 class Manager {
21 19
22 20 const OPTION_ACTIVE = 'elementor_active_kit';
23 21
24 - const OPTION_PREVIOUS = 'elementor_previous_kit';
25 -
26 - const E_HASH_COMMAND_OPEN_SITE_SETTINGS = 'e:run:panel/global/open';
27 -
28 - private $should_skip_trash_kit_confirmation = false;
29 -
30 22 public function get_active_id() {
31 - return get_option( self::OPTION_ACTIVE );
32 - }
23 + $id = get_option( self::OPTION_ACTIVE );
33 24
34 - public function get_previous_id() {
35 - return get_option( self::OPTION_PREVIOUS );
36 - }
25 + $kit_document = Plugin::$instance->documents->get( $id );
37 26
38 - public function get_kit( $kit_id ) {
39 - $kit = Plugin::$instance->documents->get( $kit_id );
40 -
41 - if ( ! $this->is_valid_kit( $kit ) ) {
42 - return $this->get_empty_kit_instance();
27 + if ( ! $kit_document || ! $kit_document instanceof Kit || 'trash' === $kit_document->get_main_post()->post_status ) {
28 + $id = $this->create_default();
29 + update_option( self::OPTION_ACTIVE, $id );
43 30 }
44 31
45 - return $kit;
32 + return $id;
46 33 }
47 34
48 35 public function get_active_kit() {
49 - return $this->get_kit( $this->get_active_id() );
36 + $id = $this->get_active_id();
37 +
38 + return Plugin::$instance->documents->get( $id );
50 39 }
51 40
52 41 public function get_active_kit_for_frontend() {
53 - $kit = Plugin::$instance->documents->get_doc_for_frontend( $this->get_active_id() );
42 + $id = $this->get_active_id();
54 43
55 - if ( ! $this->is_valid_kit( $kit ) ) {
56 - return $this->get_empty_kit_instance();
57 - }
58 -
59 - return $kit;
44 + return Plugin::$instance->documents->get_doc_for_frontend( $id );
60 45 }
61 46
62 - /**
63 - * @param $kit
64 - *
65 - * @return bool
66 - */
67 - private function is_valid_kit( $kit ) {
68 - return $kit && $kit instanceof Kit && 'trash' !== $kit->get_main_post()->post_status;
69 - }
70 47
71 48 /**
72 - * Returns an empty kit for situation when there is no kit in the site.
73 - *
74 - * @return Kit
75 - * @throws \Exception If the kit instance cannot be created.
76 - */
77 - private function get_empty_kit_instance() {
78 - return new Kit( [
79 - 'settings' => [],
80 - 'post_id' => 0,
81 - ] );
82 - }
83 -
84 - /**
85 - * Checks if specific post is a kit.
86 - *
87 - * @param $post_id
88 - *
89 - * @return bool
90 - */
91 - public function is_kit( $post_id ) {
92 - $document = Plugin::$instance->documents->get( $post_id );
93 -
94 - return $document && $document instanceof Kit && ! $document->is_revision();
95 - }
96 -
97 -
98 - /**
99 49 * Init kit controls.
100 50 *
101 51 * A temp solution in order to avoid init kit group control from within another group control.
102 52 *
@@ -116,124 +66,19 @@
116 66
117 67 return $kit->get_settings( $setting );
118 68 }
119 69
120 - public function create( array $kit_data = [], array $kit_meta_data = [] ) {
121 - $default_kit_data = [
122 - 'post_status' => 'publish',
123 - ];
124 -
125 - $kit_data = array_merge( $default_kit_data, $kit_data );
126 -
127 - $kit_data['post_type'] = Source_Local::CPT;
128 -
129 - $kit = Plugin::$instance->documents->create( 'kit', $kit_data, $kit_meta_data );
130 -
131 - if ( isset( $kit_data['settings'] ) ) {
132 - $kit->save( [ 'settings' => $kit_data['settings'] ] );
133 - }
134 -
135 - return $kit->get_id();
136 - }
137 -
138 - public function create_new_kit( $kit_name = '', $settings = [], $active = true ) {
139 - $kit_name = $kit_name ? $kit_name : esc_html__( 'Custom', 'elementor' );
140 -
141 - $current_kit = $this->get_active_kit();
142 -
143 - $kit_meta_data = $this->get_meta_to_preserve( $current_kit );
144 -
145 - $id = $this->create( [
146 - 'post_title' => $kit_name,
147 - 'settings' => $settings,
148 - ], $kit_meta_data );
149 -
150 - if ( $active ) {
151 - update_option( self::OPTION_PREVIOUS, $this->get_active_id() );
152 - update_option( self::OPTION_ACTIVE, $id );
153 - }
154 -
155 - return $id;
156 - }
157 -
158 - private function get_meta_to_preserve( Kit $current_kit ): array {
159 - $meta_keys_to_preserve = apply_filters( 'elementor/kit/meta_to_preserve_on_kit_import', [] );
160 -
161 - $kit_meta_data = [];
162 -
163 - foreach ( $meta_keys_to_preserve as $meta_key ) {
164 - $value = $current_kit->get_meta( $meta_key );
165 -
166 - if ( ! empty( $value ) ) {
167 - $kit_meta_data[ $meta_key ] = $value;
168 - }
169 - }
170 -
171 - return $kit_meta_data;
172 - }
173 -
174 - public function create_default() {
175 - return $this->create( [
176 - 'post_title' => esc_html__( 'Default Kit', 'elementor' ),
177 - ] );
178 - }
179 -
180 - /**
181 - * Create a default kit if needed.
182 - *
183 - * This action runs on activation hook, all the Plugin components do not exists and
184 - * the Document manager and Kits manager instances cannot be used.
185 - *
186 - * @return int|void|\WP_Error
187 - */
188 - public static function create_default_kit() {
189 - if ( get_option( self::OPTION_ACTIVE ) ) {
190 - return;
191 - }
192 -
193 - $id = wp_insert_post( [
194 - 'post_title' => esc_html__( 'Default Kit', 'elementor' ),
70 + private function create_default() {
71 + $kit = Plugin::$instance->documents->create( 'kit', [
195 72 'post_type' => Source_Local::CPT,
73 + 'post_title' => __( 'Default Kit', 'elementor' ),
196 74 'post_status' => 'publish',
197 - 'meta_input' => [
198 - '_elementor_edit_mode' => 'builder',
199 - Document::TYPE_META_KEY => 'kit',
200 - ],
201 75 ] );
202 76
203 - update_option( self::OPTION_ACTIVE, $id );
204 -
205 - return $id;
77 + return $kit->get_id();
206 78 }
207 79
208 80 /**
209 - * @param $imported_kit_id int The id of the imported kit that should be deleted.
210 - * @param $active_kit_id int The id of the kit that should set as 'active_kit' after the deletion.
211 - * @param $previous_kit_id int The id of the kit that should set as 'previous_kit' after the deletion.
212 - * @return void
213 - */
214 - public function revert( int $imported_kit_id, int $active_kit_id, int $previous_kit_id ) {
215 - // If the kit that should set as active is not a valid kit then abort the revert.
216 - if ( ! $this->is_kit( $active_kit_id ) ) {
217 - return;
218 - }
219 -
220 - // This a hacky solution to avoid from the revert process to be interrupted by the `trash_kit_confirmation`.
221 - $this->should_skip_trash_kit_confirmation = true;
222 -
223 - $kit = $this->get_kit( $imported_kit_id );
224 - $kit->force_delete();
225 -
226 - $this->should_skip_trash_kit_confirmation = false;
227 -
228 - update_option( self::OPTION_ACTIVE, $active_kit_id );
229 -
230 - if ( $this->is_kit( $previous_kit_id ) ) {
231 - update_option( self::OPTION_PREVIOUS, $previous_kit_id );
232 - }
233 - }
234 -
235 - /**
236 81 * @param Documents_Manager $documents_manager
237 82 */
238 83 public function register_document( $documents_manager ) {
239 84 $documents_manager->register_document_type( 'kit', Kit::get_class_full_name() );
@@ -255,8 +100,34 @@
255 100 ],
256 101 'user' => [
257 102 'can_edit_kit' => $kit->is_editable_by_current_user(),
258 103 ],
104 + 'i18n' => [
105 + 'close' => __( 'Close', 'elementor' ),
106 + 'back' => __( 'Back', 'elementor' ),
107 + 'site_identity' => __( 'Site Identity', 'elementor' ),
108 + 'lightbox' => __( 'Lightbox', 'elementor' ),
109 + 'layout' => __( 'Layout', 'elementor' ),
110 + 'theme_style' => __( 'Theme Style', 'elementor' ),
111 + 'add_color' => __( 'Add Color', 'elementor' ),
112 + 'add_style' => __( 'Add Style', 'elementor' ),
113 + 'new_item' => __( 'New Item', 'elementor' ),
114 + 'global_color' => __( 'Global Color', 'elementor' ),
115 + 'global_fonts' => __( 'Global Fonts', 'elementor' ),
116 + 'global_colors' => __( 'Global Colors', 'elementor' ),
117 + 'invalid' => __( 'Invalid', 'elementor' ),
118 + 'color_cannot_be_deleted' => __( 'System Color can\'t be deleted', 'elementor' ),
119 + 'font_cannot_be_deleted' => __( 'System Font can\'t be deleted', 'elementor' ),
120 + 'design_system' => __( 'Design System', 'elementor' ),
121 + 'buttons' => __( 'Buttons', 'elementor' ),
122 + 'images' => __( 'Images', 'elementor' ),
123 + 'form_fields' => __( 'Form Fields', 'elementor' ),
124 + 'background' => __( 'Background', 'elementor' ),
125 + 'custom_css' => __( 'Custom CSS', 'elementor' ),
126 + 'additional_settings' => __( 'Additional Settings', 'elementor' ),
127 + 'kit_changes_updated' => __( 'Your changes have been updated.', 'elementor' ),
128 + 'back_to_editor' => __( 'Back to Editor', 'elementor' ),
129 + ],
259 130 ] );
260 131
261 132 return $settings;
262 133 }
@@ -282,8 +153,10 @@
282 153 $css_file = Post_CSS::create( $kit->get_id() );
283 154 }
284 155
285 156 $css_file->enqueue();
157 +
158 + Plugin::$instance->frontend->add_body_class( 'elementor-kit-' . $kit->get_main_id() );
286 159 }
287 160 }
288 161
289 162 public function render_panel_html() {
@@ -296,9 +169,9 @@
296 169 $is_kit_preview = is_preview() && isset( $_GET['preview_id'] ) && $active_kit->get_main_id() === (int) $_GET['preview_id'];
297 170
298 171 if ( $is_kit_preview ) {
299 172 $kit = Plugin::$instance->documents->get_doc_or_auto_save( $active_kit->get_main_id(), get_current_user_id() );
300 - } elseif ( null !== $active_kit->get_main_post() && 'publish' === $active_kit->get_main_post()->post_status ) {
173 + } elseif ( 'publish' === $active_kit->get_main_post()->post_status ) {
301 174 $kit = $active_kit;
302 175 }
303 176
304 177 return $kit;
@@ -303,25 +176,14 @@
303 176
304 177 return $kit;
305 178 }
306 179
307 - public function update_kit_settings_based_on_option( $key, $value ) {
308 - /** @var Kit $active_kit */
309 - $active_kit = $this->get_active_kit();
310 -
311 - if ( $active_kit->is_saving() ) {
312 - return;
313 - }
314 -
315 - $active_kit->update_settings( [ $key => $value ] );
316 - }
317 -
318 180 /**
319 181 * Map Scheme To Global
320 182 *
321 183 * Convert a given scheme value to its corresponding default global value
322 184 *
323 - * @param string $type 'color'/'typography'.
185 + * @param string $type 'color'/'typography'
324 186 * @param $value
325 187 * @return mixed
326 188 */
327 189 private function map_scheme_to_global( $type, $value ) {
@@ -354,9 +216,9 @@
354 216 * @access public
355 217 */
356 218 public function convert_scheme_to_global( $scheme ) {
357 219 if ( isset( $scheme['type'] ) && isset( $scheme['value'] ) ) {
358 - // _deprecated_argument( $args['scheme'], '3.0.0', 'Schemes are now deprecated - use $args[\'global\'] instead.' );
220 + //_deprecated_argument( $args['scheme'], '3.0.0', 'Schemes are now deprecated - use $args[\'global\'] instead.' );
359 221 return $this->map_scheme_to_global( $scheme['type'], $scheme['value'] );
360 222 }
361 223
362 224 // Typography control 'scheme' properties usually only include the string with the typography value ('1'-'4').
@@ -365,9 +227,9 @@
365 227
366 228 public function register_controls() {
367 229 $controls_manager = Plugin::$instance->controls_manager;
368 230
369 - $controls_manager->register( new Repeater() );
231 + $controls_manager->register_control( Repeater::CONTROL_TYPE, new Repeater() );
370 232 }
371 233
372 234 public function is_custom_colors_enabled() {
373 235 return ! get_option( 'elementor_disable_color_schemes' );
@@ -376,95 +238,8 @@
376 238 public function is_custom_typography_enabled() {
377 239 return ! get_option( 'elementor_disable_typography_schemes' );
378 240 }
379 241
380 - /**
381 - * Add kit wrapper body class.
382 - *
383 - * It should be added even for non Elementor pages,
384 - * in order to support embedded templates.
385 - */
386 - private function add_body_class() {
387 - $kit = $this->get_kit_for_frontend();
388 -
389 - if ( $kit ) {
390 - Plugin::$instance->frontend->add_body_class( 'elementor-kit-' . $kit->get_main_id() );
391 - }
392 - }
393 -
394 - /**
395 - * Send a confirm message before move a kit to trash, or if delete permanently not for trash.
396 - *
397 - * @param $post_id
398 - * @param bool $is_permanently_delete
399 - */
400 - private function before_delete_kit( $post_id, $is_permanently_delete = false ) {
401 - if ( $this->should_skip_trash_kit_confirmation ) {
402 - return;
403 - }
404 -
405 - $document = Plugin::$instance->documents->get( $post_id );
406 -
407 - if (
408 - ! $document ||
409 - ! $this->is_kit( $post_id ) ||
410 - isset( $_GET['force_delete_kit'] ) || // phpcs:ignore -- nonce validation is not require here.
411 - ( $is_permanently_delete && $document->is_trash() )
412 - ) {
413 - return;
414 - }
415 -
416 - ob_start();
417 - require __DIR__ . '/views/trash-kit-confirmation.php';
418 -
419 - $confirmation_content = ob_get_clean();
420 -
421 - // PHPCS - the content does not contain user input value.
422 - wp_die( new \WP_Error( 'cant_delete_kit', $confirmation_content ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
423 - }
424 -
425 - /**
426 - * Add 'Edit with elementor -> Site Settings' in admin bar.
427 - *
428 - * @param [] $admin_bar_config
429 - *
430 - * @return array $admin_bar_config
431 - */
432 - private function add_menu_in_admin_bar( $admin_bar_config ) {
433 - $document = Plugin::$instance->documents->get( get_the_ID() );
434 -
435 - if ( ! $document || ! $document->is_built_with_elementor() ) {
436 - $recent_edited_post = Utils::get_recently_edited_posts_query( [
437 - 'posts_per_page' => 1,
438 - ] );
439 -
440 - if ( $recent_edited_post->post_count ) {
441 - $posts = $recent_edited_post->get_posts();
442 - $document = Plugin::$instance->documents->get( reset( $posts )->ID );
443 - }
444 - }
445 -
446 - if ( $document ) {
447 - $document_edit_url = add_query_arg(
448 - [
449 - 'active-document' => $this->get_active_id(),
450 - ],
451 - $document->get_edit_url()
452 - );
453 -
454 - $admin_bar_config['elementor_edit_page']['children'][] = [
455 - 'id' => 'elementor_site_settings',
456 - 'title' => esc_html__( 'Site Settings', 'elementor' ),
457 - 'sub_title' => esc_html__( 'Site', 'elementor' ),
458 - 'href' => $document_edit_url,
459 - 'class' => 'elementor-site-settings',
460 - 'parent_class' => 'elementor-second-section',
461 - ];
462 - }
463 -
464 - return $admin_bar_config;
465 - }
466 -
467 242 public function __construct() {
468 243 add_action( 'elementor/documents/register', [ $this, 'register_document' ] );
469 244 add_filter( 'elementor/editor/localize_settings', [ $this, 'localize_settings' ] );
470 245 add_filter( 'elementor/editor/footer', [ $this, 'render_panel_html' ] );
@@ -469,31 +244,7 @@
469 244 add_filter( 'elementor/editor/localize_settings', [ $this, 'localize_settings' ] );
470 245 add_filter( 'elementor/editor/footer', [ $this, 'render_panel_html' ] );
471 246 add_action( 'elementor/frontend/after_enqueue_styles', [ $this, 'frontend_before_enqueue_styles' ], 0 );
472 247 add_action( 'elementor/preview/enqueue_styles', [ $this, 'preview_enqueue_styles' ], 0 );
473 - add_action( 'elementor/controls/register', [ $this, 'register_controls' ] );
474 -
475 - add_action( 'wp_trash_post', function ( $post_id ) {
476 - $this->before_delete_kit( $post_id );
477 - } );
478 -
479 - add_action( 'before_delete_post', function ( $post_id ) {
480 - $this->before_delete_kit( $post_id, true );
481 - } );
482 -
483 - add_action( 'update_option_blogname', function ( $old_value, $value ) {
484 - $this->update_kit_settings_based_on_option( 'site_name', $value );
485 - }, 10, 2 );
486 -
487 - add_action( 'update_option_blogdescription', function ( $old_value, $value ) {
488 - $this->update_kit_settings_based_on_option( 'site_description', $value );
489 - }, 10, 2 );
490 -
491 - add_action( 'wp_head', function() {
492 - $this->add_body_class();
493 - } );
494 -
495 - add_filter( 'elementor/frontend/admin_bar/settings', function ( $admin_bar_config ) {
496 - return $this->add_menu_in_admin_bar( $admin_bar_config );
497 - }, 9 /* Before site-editor (theme-builder) */ );
248 + add_action( 'elementor/controls/controls_registered', [ $this, 'register_controls' ] );
498 249 }
499 250 }