PluginProbe
Elementor Website Builder – more than just a page builder / 3.2.0
Elementor Website Builder – more than just a page builder v3.2.0
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 +27 -148 4.0.93.2.0 View file →
@@ -1,14 +1,13 @@
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 13 use Elementor\Utils;
@@ -20,69 +19,36 @@
20 19 class Manager {
21 20
22 21 const OPTION_ACTIVE = 'elementor_active_kit';
23 22
24 - const OPTION_PREVIOUS = 'elementor_previous_kit';
25 -
26 23 const E_HASH_COMMAND_OPEN_SITE_SETTINGS = 'e:run:panel/global/open';
27 24
28 - private $should_skip_trash_kit_confirmation = false;
29 -
30 25 public function get_active_id() {
31 - return get_option( self::OPTION_ACTIVE );
32 - }
26 + $id = get_option( self::OPTION_ACTIVE );
33 27
34 - public function get_previous_id() {
35 - return get_option( self::OPTION_PREVIOUS );
36 - }
28 + $kit_document = Plugin::$instance->documents->get( $id );
37 29
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();
30 + if ( ! $kit_document || ! $kit_document instanceof Kit || 'trash' === $kit_document->get_main_post()->post_status ) {
31 + $id = $this->create_default();
32 + update_option( self::OPTION_ACTIVE, $id );
43 33 }
44 34
45 - return $kit;
35 + return $id;
46 36 }
47 37
48 38 public function get_active_kit() {
49 - return $this->get_kit( $this->get_active_id() );
39 + $id = $this->get_active_id();
40 +
41 + return Plugin::$instance->documents->get( $id );
50 42 }
51 43
52 44 public function get_active_kit_for_frontend() {
53 - $kit = Plugin::$instance->documents->get_doc_for_frontend( $this->get_active_id() );
45 + $id = $this->get_active_id();
54 46
55 - if ( ! $this->is_valid_kit( $kit ) ) {
56 - return $this->get_empty_kit_instance();
57 - }
58 -
59 - return $kit;
47 + return Plugin::$instance->documents->get_doc_for_frontend( $id );
60 48 }
61 49
62 50 /**
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 51 * Checks if specific post is a kit.
86 52 *
87 53 * @param $post_id
88 54 *
@@ -127,93 +93,16 @@
127 93 $kit_data['post_type'] = Source_Local::CPT;
128 94
129 95 $kit = Plugin::$instance->documents->create( 'kit', $kit_data, $kit_meta_data );
130 96
131 - if ( isset( $kit_data['settings'] ) ) {
132 - $kit->save( [ 'settings' => $kit_data['settings'] ] );
133 - }
134 -
135 97 return $kit->get_id();
136 98 }
137 99
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;
100 + private function create_default() {
101 + return $this->create( [ 'post_title' => __( 'Default Kit', 'elementor' ) ] );
152 102 }
153 103
154 - public function create_default() {
155 - return $this->create( [
156 - 'post_title' => esc_html__( 'Default Kit', 'elementor' ),
157 - ] );
158 - }
159 -
160 104 /**
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' ),
175 - 'post_type' => Source_Local::CPT,
176 - 'post_status' => 'publish',
177 - 'meta_input' => [
178 - '_elementor_edit_mode' => 'builder',
179 - Document::TYPE_META_KEY => 'kit',
180 - ],
181 - ] );
182 -
183 - update_option( self::OPTION_ACTIVE, $id );
184 -
185 - return $id;
186 - }
187 -
188 - /**
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 105 * @param Documents_Manager $documents_manager
217 106 */
218 107 public function register_document( $documents_manager ) {
219 108 $documents_manager->register_document_type( 'kit', Kit::get_class_full_name() );
@@ -276,9 +165,9 @@
276 165 $is_kit_preview = is_preview() && isset( $_GET['preview_id'] ) && $active_kit->get_main_id() === (int) $_GET['preview_id'];
277 166
278 167 if ( $is_kit_preview ) {
279 168 $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 ) {
169 + } elseif ( 'publish' === $active_kit->get_main_post()->post_status ) {
281 170 $kit = $active_kit;
282 171 }
283 172
284 173 return $kit;
@@ -299,9 +188,9 @@
299 188 * Map Scheme To Global
300 189 *
301 190 * Convert a given scheme value to its corresponding default global value
302 191 *
303 - * @param string $type 'color'/'typography'.
192 + * @param string $type 'color'/'typography'
304 193 * @param $value
305 194 * @return mixed
306 195 */
307 196 private function map_scheme_to_global( $type, $value ) {
@@ -334,9 +223,9 @@
334 223 * @access public
335 224 */
336 225 public function convert_scheme_to_global( $scheme ) {
337 226 if ( isset( $scheme['type'] ) && isset( $scheme['value'] ) ) {
338 - // _deprecated_argument( $args['scheme'], '3.0.0', 'Schemes are now deprecated - use $args[\'global\'] instead.' );
227 + //_deprecated_argument( $args['scheme'], '3.0.0', 'Schemes are now deprecated - use $args[\'global\'] instead.' );
339 228 return $this->map_scheme_to_global( $scheme['type'], $scheme['value'] );
340 229 }
341 230
342 231 // Typography control 'scheme' properties usually only include the string with the typography value ('1'-'4').
@@ -345,9 +234,9 @@
345 234
346 235 public function register_controls() {
347 236 $controls_manager = Plugin::$instance->controls_manager;
348 237
349 - $controls_manager->register( new Repeater() );
238 + $controls_manager->register_control( Repeater::CONTROL_TYPE, new Repeater() );
350 239 }
351 240
352 241 public function is_custom_colors_enabled() {
353 242 return ! get_option( 'elementor_disable_color_schemes' );
@@ -373,16 +262,12 @@
373 262
374 263 /**
375 264 * Send a confirm message before move a kit to trash, or if delete permanently not for trash.
376 265 *
377 - * @param $post_id
378 - * @param bool $is_permanently_delete
266 + * @param $post_id
267 + * @param false $is_permanently_delete
379 268 */
380 269 private function before_delete_kit( $post_id, $is_permanently_delete = false ) {
381 - if ( $this->should_skip_trash_kit_confirmation ) {
382 - return;
383 - }
384 -
385 270 $document = Plugin::$instance->documents->get( $post_id );
386 271
387 272 if (
388 273 ! $document ||
@@ -397,10 +282,11 @@
397 282 require __DIR__ . '/views/trash-kit-confirmation.php';
398 283
399 284 $confirmation_content = ob_get_clean();
400 285
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
286 + wp_die(
287 + new \WP_Error( 'cant_delete_kit', $confirmation_content )
288 + );
403 289 }
404 290
405 291 /**
406 292 * Add 'Edit with elementor -> Site Settings' in admin bar.
@@ -423,20 +309,13 @@
423 309 }
424 310 }
425 311
426 312 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 313 $admin_bar_config['elementor_edit_page']['children'][] = [
435 314 'id' => 'elementor_site_settings',
436 - 'title' => esc_html__( 'Site Settings', 'elementor' ),
437 - 'sub_title' => esc_html__( 'Site', 'elementor' ),
438 - 'href' => $document_edit_url,
315 + 'title' => __( 'Site Settings', 'elementor' ),
316 + 'sub_title' => __( 'Site', 'elementor' ),
317 + 'href' => $document->get_edit_url() . '#' . self::E_HASH_COMMAND_OPEN_SITE_SETTINGS,
439 318 'class' => 'elementor-site-settings',
440 319 'parent_class' => 'elementor-second-section',
441 320 ];
442 321 }
@@ -449,9 +328,9 @@
449 328 add_filter( 'elementor/editor/localize_settings', [ $this, 'localize_settings' ] );
450 329 add_filter( 'elementor/editor/footer', [ $this, 'render_panel_html' ] );
451 330 add_action( 'elementor/frontend/after_enqueue_styles', [ $this, 'frontend_before_enqueue_styles' ], 0 );
452 331 add_action( 'elementor/preview/enqueue_styles', [ $this, 'preview_enqueue_styles' ], 0 );
453 - add_action( 'elementor/controls/register', [ $this, 'register_controls' ] );
332 + add_action( 'elementor/controls/controls_registered', [ $this, 'register_controls' ] );
454 333
455 334 add_action( 'wp_trash_post', function ( $post_id ) {
456 335 $this->before_delete_kit( $post_id );
457 336 } );