| @@ -6,9 +6,9 @@ | ||
| 6 | 6 | use Elementor\Core\Kits\Documents\Tabs\Global_Colors; |
| 7 | 7 | use Elementor\Core\Kits\Documents\Tabs\Global_Typography; |
| 8 | 8 | use Elementor\Plugin; |
| 9 | 9 | use Elementor\Core\Files\CSS\Post as Post_CSS; |
| 10 | -use Elementor\Core\Files\CSS\Post_Preview; | |
| 10 | +use Elementor\Core\Files\CSS\Post_Preview as Post_Preview; | |
| 11 | 11 | use Elementor\Core\Documents_Manager; |
| 12 | 12 | use Elementor\Core\Kits\Documents\Kit; |
| 13 | 13 | use Elementor\TemplateLibrary\Source_Local; |
| 14 | 14 | use Elementor\Utils; |
| @@ -20,25 +20,17 @@ | ||
| 20 | 20 | class Manager { |
| 21 | 21 | |
| 22 | 22 | const OPTION_ACTIVE = 'elementor_active_kit'; |
| 23 | 23 | |
| 24 | - const OPTION_PREVIOUS = 'elementor_previous_kit'; | |
| 25 | - | |
| 26 | 24 | const E_HASH_COMMAND_OPEN_SITE_SETTINGS = 'e:run:panel/global/open'; |
| 27 | 25 | |
| 28 | - private $should_skip_trash_kit_confirmation = false; | |
| 29 | - | |
| 30 | 26 | public function get_active_id() { |
| 31 | 27 | return get_option( self::OPTION_ACTIVE ); |
| 32 | 28 | } |
| 33 | 29 | |
| 34 | - public function get_previous_id() { | |
| 35 | - return get_option( self::OPTION_PREVIOUS ); | |
| 36 | - } | |
| 30 | + public function get_active_kit() { | |
| 31 | + $kit = Plugin::$instance->documents->get( $this->get_active_id() ); | |
| 37 | 32 | |
| 38 | - public function get_kit( $kit_id ) { | |
| 39 | - $kit = Plugin::$instance->documents->get( $kit_id ); | |
| 40 | - | |
| 41 | 33 | if ( ! $this->is_valid_kit( $kit ) ) { |
| 42 | 34 | return $this->get_empty_kit_instance(); |
| 43 | 35 | } |
| 44 | 36 | |
| @@ -44,12 +36,8 @@ | ||
| 44 | 36 | |
| 45 | 37 | return $kit; |
| 46 | 38 | } |
| 47 | 39 | |
| 48 | - public function get_active_kit() { | |
| 49 | - return $this->get_kit( $this->get_active_id() ); | |
| 50 | - } | |
| 51 | - | |
| 52 | 40 | public function get_active_kit_for_frontend() { |
| 53 | 41 | $kit = Plugin::$instance->documents->get_doc_for_frontend( $this->get_active_id() ); |
| 54 | 42 | |
| 55 | 43 | if ( ! $this->is_valid_kit( $kit ) ) { |
| @@ -71,9 +59,9 @@ | ||
| 71 | 59 | /** |
| 72 | 60 | * Returns an empty kit for situation when there is no kit in the site. |
| 73 | 61 | * |
| 74 | 62 | * @return Kit |
| 75 | - * @throws \Exception If the kit instance cannot be created. | |
| 63 | + * @throws \Exception | |
| 76 | 64 | */ |
| 77 | 65 | private function get_empty_kit_instance() { |
| 78 | 66 | return new Kit( [ |
| 79 | 67 | 'settings' => [], |
| @@ -127,56 +115,11 @@ | ||
| 127 | 115 | $kit_data['post_type'] = Source_Local::CPT; |
| 128 | 116 | |
| 129 | 117 | $kit = Plugin::$instance->documents->create( 'kit', $kit_data, $kit_meta_data ); |
| 130 | 118 | |
| 131 | - if ( isset( $kit_data['settings'] ) ) { | |
| 132 | - $kit->save( [ 'settings' => $kit_data['settings'] ] ); | |
| 133 | - } | |
| 134 | - | |
| 135 | 119 | return $kit->get_id(); |
| 136 | 120 | } |
| 137 | 121 | |
| 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 | - do_action( 'elementor/kit/after_new_kit_created', [ | |
| 156 | - 'new_kit_id' => $id, | |
| 157 | - 'previous_kit_id' => $current_kit->get_post()->ID, | |
| 158 | - ] ); | |
| 159 | - | |
| 160 | - return $id; | |
| 161 | - } | |
| 162 | - | |
| 163 | - private function get_meta_to_preserve( Kit $current_kit ): array { | |
| 164 | - $meta_keys_to_preserve = apply_filters( 'elementor/kit/meta_to_preserve_on_kit_import', [] ); | |
| 165 | - | |
| 166 | - $kit_meta_data = []; | |
| 167 | - | |
| 168 | - foreach ( $meta_keys_to_preserve as $meta_key ) { | |
| 169 | - $value = $current_kit->get_meta( $meta_key ); | |
| 170 | - | |
| 171 | - if ( ! empty( $value ) ) { | |
| 172 | - $kit_meta_data[ $meta_key ] = $value; | |
| 173 | - } | |
| 174 | - } | |
| 175 | - | |
| 176 | - return $kit_meta_data; | |
| 177 | - } | |
| 178 | - | |
| 179 | 122 | public function create_default() { |
| 180 | 123 | return $this->create( [ |
| 181 | 124 | 'post_title' => esc_html__( 'Default Kit', 'elementor' ), |
| 182 | 125 | ] ); |
| @@ -195,9 +138,9 @@ | ||
| 195 | 138 | return; |
| 196 | 139 | } |
| 197 | 140 | |
| 198 | 141 | $id = wp_insert_post( [ |
| 199 | - 'post_title' => esc_html__( 'Default Kit', 'elementor' ), | |
| 142 | + 'post_title' => __( 'Default Kit', 'elementor' ), | |
| 200 | 143 | 'post_type' => Source_Local::CPT, |
| 201 | 144 | 'post_status' => 'publish', |
| 202 | 145 | 'meta_input' => [ |
| 203 | 146 | '_elementor_edit_mode' => 'builder', |
| @@ -210,35 +153,8 @@ | ||
| 210 | 153 | return $id; |
| 211 | 154 | } |
| 212 | 155 | |
| 213 | 156 | /** |
| 214 | - * @param $imported_kit_id int The id of the imported kit that should be deleted. | |
| 215 | - * @param $active_kit_id int The id of the kit that should set as 'active_kit' after the deletion. | |
| 216 | - * @param $previous_kit_id int The id of the kit that should set as 'previous_kit' after the deletion. | |
| 217 | - * @return void | |
| 218 | - */ | |
| 219 | - public function revert( int $imported_kit_id, int $active_kit_id, int $previous_kit_id ) { | |
| 220 | - // If the kit that should set as active is not a valid kit then abort the revert. | |
| 221 | - if ( ! $this->is_kit( $active_kit_id ) ) { | |
| 222 | - return; | |
| 223 | - } | |
| 224 | - | |
| 225 | - // This a hacky solution to avoid from the revert process to be interrupted by the `trash_kit_confirmation`. | |
| 226 | - $this->should_skip_trash_kit_confirmation = true; | |
| 227 | - | |
| 228 | - $kit = $this->get_kit( $imported_kit_id ); | |
| 229 | - $kit->force_delete(); | |
| 230 | - | |
| 231 | - $this->should_skip_trash_kit_confirmation = false; | |
| 232 | - | |
| 233 | - update_option( self::OPTION_ACTIVE, $active_kit_id ); | |
| 234 | - | |
| 235 | - if ( $this->is_kit( $previous_kit_id ) ) { | |
| 236 | - update_option( self::OPTION_PREVIOUS, $previous_kit_id ); | |
| 237 | - } | |
| 238 | - } | |
| 239 | - | |
| 240 | - /** | |
| 241 | 157 | * @param Documents_Manager $documents_manager |
| 242 | 158 | */ |
| 243 | 159 | public function register_document( $documents_manager ) { |
| 244 | 160 | $documents_manager->register_document_type( 'kit', Kit::get_class_full_name() ); |
| @@ -301,9 +217,9 @@ | ||
| 301 | 217 | $is_kit_preview = is_preview() && isset( $_GET['preview_id'] ) && $active_kit->get_main_id() === (int) $_GET['preview_id']; |
| 302 | 218 | |
| 303 | 219 | if ( $is_kit_preview ) { |
| 304 | 220 | $kit = Plugin::$instance->documents->get_doc_or_auto_save( $active_kit->get_main_id(), get_current_user_id() ); |
| 305 | - } elseif ( null !== $active_kit->get_main_post() && 'publish' === $active_kit->get_main_post()->post_status ) { | |
| 221 | + } elseif ( 'publish' === $active_kit->get_main_post()->post_status ) { | |
| 306 | 222 | $kit = $active_kit; |
| 307 | 223 | } |
| 308 | 224 | |
| 309 | 225 | return $kit; |
| @@ -324,9 +240,9 @@ | ||
| 324 | 240 | * Map Scheme To Global |
| 325 | 241 | * |
| 326 | 242 | * Convert a given scheme value to its corresponding default global value |
| 327 | 243 | * |
| 328 | - * @param string $type 'color'/'typography'. | |
| 244 | + * @param string $type 'color'/'typography' | |
| 329 | 245 | * @param $value |
| 330 | 246 | * @return mixed |
| 331 | 247 | */ |
| 332 | 248 | private function map_scheme_to_global( $type, $value ) { |
| @@ -359,9 +275,9 @@ | ||
| 359 | 275 | * @access public |
| 360 | 276 | */ |
| 361 | 277 | public function convert_scheme_to_global( $scheme ) { |
| 362 | 278 | if ( isset( $scheme['type'] ) && isset( $scheme['value'] ) ) { |
| 363 | - // _deprecated_argument( $args['scheme'], '3.0.0', 'Schemes are now deprecated - use $args[\'global\'] instead.' ); | |
| 279 | + //_deprecated_argument( $args['scheme'], '3.0.0', 'Schemes are now deprecated - use $args[\'global\'] instead.' ); | |
| 364 | 280 | return $this->map_scheme_to_global( $scheme['type'], $scheme['value'] ); |
| 365 | 281 | } |
| 366 | 282 | |
| 367 | 283 | // Typography control 'scheme' properties usually only include the string with the typography value ('1'-'4'). |
| @@ -370,9 +286,9 @@ | ||
| 370 | 286 | |
| 371 | 287 | public function register_controls() { |
| 372 | 288 | $controls_manager = Plugin::$instance->controls_manager; |
| 373 | 289 | |
| 374 | - $controls_manager->register( new Repeater() ); | |
| 290 | + $controls_manager->register_control( Repeater::CONTROL_TYPE, new Repeater() ); | |
| 375 | 291 | } |
| 376 | 292 | |
| 377 | 293 | public function is_custom_colors_enabled() { |
| 378 | 294 | return ! get_option( 'elementor_disable_color_schemes' ); |
| @@ -398,16 +314,12 @@ | ||
| 398 | 314 | |
| 399 | 315 | /** |
| 400 | 316 | * Send a confirm message before move a kit to trash, or if delete permanently not for trash. |
| 401 | 317 | * |
| 402 | - * @param $post_id | |
| 403 | - * @param bool $is_permanently_delete | |
| 318 | + * @param $post_id | |
| 319 | + * @param false $is_permanently_delete | |
| 404 | 320 | */ |
| 405 | 321 | private function before_delete_kit( $post_id, $is_permanently_delete = false ) { |
| 406 | - if ( $this->should_skip_trash_kit_confirmation ) { | |
| 407 | - return; | |
| 408 | - } | |
| 409 | - | |
| 410 | 322 | $document = Plugin::$instance->documents->get( $post_id ); |
| 411 | 323 | |
| 412 | 324 | if ( |
| 413 | 325 | ! $document || |
| @@ -448,20 +360,13 @@ | ||
| 448 | 360 | } |
| 449 | 361 | } |
| 450 | 362 | |
| 451 | 363 | if ( $document ) { |
| 452 | - $document_edit_url = add_query_arg( | |
| 453 | - [ | |
| 454 | - 'active-document' => $this->get_active_id(), | |
| 455 | - ], | |
| 456 | - $document->get_edit_url() | |
| 457 | - ); | |
| 458 | - | |
| 459 | 364 | $admin_bar_config['elementor_edit_page']['children'][] = [ |
| 460 | 365 | 'id' => 'elementor_site_settings', |
| 461 | 366 | 'title' => esc_html__( 'Site Settings', 'elementor' ), |
| 462 | 367 | 'sub_title' => esc_html__( 'Site', 'elementor' ), |
| 463 | - 'href' => $document_edit_url, | |
| 368 | + 'href' => $document->get_edit_url() . '#' . self::E_HASH_COMMAND_OPEN_SITE_SETTINGS, | |
| 464 | 369 | 'class' => 'elementor-site-settings', |
| 465 | 370 | 'parent_class' => 'elementor-second-section', |
| 466 | 371 | ]; |
| 467 | 372 | } |
| @@ -474,9 +379,9 @@ | ||
| 474 | 379 | add_filter( 'elementor/editor/localize_settings', [ $this, 'localize_settings' ] ); |
| 475 | 380 | add_filter( 'elementor/editor/footer', [ $this, 'render_panel_html' ] ); |
| 476 | 381 | add_action( 'elementor/frontend/after_enqueue_styles', [ $this, 'frontend_before_enqueue_styles' ], 0 ); |
| 477 | 382 | add_action( 'elementor/preview/enqueue_styles', [ $this, 'preview_enqueue_styles' ], 0 ); |
| 478 | - add_action( 'elementor/controls/register', [ $this, 'register_controls' ] ); | |
| 383 | + add_action( 'elementor/controls/controls_registered', [ $this, 'register_controls' ] ); | |
| 479 | 384 | |
| 480 | 385 | add_action( 'wp_trash_post', function ( $post_id ) { |
| 481 | 386 | $this->before_delete_kit( $post_id ); |
| 482 | 387 | } ); |