PluginProbe
Elementor Website Builder – more than just a page builder / 3.35.8
Elementor Website Builder – more than just a page builder v3.35.8
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 | includes/template-library/sources/local.php +94 -11 4.1.0-beta23.35.8 View file →
@@ -1,7 +1,8 @@
1 1 <?php
2 2 namespace Elementor\TemplateLibrary;
3 3
4 +use Elementor\Core\Admin\Menu\Admin_Menu_Manager;
4 5 use Elementor\Core\Base\Document;
5 6 use Elementor\Core\Editor\Editor;
6 7 use Elementor\Core\Utils\Collection;
7 8 use Elementor\DB;
@@ -352,14 +353,90 @@
352 353
353 354 register_taxonomy( self::TAXONOMY_CATEGORY_SLUG, self::CPT, $args );
354 355 }
355 356
357 + /**
358 + * Remove Add New item from admin menu.
359 + *
360 + * Fired by `admin_menu` action.
361 + *
362 + * @since 2.4.0
363 + * @access public
364 + */
365 + private function admin_menu_reorder( Admin_Menu_Manager $admin_menu ) {
366 + global $submenu;
356 367
368 + if ( ! isset( $submenu[ static::ADMIN_MENU_SLUG ] ) ) {
369 + return;
370 + }
371 +
372 + remove_submenu_page( static::ADMIN_MENU_SLUG, static::ADMIN_MENU_SLUG );
373 +
374 + $add_new_slug = 'post-new.php?post_type=' . static::CPT;
375 + $category_slug = 'edit-tags.php?taxonomy=' . static::TAXONOMY_CATEGORY_SLUG . '&amp;post_type=' . static::CPT;
376 +
377 + $library_submenu = new Collection( $submenu[ static::ADMIN_MENU_SLUG ] );
378 +
379 + $add_new_item = $library_submenu->find( function ( $item ) use ( $add_new_slug ) {
380 + return $add_new_slug === $item[2];
381 + } );
382 +
383 + $categories_item = $library_submenu->find( function ( $item ) use ( $category_slug ) {
384 + return $category_slug === $item[2];
385 + } );
386 +
387 + if ( $add_new_item ) {
388 + remove_submenu_page( static::ADMIN_MENU_SLUG, $add_new_slug );
389 +
390 + $admin_menu->register( admin_url( static::ADMIN_MENU_SLUG . '#add_new' ), new Add_New_Template_Menu_Item() );
391 + }
392 +
393 + if ( $categories_item ) {
394 + remove_submenu_page( static::ADMIN_MENU_SLUG, $category_slug );
395 +
396 + $admin_menu->register( $category_slug, new Templates_Categories_Menu_Item() );
397 + }
398 + }
399 +
400 + /**
401 + * Add a `current` CSS class to the `Saved Templates` submenu page when it's active.
402 + * It should work by default, but since we interfere with WordPress' builtin CPT menus it doesn't work properly.
403 + *
404 + * @return void
405 + */
406 + private function admin_menu_set_current() {
407 + global $submenu;
408 +
409 + if ( $this->is_current_screen() ) {
410 + $library_submenu = &$submenu[ static::ADMIN_MENU_SLUG ];
411 + $library_title = $this->get_library_title();
412 +
413 + foreach ( $library_submenu as &$item ) {
414 + if ( $library_title === $item[0] ) {
415 + if ( ! isset( $item[4] ) ) {
416 + $item[4] = '';
417 + }
418 + $item[4] .= ' current';
419 + }
420 + }
421 + }
422 + }
423 +
424 + private function register_admin_menu( Admin_Menu_Manager $admin_menu ) {
425 + if ( ! $this->is_editor_one_active() ) {
426 + $admin_menu->register( static::get_admin_url( true ), new Saved_Templates_Menu_Item() );
427 + }
428 + }
429 +
357 430 private function register_editor_one_menu( Menu_Data_Provider $menu_data_provider ) {
358 431 $menu_data_provider->register_menu( new Editor_One_Templates_Menu() );
359 432 $menu_data_provider->register_menu( new Editor_One_Saved_Templates_Menu() );
360 433 }
361 434
435 + private function is_editor_one_active(): bool {
436 + return (bool) Plugin::instance()->modules_manager->get_modules( 'editor-one' );
437 + }
438 +
362 439 public function admin_title( $admin_title, $title ) {
363 440 $library_title = $this->get_library_title();
364 441
365 442 if ( $library_title ) {
@@ -743,12 +820,8 @@
743 820
744 821 $data['page_settings'] = $page->get_data( 'settings' );
745 822 }
746 823
747 - if ( ! empty( $content ) ) {
748 - $this->attach_global_styles_to_data( $data, $content, $template_id );
749 - }
750 -
751 824 return $data;
752 825 }
753 826
754 827 /**
@@ -923,9 +996,9 @@
923 996 * @param string $name - The file name.
924 997 * @param string $path - The file path.
925 998 * @return \WP_Error|array An array of items on success, 'WP_Error' on failure.
926 999 */
927 - public function import_template( $name, $path, $import_mode = 'match_site' ) {
1000 + public function import_template( $name, $path ) {
928 1001 if ( empty( $path ) ) {
929 1002 return new \WP_Error( 'file_error', 'Please upload a file to import' );
930 1003 }
931 1004
@@ -950,9 +1023,9 @@
950 1023 if ( false !== strpos( $file_path, '__MACOSX' ) || '.' === basename( $file_path )[0] ) {
951 1024 continue;
952 1025 }
953 1026
954 - $import_result = $this->import_single_template( $file_path, $import_mode );
1027 + $import_result = $this->import_single_template( $file_path );
955 1028
956 1029 if ( is_wp_error( $import_result ) ) {
957 1030 // Skip failed files
958 1031 continue;
@@ -964,9 +1037,9 @@
964 1037 // Delete the temporary extraction directory, since it's now not necessary.
965 1038 Plugin::$instance->uploads_manager->remove_file_or_dir( $extracted_files['extraction_directory'] );
966 1039 } else {
967 1040 // If the import file is a single JSON file
968 - $import_result = $this->import_single_template( $path, $import_mode );
1041 + $import_result = $this->import_single_template( $path );
969 1042
970 1043 if ( is_wp_error( $import_result ) ) {
971 1044 return $import_result;
972 1045 }
@@ -1529,10 +1602,10 @@
1529 1602 *
1530 1603 * @return \WP_Error|int|array Local template array, or template ID, or
1531 1604 * `WP_Error`.
1532 1605 */
1533 - private function import_single_template( $file_path, $import_mode = 'match_site' ) {
1534 - $data = $this->prepare_import_template_data( $file_path, $import_mode );
1606 + private function import_single_template( $file_path ) {
1607 + $data = $this->prepare_import_template_data( $file_path );
1535 1608
1536 1609 if ( is_wp_error( $data ) ) {
1537 1610 return $data;
1538 1611 }
@@ -1588,10 +1661,8 @@
1588 1661 'title' => $document->get_main_post()->post_title,
1589 1662 'type' => self::get_template_type( $template_id ),
1590 1663 ];
1591 1664
1592 - $this->attach_global_styles_to_data( $export_data, $content, $template_id );
1593 -
1594 1665 return [
1595 1666 'name' => 'elementor-' . $template_id . '-' . gmdate( 'Y-m-d' ) . '.json',
1596 1667 'content' => wp_json_encode( $export_data ),
1597 1668 ];
@@ -1737,8 +1808,12 @@
1737 1808 * @access private
1738 1809 */
1739 1810 private function add_actions() {
1740 1811 if ( is_admin() ) {
1812 + add_action( 'elementor/admin/menu/register', function ( Admin_Menu_Manager $admin_menu ) {
1813 + $this->register_admin_menu( $admin_menu );
1814 + }, static::ADMIN_MENU_PRIORITY );
1815 +
1741 1816 add_action( 'admin_init', [ $this, 'redirect_categories_page_to_saved_templates_page' ] );
1742 1817
1743 1818 add_action( 'elementor/editor-one/menu/register', function ( Menu_Data_Provider $menu_data_provider ) {
1744 1819 $this->register_editor_one_menu( $menu_data_provider );
@@ -1759,8 +1834,16 @@
1759 1834 add_filter( 'elementor/editor-one/admin-edit-post-types', function ( array $post_types ): array {
1760 1835 $post_types[] = self::CPT;
1761 1836
1762 1837 return $post_types;
1838 + } );
1839 +
1840 + add_action( 'elementor/admin/menu/register', function ( Admin_Menu_Manager $admin_menu ) {
1841 + $this->admin_menu_reorder( $admin_menu );
1842 + }, 800 );
1843 +
1844 + add_action( 'elementor/admin/menu/after_register', function () {
1845 + $this->admin_menu_set_current();
1763 1846 } );
1764 1847
1765 1848 add_filter( 'admin_title', [ $this, 'admin_title' ], 10, 2 );
1766 1849 add_action( 'all_admin_notices', [ $this, 'replace_admin_heading' ] );