← All changes
|
includes/template-library/sources/local.php
+120
-176
4.2.1
→
3.35.0-dev2
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; |
| @@ -14,8 +15,9 @@ | ||
| 14 | 15 | use Elementor\Utils; |
| 15 | 16 | use Elementor\User; |
| 16 | 17 | use Elementor\Core\Isolation\Wordpress_Adapter; |
| 17 | 18 | use Elementor\Core\Isolation\Wordpress_Adapter_Interface; |
| 19 | +use Elementor\Core\Isolation\Elementor_Adapter; | |
| 18 | 20 | use Elementor\Core\Isolation\Elementor_Adapter_Interface; |
| 19 | 21 | use Elementor\Modules\EditorOne\Classes\Menu_Data_Provider; |
| 20 | 22 | use Elementor\Includes\TemplateLibrary\Sources\AdminMenuItems\Editor_One_Saved_Templates_Menu; |
| 21 | 23 | use Elementor\Includes\TemplateLibrary\Sources\AdminMenuItems\Editor_One_Templates_Menu; |
| @@ -351,14 +353,90 @@ | ||
| 351 | 353 | |
| 352 | 354 | register_taxonomy( self::TAXONOMY_CATEGORY_SLUG, self::CPT, $args ); |
| 353 | 355 | } |
| 354 | 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; | |
| 355 | 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 . '&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 | + | |
| 356 | 430 | private function register_editor_one_menu( Menu_Data_Provider $menu_data_provider ) { |
| 357 | 431 | $menu_data_provider->register_menu( new Editor_One_Templates_Menu() ); |
| 358 | 432 | $menu_data_provider->register_menu( new Editor_One_Saved_Templates_Menu() ); |
| 359 | 433 | } |
| 360 | 434 | |
| 435 | + private function is_editor_one_active(): bool { | |
| 436 | + return (bool) Plugin::instance()->modules_manager->get_modules( 'editor-one' ); | |
| 437 | + } | |
| 438 | + | |
| 361 | 439 | public function admin_title( $admin_title, $title ) { |
| 362 | 440 | $library_title = $this->get_library_title(); |
| 363 | 441 | |
| 364 | 442 | if ( $library_title ) { |
| @@ -368,54 +446,15 @@ | ||
| 368 | 446 | return $admin_title; |
| 369 | 447 | } |
| 370 | 448 | |
| 371 | 449 | public function replace_admin_heading() { |
| 372 | - if ( ! $this->is_current_screen() ) { | |
| 373 | - return; | |
| 374 | - } | |
| 375 | - | |
| 376 | - global $post_type_object; | |
| 377 | - | |
| 378 | 450 | $library_title = $this->get_library_title(); |
| 379 | 451 | |
| 380 | 452 | if ( $library_title ) { |
| 453 | + global $post_type_object; | |
| 454 | + | |
| 381 | 455 | $post_type_object->labels->name = $library_title; |
| 382 | 456 | } |
| 383 | - | |
| 384 | - $labels = $this->get_current_template_labels(); | |
| 385 | - $template_singular = $labels['singular']; | |
| 386 | - $template_plural = $labels['plural']; | |
| 387 | - | |
| 388 | - if ( ! $template_plural && $library_title ) { | |
| 389 | - $template_plural = $library_title; | |
| 390 | - } | |
| 391 | - | |
| 392 | - if ( $template_singular ) { | |
| 393 | - $labels = $post_type_object->labels; | |
| 394 | - $labels->name = $template_plural; | |
| 395 | - $labels->singular_name = $template_singular; | |
| 396 | - /* translators: %s: Template label (plural). */ | |
| 397 | - $labels->all_items = sprintf( esc_html__( 'All %s', 'elementor' ), $template_plural ); | |
| 398 | - /* translators: %s: Template label (singular). */ | |
| 399 | - $labels->add_new = sprintf( esc_html__( 'Add New %s', 'elementor' ), $template_singular ); | |
| 400 | - $labels->add_new_item = $labels->add_new; | |
| 401 | - /* translators: %s: Template label (singular). */ | |
| 402 | - $labels->edit_item = sprintf( esc_html__( 'Edit %s', 'elementor' ), $template_singular ); | |
| 403 | - /* translators: %s: Template label (singular). */ | |
| 404 | - $labels->new_item = sprintf( esc_html__( 'New %s', 'elementor' ), $template_singular ); | |
| 405 | - /* translators: %s: Template label (singular). */ | |
| 406 | - $labels->view_item = sprintf( esc_html__( 'View %s', 'elementor' ), $template_singular ); | |
| 407 | - /* translators: %s: Template label (plural). */ | |
| 408 | - $labels->search_items = sprintf( esc_html__( 'Search %s', 'elementor' ), $template_plural ); | |
| 409 | - /* translators: %s: Template label (plural). */ | |
| 410 | - $labels->not_found = sprintf( esc_html__( 'No %s found', 'elementor' ), $template_plural ); | |
| 411 | - /* translators: %s: Template label (plural). */ | |
| 412 | - $labels->not_found_in_trash = sprintf( esc_html__( 'No %s found in Trash', 'elementor' ), $template_plural ); | |
| 413 | - /* translators: %s: Template label (singular). */ | |
| 414 | - $labels->parent_item_colon = sprintf( esc_html__( 'Parent %s:', 'elementor' ), $template_singular ); | |
| 415 | - $labels->menu_name = $template_plural; | |
| 416 | - $post_type_object->labels = $labels; | |
| 417 | - } | |
| 418 | 457 | } |
| 419 | 458 | |
| 420 | 459 | /** |
| 421 | 460 | * Get local templates. |
| @@ -742,12 +781,8 @@ | ||
| 742 | 781 | |
| 743 | 782 | $data['page_settings'] = $page->get_data( 'settings' ); |
| 744 | 783 | } |
| 745 | 784 | |
| 746 | - if ( ! empty( $content ) ) { | |
| 747 | - $this->attach_global_styles_to_data( $data, $content, $template_id ); | |
| 748 | - } | |
| 749 | - | |
| 750 | 785 | return $data; |
| 751 | 786 | } |
| 752 | 787 | |
| 753 | 788 | /** |
| @@ -922,9 +957,9 @@ | ||
| 922 | 957 | * @param string $name - The file name. |
| 923 | 958 | * @param string $path - The file path. |
| 924 | 959 | * @return \WP_Error|array An array of items on success, 'WP_Error' on failure. |
| 925 | 960 | */ |
| 926 | - public function import_template( $name, $path, $import_mode = 'match_site' ) { | |
| 961 | + public function import_template( $name, $path ) { | |
| 927 | 962 | if ( empty( $path ) ) { |
| 928 | 963 | return new \WP_Error( 'file_error', 'Please upload a file to import' ); |
| 929 | 964 | } |
| 930 | 965 | |
| @@ -949,9 +984,9 @@ | ||
| 949 | 984 | if ( false !== strpos( $file_path, '__MACOSX' ) || '.' === basename( $file_path )[0] ) { |
| 950 | 985 | continue; |
| 951 | 986 | } |
| 952 | 987 | |
| 953 | - $import_result = $this->import_single_template( $file_path, $import_mode ); | |
| 988 | + $import_result = $this->import_single_template( $file_path ); | |
| 954 | 989 | |
| 955 | 990 | if ( is_wp_error( $import_result ) ) { |
| 956 | 991 | // Skip failed files |
| 957 | 992 | continue; |
| @@ -963,9 +998,9 @@ | ||
| 963 | 998 | // Delete the temporary extraction directory, since it's now not necessary. |
| 964 | 999 | Plugin::$instance->uploads_manager->remove_file_or_dir( $extracted_files['extraction_directory'] ); |
| 965 | 1000 | } else { |
| 966 | 1001 | // If the import file is a single JSON file |
| 967 | - $import_result = $this->import_single_template( $path, $import_mode ); | |
| 1002 | + $import_result = $this->import_single_template( $path ); | |
| 968 | 1003 | |
| 969 | 1004 | if ( is_wp_error( $import_result ) ) { |
| 970 | 1005 | return $import_result; |
| 971 | 1006 | } |
| @@ -993,17 +1028,9 @@ | ||
| 993 | 1028 | */ |
| 994 | 1029 | public function post_row_actions( $actions, \WP_Post $post ) { |
| 995 | 1030 | if ( self::is_base_templates_screen() ) { |
| 996 | 1031 | if ( $this->is_template_supports_export( $post->ID ) ) { |
| 997 | - $template_labels = $this->get_template_labels_by_type( self::get_template_type( $post->ID ) ); | |
| 998 | - $export_label = esc_html__( 'Export Template', 'elementor' ); | |
| 999 | - | |
| 1000 | - if ( $template_labels['singular'] ) { | |
| 1001 | - /* translators: %s: Template label (singular). */ | |
| 1002 | - $export_label = sprintf( esc_html__( 'Export %s', 'elementor' ), $template_labels['singular'] ); | |
| 1003 | - } | |
| 1004 | - | |
| 1005 | - $actions['export-template'] = sprintf( '<a href="%1$s">%2$s</a>', $this->get_export_link( $post->ID ), $export_label ); | |
| 1032 | + $actions['export-template'] = sprintf( '<a href="%1$s">%2$s</a>', $this->get_export_link( $post->ID ), esc_html__( 'Export Template', 'elementor' ) ); | |
| 1006 | 1033 | } |
| 1007 | 1034 | } |
| 1008 | 1035 | |
| 1009 | 1036 | return $actions; |
| @@ -1027,30 +1054,13 @@ | ||
| 1027 | 1054 | } |
| 1028 | 1055 | |
| 1029 | 1056 | /** @var \Elementor\Core\Common\Modules\Ajax\Module $ajax */ |
| 1030 | 1057 | $ajax = Plugin::$instance->common->get_component( 'ajax' ); |
| 1031 | - $template_labels = $this->get_current_template_labels(); | |
| 1032 | - $import_label = esc_html__( 'Import Templates', 'elementor' ); | |
| 1033 | - $description = esc_html__( 'Choose an Elementor template JSON file or a .zip archive of Elementor templates, and add them to the list of templates available in your library.', 'elementor' ); | |
| 1034 | - | |
| 1035 | - if ( $template_labels['plural'] ) { | |
| 1036 | - /* translators: %s: Template label (plural). */ | |
| 1037 | - $import_label = sprintf( esc_html__( 'Import %s', 'elementor' ), $template_labels['plural'] ); | |
| 1038 | - } | |
| 1039 | - | |
| 1040 | - if ( $template_labels['singular'] && $template_labels['plural'] ) { | |
| 1041 | - $description = sprintf( | |
| 1042 | - /* translators: 1: Template label (singular). 2: Template label (plural). */ | |
| 1043 | - esc_html__( 'Choose an Elementor %1$s JSON file or a .zip archive of Elementor %2$s, and add them to the list of %2$s available in your library.', 'elementor' ), | |
| 1044 | - $template_labels['singular'], | |
| 1045 | - $template_labels['plural'] | |
| 1046 | - ); | |
| 1047 | - } | |
| 1048 | 1058 | ?> |
| 1049 | 1059 | <div id="elementor-hidden-area"> |
| 1050 | - <a id="elementor-import-template-trigger" class="page-title-action button button-secondary"><?php echo esc_html( $import_label ); ?></a> | |
| 1060 | + <a id="elementor-import-template-trigger" class="page-title-action button button-secondary"><?php echo esc_html__( 'Import Templates', 'elementor' ); ?></a> | |
| 1051 | 1061 | <div id="elementor-import-template-area"> |
| 1052 | - <div id="elementor-import-template-title"><?php echo esc_html( $description ); ?></div> | |
| 1062 | + <div id="elementor-import-template-title"><?php echo esc_html__( 'Choose an Elementor template JSON file or a .zip archive of Elementor templates, and add them to the list of templates available in your library.', 'elementor' ); ?></div> | |
| 1053 | 1063 | <form id="elementor-import-template-form" method="post" action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>" enctype="multipart/form-data"> |
| 1054 | 1064 | <input type="hidden" name="action" value="elementor_library_direct_actions"> |
| 1055 | 1065 | <input type="hidden" name="library_action" value="direct_import_template"> |
| 1056 | 1066 | <input type="hidden" name="_nonce" value="<?php Utils::print_unescaped_internal_string( $ajax->create_nonce() ); ?>"> |
| @@ -1081,23 +1091,8 @@ | ||
| 1081 | 1091 | die; |
| 1082 | 1092 | } |
| 1083 | 1093 | } |
| 1084 | 1094 | |
| 1085 | - public function redirect_categories_page_to_saved_templates_page() { | |
| 1086 | - // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 1087 | - $taxonomy = sanitize_key( wp_unslash( $_GET['taxonomy'] ?? '' ) ); | |
| 1088 | - // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 1089 | - $post_type = sanitize_key( wp_unslash( $_GET['post_type'] ?? '' ) ); | |
| 1090 | - $is_categories_page = 'edit-tags.php' === $GLOBALS['pagenow'] | |
| 1091 | - && self::TAXONOMY_CATEGORY_SLUG === $taxonomy | |
| 1092 | - && self::CPT === $post_type; | |
| 1093 | - | |
| 1094 | - if ( $is_categories_page ) { | |
| 1095 | - wp_safe_redirect( admin_url( 'edit.php?post_type=' . self::CPT . '&tabs_group=library' ) ); | |
| 1096 | - die; | |
| 1097 | - } | |
| 1098 | - } | |
| 1099 | - | |
| 1100 | 1095 | /** |
| 1101 | 1096 | * Is template library supports export. |
| 1102 | 1097 | * |
| 1103 | 1098 | * Whether the template library supports export. |
| @@ -1416,24 +1411,14 @@ | ||
| 1416 | 1411 | } |
| 1417 | 1412 | |
| 1418 | 1413 | private function render_blank_state( $current_type, array $args = [] ) { |
| 1419 | 1414 | $current_type_label = $this->get_template_label_by_type( $current_type ); |
| 1420 | - $type_labels = $this->get_template_labels_by_type( $current_type ); | |
| 1421 | - $description = esc_html__( 'Add templates and reuse them across your website. Easily export and import them to any other project, for an optimized workflow.', 'elementor' ); | |
| 1422 | - | |
| 1423 | - if ( $type_labels['plural'] ) { | |
| 1424 | - $description = sprintf( | |
| 1425 | - /* translators: %s: Template label (plural). */ | |
| 1426 | - esc_html__( 'Add %s and reuse them across your website. Easily export and import them to any other project, for an optimized workflow.', 'elementor' ), | |
| 1427 | - $type_labels['plural'] | |
| 1428 | - ); | |
| 1429 | - } | |
| 1430 | 1415 | $inline_style = '#posts-filter .wp-list-table, #posts-filter .tablenav.top, .tablenav.bottom .actions, .wrap .subsubsub { display:none;}'; |
| 1431 | 1416 | |
| 1432 | 1417 | $args = wp_parse_args( $args, [ |
| 1433 | 1418 | 'additional_inline_style' => '', |
| 1434 | 1419 | 'href' => '', |
| 1435 | - 'description' => $description, | |
| 1420 | + 'description' => esc_html__( 'Add templates and reuse them across your website. Easily export and import them to any other project, for an optimized workflow.', 'elementor' ), | |
| 1436 | 1421 | ] ); |
| 1437 | 1422 | $inline_style .= $args['additional_inline_style']; |
| 1438 | 1423 | ?> |
| 1439 | 1424 | <style type="text/css"><?php Utils::print_unescaped_internal_string( $inline_style ); ?></style> |
| @@ -1528,10 +1513,10 @@ | ||
| 1528 | 1513 | * |
| 1529 | 1514 | * @return \WP_Error|int|array Local template array, or template ID, or |
| 1530 | 1515 | * `WP_Error`. |
| 1531 | 1516 | */ |
| 1532 | - private function import_single_template( $file_path, $import_mode = 'match_site' ) { | |
| 1533 | - $data = $this->prepare_import_template_data( $file_path, $import_mode ); | |
| 1517 | + private function import_single_template( $file_path ) { | |
| 1518 | + $data = $this->prepare_import_template_data( $file_path ); | |
| 1534 | 1519 | |
| 1535 | 1520 | if ( is_wp_error( $data ) ) { |
| 1536 | 1521 | return $data; |
| 1537 | 1522 | } |
| @@ -1587,10 +1572,8 @@ | ||
| 1587 | 1572 | 'title' => $document->get_main_post()->post_title, |
| 1588 | 1573 | 'type' => self::get_template_type( $template_id ), |
| 1589 | 1574 | ]; |
| 1590 | 1575 | |
| 1591 | - $this->attach_global_styles_to_data( $export_data, $content, $template_id ); | |
| 1592 | - | |
| 1593 | 1576 | return [ |
| 1594 | 1577 | 'name' => 'elementor-' . $template_id . '-' . gmdate( 'Y-m-d' ) . '.json', |
| 1595 | 1578 | 'content' => wp_json_encode( $export_data ), |
| 1596 | 1579 | ]; |
| @@ -1631,68 +1614,8 @@ | ||
| 1631 | 1614 | |
| 1632 | 1615 | return $template_label; |
| 1633 | 1616 | } |
| 1634 | 1617 | |
| 1635 | - private function get_template_labels_by_type( $template_type ) { | |
| 1636 | - $labels = [ | |
| 1637 | - 'singular' => '', | |
| 1638 | - 'plural' => '', | |
| 1639 | - ]; | |
| 1640 | - | |
| 1641 | - if ( ! $template_type ) { | |
| 1642 | - return $labels; | |
| 1643 | - } | |
| 1644 | - | |
| 1645 | - $document_types = Plugin::instance()->documents->get_document_types(); | |
| 1646 | - | |
| 1647 | - if ( isset( $document_types[ $template_type ] ) ) { | |
| 1648 | - $doc_type = $document_types[ $template_type ]; | |
| 1649 | - $labels['singular'] = call_user_func( [ $doc_type, 'get_title' ] ); | |
| 1650 | - $labels['plural'] = call_user_func( [ $doc_type, 'get_plural_title' ] ); | |
| 1651 | - } else { | |
| 1652 | - $labels['singular'] = $this->get_template_label_by_type( $template_type ); | |
| 1653 | - } | |
| 1654 | - | |
| 1655 | - if ( ! $labels['plural'] ) { | |
| 1656 | - $labels['plural'] = $labels['singular']; | |
| 1657 | - } | |
| 1658 | - | |
| 1659 | - return $labels; | |
| 1660 | - } | |
| 1661 | - | |
| 1662 | - private function get_current_template_labels() { | |
| 1663 | - $labels = [ | |
| 1664 | - 'singular' => '', | |
| 1665 | - 'plural' => '', | |
| 1666 | - ]; | |
| 1667 | - | |
| 1668 | - $template_type = Utils::get_super_global_value( $_GET, self::TAXONOMY_TYPE_SLUG ); | |
| 1669 | - | |
| 1670 | - if ( $template_type ) { | |
| 1671 | - return $this->get_template_labels_by_type( $template_type ); | |
| 1672 | - } | |
| 1673 | - | |
| 1674 | - $current_tabs_group = $this->get_current_tab_group(); | |
| 1675 | - | |
| 1676 | - if ( $current_tabs_group ) { | |
| 1677 | - $doc_types = Plugin::$instance->documents->get_document_types( [ | |
| 1678 | - 'admin_tab_group' => $current_tabs_group, | |
| 1679 | - ], 'and' ); | |
| 1680 | - | |
| 1681 | - if ( 1 === count( $doc_types ) ) { | |
| 1682 | - $doc_type = reset( $doc_types ); | |
| 1683 | - $labels['singular'] = call_user_func( [ $doc_type, 'get_title' ] ); | |
| 1684 | - $labels['plural'] = call_user_func( [ $doc_type, 'get_plural_title' ] ); | |
| 1685 | - } | |
| 1686 | - } | |
| 1687 | - | |
| 1688 | - if ( ! $labels['plural'] ) { | |
| 1689 | - $labels['plural'] = $labels['singular']; | |
| 1690 | - } | |
| 1691 | - | |
| 1692 | - return $labels; | |
| 1693 | - } | |
| 1694 | - | |
| 1695 | 1618 | /** |
| 1696 | 1619 | * Filter template types in admin query. |
| 1697 | 1620 | * |
| 1698 | 1621 | * Update the template types in the main admin query. |
| @@ -1736,9 +1659,11 @@ | ||
| 1736 | 1659 | * @access private |
| 1737 | 1660 | */ |
| 1738 | 1661 | private function add_actions() { |
| 1739 | 1662 | if ( is_admin() ) { |
| 1740 | - add_action( 'admin_init', [ $this, 'redirect_categories_page_to_saved_templates_page' ] ); | |
| 1663 | + add_action( 'elementor/admin/menu/register', function ( Admin_Menu_Manager $admin_menu ) { | |
| 1664 | + $this->register_admin_menu( $admin_menu ); | |
| 1665 | + }, static::ADMIN_MENU_PRIORITY ); | |
| 1741 | 1666 | |
| 1742 | 1667 | add_action( 'elementor/editor-one/menu/register', function ( Menu_Data_Provider $menu_data_provider ) { |
| 1743 | 1668 | $this->register_editor_one_menu( $menu_data_provider ); |
| 1744 | 1669 | } ); |
| @@ -1754,12 +1679,14 @@ | ||
| 1754 | 1679 | |
| 1755 | 1680 | return $elementor_post_types; |
| 1756 | 1681 | } ); |
| 1757 | 1682 | |
| 1758 | - add_filter( 'elementor/editor-one/admin-edit-post-types', function ( array $post_types ): array { | |
| 1759 | - $post_types[] = self::CPT; | |
| 1683 | + add_action( 'elementor/admin/menu/register', function ( Admin_Menu_Manager $admin_menu ) { | |
| 1684 | + $this->admin_menu_reorder( $admin_menu ); | |
| 1685 | + }, 800 ); | |
| 1760 | 1686 | |
| 1761 | - return $post_types; | |
| 1687 | + add_action( 'elementor/admin/menu/after_register', function () { | |
| 1688 | + $this->admin_menu_set_current(); | |
| 1762 | 1689 | } ); |
| 1763 | 1690 | |
| 1764 | 1691 | add_filter( 'admin_title', [ $this, 'admin_title' ], 10, 2 ); |
| 1765 | 1692 | add_action( 'all_admin_notices', [ $this, 'replace_admin_heading' ] ); |
| @@ -1842,10 +1769,12 @@ | ||
| 1842 | 1769 | return $posts_columns; |
| 1843 | 1770 | } |
| 1844 | 1771 | |
| 1845 | 1772 | public function get_current_tab_group() { |
| 1846 | - $current_tabs_group = Utils::get_super_global_value( $_GET, 'tabs_group' ) ?? ''; | |
| 1847 | - $type_slug = Utils::get_super_global_value( $_GET, self::TAXONOMY_TYPE_SLUG ); | |
| 1773 | + //phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce verification is not required here. | |
| 1774 | + $current_tabs_group = Utils::get_super_global_value( $_REQUEST, 'tabs_group' ) ?? ''; | |
| 1775 | + //phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce verification is not required here. | |
| 1776 | + $type_slug = Utils::get_super_global_value( $_REQUEST, self::TAXONOMY_TYPE_SLUG ); | |
| 1848 | 1777 | |
| 1849 | 1778 | if ( $type_slug ) { |
| 1850 | 1779 | $doc_type = Plugin::$instance->documents->get_document_type( $type_slug, '' ); |
| 1851 | 1780 | if ( $doc_type ) { |
| @@ -1996,18 +1925,33 @@ | ||
| 1996 | 1925 | if ( null === $this->wordpress_adapter ) { |
| 1997 | 1926 | $this->set_wordpress_adapter( new WordPress_Adapter() ); |
| 1998 | 1927 | } |
| 1999 | 1928 | |
| 1929 | + if ( ! $this->should_check_permissions( $args ) ) { | |
| 1930 | + return true; | |
| 1931 | + } | |
| 1932 | + | |
| 2000 | 1933 | $post_id = intval( $args['template_id'] ); |
| 2001 | 1934 | $post_status = $this->wordpress_adapter->get_post_status( $post_id ); |
| 1935 | + $is_private_or_non_published = ( 'private' === $post_status && ! $this->wordpress_adapter->current_user_can( 'read_private_posts', $post_id ) ) || ( 'publish' !== $post_status ); | |
| 2002 | 1936 | |
| 2003 | - if ( 'publish' === $post_status && ! post_password_required( $post_id ) ) { | |
| 2004 | - return true; | |
| 1937 | + $can_read_template = $is_private_or_non_published || $this->wordpress_adapter->current_user_can( 'edit_post', $post_id ); | |
| 1938 | + | |
| 1939 | + return apply_filters( 'elementor/template-library/is_allowed_to_read_template', $can_read_template, $args ); | |
| 1940 | + } | |
| 1941 | + | |
| 1942 | + private function should_check_permissions( array $args ): bool { | |
| 1943 | + if ( null === $this->elementor_adapter ) { | |
| 1944 | + $this->set_elementor_adapter( new Elementor_Adapter() ); | |
| 2005 | 1945 | } |
| 2006 | 1946 | |
| 2007 | - $can_read_template = $this->wordpress_adapter->current_user_can( 'edit_post', $post_id ); | |
| 1947 | + $check_permissions = isset( $args['check_permissions'] ) && false === $args['check_permissions']; | |
| 2008 | 1948 | |
| 2009 | - return apply_filters( 'elementor/template-library/is_allowed_to_read_template', $can_read_template, $args ); | |
| 1949 | + if ( $check_permissions ) { | |
| 1950 | + return false; | |
| 1951 | + } | |
| 1952 | + | |
| 1953 | + return true; | |
| 2010 | 1954 | } |
| 2011 | 1955 | |
| 2012 | 1956 | public function set_wordpress_adapter( Wordpress_Adapter_Interface $wordpress_adapter ) { |
| 2013 | 1957 | $this->wordpress_adapter = $wordpress_adapter; |