PluginProbe
Elementor Website Builder – more than just a page builder / 3.1.3
Elementor Website Builder – more than just a page builder v3.1.3
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 +26 -197 4.0.93.1.3 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,69 +18,34 @@
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 47 /**
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 -
71 - /**
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 48 * Checks if specific post is a kit.
86 49 *
87 50 * @param $post_id
88 51 *
@@ -116,104 +79,19 @@
116 79
117 80 return $kit->get_settings( $setting );
118 81 }
119 82
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 - $id = $this->create( [
142 - 'post_title' => $kit_name,
143 - 'settings' => $settings,
144 - ] );
145 -
146 - if ( $active ) {
147 - update_option( self::OPTION_PREVIOUS, $this->get_active_id() );
148 - update_option( self::OPTION_ACTIVE, $id );
149 - }
150 -
151 - return $id;
152 - }
153 -
154 - public function create_default() {
155 - return $this->create( [
156 - 'post_title' => esc_html__( 'Default Kit', 'elementor' ),
157 - ] );
158 - }
159 -
160 - /**
161 - * Create a default kit if needed.
162 - *
163 - * This action runs on activation hook, all the Plugin components do not exists and
164 - * the Document manager and Kits manager instances cannot be used.
165 - *
166 - * @return int|void|\WP_Error
167 - */
168 - public static function create_default_kit() {
169 - if ( get_option( self::OPTION_ACTIVE ) ) {
170 - return;
171 - }
172 -
173 - $id = wp_insert_post( [
174 - 'post_title' => esc_html__( 'Default Kit', 'elementor' ),
83 + private function create_default() {
84 + $kit = Plugin::$instance->documents->create( 'kit', [
175 85 'post_type' => Source_Local::CPT,
86 + 'post_title' => __( 'Default Kit', 'elementor' ),
176 87 'post_status' => 'publish',
177 - 'meta_input' => [
178 - '_elementor_edit_mode' => 'builder',
179 - Document::TYPE_META_KEY => 'kit',
180 - ],
181 88 ] );
182 89
183 - update_option( self::OPTION_ACTIVE, $id );
184 -
185 - return $id;
90 + return $kit->get_id();
186 91 }
187 92
188 93 /**
189 - * @param $imported_kit_id int The id of the imported kit that should be deleted.
190 - * @param $active_kit_id int The id of the kit that should set as 'active_kit' after the deletion.
191 - * @param $previous_kit_id int The id of the kit that should set as 'previous_kit' after the deletion.
192 - * @return void
193 - */
194 - public function revert( int $imported_kit_id, int $active_kit_id, int $previous_kit_id ) {
195 - // If the kit that should set as active is not a valid kit then abort the revert.
196 - if ( ! $this->is_kit( $active_kit_id ) ) {
197 - return;
198 - }
199 -
200 - // This a hacky solution to avoid from the revert process to be interrupted by the `trash_kit_confirmation`.
201 - $this->should_skip_trash_kit_confirmation = true;
202 -
203 - $kit = $this->get_kit( $imported_kit_id );
204 - $kit->force_delete();
205 -
206 - $this->should_skip_trash_kit_confirmation = false;
207 -
208 - update_option( self::OPTION_ACTIVE, $active_kit_id );
209 -
210 - if ( $this->is_kit( $previous_kit_id ) ) {
211 - update_option( self::OPTION_PREVIOUS, $previous_kit_id );
212 - }
213 - }
214 -
215 - /**
216 94 * @param Documents_Manager $documents_manager
217 95 */
218 96 public function register_document( $documents_manager ) {
219 97 $documents_manager->register_document_type( 'kit', Kit::get_class_full_name() );
@@ -276,9 +154,9 @@
276 154 $is_kit_preview = is_preview() && isset( $_GET['preview_id'] ) && $active_kit->get_main_id() === (int) $_GET['preview_id'];
277 155
278 156 if ( $is_kit_preview ) {
279 157 $kit = Plugin::$instance->documents->get_doc_or_auto_save( $active_kit->get_main_id(), get_current_user_id() );
280 - } elseif ( null !== $active_kit->get_main_post() && 'publish' === $active_kit->get_main_post()->post_status ) {
158 + } elseif ( 'publish' === $active_kit->get_main_post()->post_status ) {
281 159 $kit = $active_kit;
282 160 }
283 161
284 162 return $kit;
@@ -299,9 +177,9 @@
299 177 * Map Scheme To Global
300 178 *
301 179 * Convert a given scheme value to its corresponding default global value
302 180 *
303 - * @param string $type 'color'/'typography'.
181 + * @param string $type 'color'/'typography'
304 182 * @param $value
305 183 * @return mixed
306 184 */
307 185 private function map_scheme_to_global( $type, $value ) {
@@ -334,9 +212,9 @@
334 212 * @access public
335 213 */
336 214 public function convert_scheme_to_global( $scheme ) {
337 215 if ( isset( $scheme['type'] ) && isset( $scheme['value'] ) ) {
338 - // _deprecated_argument( $args['scheme'], '3.0.0', 'Schemes are now deprecated - use $args[\'global\'] instead.' );
216 + //_deprecated_argument( $args['scheme'], '3.0.0', 'Schemes are now deprecated - use $args[\'global\'] instead.' );
339 217 return $this->map_scheme_to_global( $scheme['type'], $scheme['value'] );
340 218 }
341 219
342 220 // Typography control 'scheme' properties usually only include the string with the typography value ('1'-'4').
@@ -345,9 +223,9 @@
345 223
346 224 public function register_controls() {
347 225 $controls_manager = Plugin::$instance->controls_manager;
348 226
349 - $controls_manager->register( new Repeater() );
227 + $controls_manager->register_control( Repeater::CONTROL_TYPE, new Repeater() );
350 228 }
351 229
352 230 public function is_custom_colors_enabled() {
353 231 return ! get_option( 'elementor_disable_color_schemes' );
@@ -373,16 +251,12 @@
373 251
374 252 /**
375 253 * Send a confirm message before move a kit to trash, or if delete permanently not for trash.
376 254 *
377 - * @param $post_id
378 - * @param bool $is_permanently_delete
255 + * @param $post_id
256 + * @param false $is_permanently_delete
379 257 */
380 258 private function before_delete_kit( $post_id, $is_permanently_delete = false ) {
381 - if ( $this->should_skip_trash_kit_confirmation ) {
382 - return;
383 - }
384 -
385 259 $document = Plugin::$instance->documents->get( $post_id );
386 260
387 261 if (
388 262 ! $document ||
@@ -397,54 +271,13 @@
397 271 require __DIR__ . '/views/trash-kit-confirmation.php';
398 272
399 273 $confirmation_content = ob_get_clean();
400 274
401 - // PHPCS - the content does not contain user input value.
402 - wp_die( new \WP_Error( 'cant_delete_kit', $confirmation_content ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
275 + wp_die(
276 + new \WP_Error( 'cant_delete_kit', $confirmation_content )
277 + );
403 278 }
404 279
405 - /**
406 - * Add 'Edit with elementor -> Site Settings' in admin bar.
407 - *
408 - * @param [] $admin_bar_config
409 - *
410 - * @return array $admin_bar_config
411 - */
412 - private function add_menu_in_admin_bar( $admin_bar_config ) {
413 - $document = Plugin::$instance->documents->get( get_the_ID() );
414 -
415 - if ( ! $document || ! $document->is_built_with_elementor() ) {
416 - $recent_edited_post = Utils::get_recently_edited_posts_query( [
417 - 'posts_per_page' => 1,
418 - ] );
419 -
420 - if ( $recent_edited_post->post_count ) {
421 - $posts = $recent_edited_post->get_posts();
422 - $document = Plugin::$instance->documents->get( reset( $posts )->ID );
423 - }
424 - }
425 -
426 - if ( $document ) {
427 - $document_edit_url = add_query_arg(
428 - [
429 - 'active-document' => $this->get_active_id(),
430 - ],
431 - $document->get_edit_url()
432 - );
433 -
434 - $admin_bar_config['elementor_edit_page']['children'][] = [
435 - 'id' => 'elementor_site_settings',
436 - 'title' => esc_html__( 'Site Settings', 'elementor' ),
437 - 'sub_title' => esc_html__( 'Site', 'elementor' ),
438 - 'href' => $document_edit_url,
439 - 'class' => 'elementor-site-settings',
440 - 'parent_class' => 'elementor-second-section',
441 - ];
442 - }
443 -
444 - return $admin_bar_config;
445 - }
446 -
447 280 public function __construct() {
448 281 add_action( 'elementor/documents/register', [ $this, 'register_document' ] );
449 282 add_filter( 'elementor/editor/localize_settings', [ $this, 'localize_settings' ] );
450 283 add_filter( 'elementor/editor/footer', [ $this, 'render_panel_html' ] );
@@ -449,9 +282,9 @@
449 282 add_filter( 'elementor/editor/localize_settings', [ $this, 'localize_settings' ] );
450 283 add_filter( 'elementor/editor/footer', [ $this, 'render_panel_html' ] );
451 284 add_action( 'elementor/frontend/after_enqueue_styles', [ $this, 'frontend_before_enqueue_styles' ], 0 );
452 285 add_action( 'elementor/preview/enqueue_styles', [ $this, 'preview_enqueue_styles' ], 0 );
453 - add_action( 'elementor/controls/register', [ $this, 'register_controls' ] );
286 + add_action( 'elementor/controls/controls_registered', [ $this, 'register_controls' ] );
454 287
455 288 add_action( 'wp_trash_post', function ( $post_id ) {
456 289 $this->before_delete_kit( $post_id );
457 290 } );
@@ -470,10 +303,6 @@
470 303
471 304 add_action( 'wp_head', function() {
472 305 $this->add_body_class();
473 306 } );
474 -
475 - add_filter( 'elementor/frontend/admin_bar/settings', function ( $admin_bar_config ) {
476 - return $this->add_menu_in_admin_bar( $admin_bar_config );
477 - }, 9 /* Before site-editor (theme-builder) */ );
478 307 }
479 308 }