PluginProbe
Elementor Website Builder – more than just a page builder / 3.34.0-beta1
Elementor Website Builder – more than just a page builder v3.34.0-beta1
4.3.4 4.3.3 4.3.2 4.3.1 4.3.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 All 457 releases
← All changes | includes/template-library/sources/local.php +113 -202 4.3.1 → 3.34.0-beta1 View file →
@@ -1,12 +1,14 @@
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;
8 9 use Elementor\Core\Settings\Manager as SettingsManager;
10 +use Elementor\Core\Settings\Page\Model;
9 11 use Elementor\Includes\TemplateLibrary\Sources\AdminMenuItems\Add_New_Template_Menu_Item;
10 12 use Elementor\Includes\TemplateLibrary\Sources\AdminMenuItems\Saved_Templates_Menu_Item;
11 13 use Elementor\Includes\TemplateLibrary\Sources\AdminMenuItems\Templates_Categories_Menu_Item;
12 14 use Elementor\Modules\Library\Documents\Library_Document;
@@ -14,12 +16,10 @@
14 16 use Elementor\Utils;
15 17 use Elementor\User;
16 18 use Elementor\Core\Isolation\Wordpress_Adapter;
17 19 use Elementor\Core\Isolation\Wordpress_Adapter_Interface;
20 +use Elementor\Core\Isolation\Elementor_Adapter;
18 21 use Elementor\Core\Isolation\Elementor_Adapter_Interface;
19 -use Elementor\Modules\EditorOne\Classes\Menu_Data_Provider;
20 -use Elementor\Includes\TemplateLibrary\Sources\AdminMenuItems\Editor_One_Saved_Templates_Menu;
21 -use Elementor\Includes\TemplateLibrary\Sources\AdminMenuItems\Editor_One_Templates_Menu;
22 22
23 23 if ( ! defined( 'ABSPATH' ) ) {
24 24 exit; // Exit if accessed directly.
25 25 }
@@ -351,14 +351,79 @@
351 351
352 352 register_taxonomy( self::TAXONOMY_CATEGORY_SLUG, self::CPT, $args );
353 353 }
354 354
355 + /**
356 + * Remove Add New item from admin menu.
357 + *
358 + * Fired by `admin_menu` action.
359 + *
360 + * @since 2.4.0
361 + * @access public
362 + */
363 + private function admin_menu_reorder( Admin_Menu_Manager $admin_menu ) {
364 + global $submenu;
355 365
356 - private function register_editor_one_menu( Menu_Data_Provider $menu_data_provider ) {
357 - $menu_data_provider->register_menu( new Editor_One_Templates_Menu() );
358 - $menu_data_provider->register_menu( new Editor_One_Saved_Templates_Menu() );
366 + if ( ! isset( $submenu[ static::ADMIN_MENU_SLUG ] ) ) {
367 + return;
368 + }
369 +
370 + remove_submenu_page( static::ADMIN_MENU_SLUG, static::ADMIN_MENU_SLUG );
371 +
372 + $add_new_slug = 'post-new.php?post_type=' . static::CPT;
373 + $category_slug = 'edit-tags.php?taxonomy=' . static::TAXONOMY_CATEGORY_SLUG . '&amp;post_type=' . static::CPT;
374 +
375 + $library_submenu = new Collection( $submenu[ static::ADMIN_MENU_SLUG ] );
376 +
377 + $add_new_item = $library_submenu->find( function ( $item ) use ( $add_new_slug ) {
378 + return $add_new_slug === $item[2];
379 + } );
380 +
381 + $categories_item = $library_submenu->find( function ( $item ) use ( $category_slug ) {
382 + return $category_slug === $item[2];
383 + } );
384 +
385 + if ( $add_new_item ) {
386 + remove_submenu_page( static::ADMIN_MENU_SLUG, $add_new_slug );
387 +
388 + $admin_menu->register( admin_url( static::ADMIN_MENU_SLUG . '#add_new' ), new Add_New_Template_Menu_Item() );
389 + }
390 +
391 + if ( $categories_item ) {
392 + remove_submenu_page( static::ADMIN_MENU_SLUG, $category_slug );
393 +
394 + $admin_menu->register( $category_slug, new Templates_Categories_Menu_Item() );
395 + }
359 396 }
360 397
398 + /**
399 + * Add a `current` CSS class to the `Saved Templates` submenu page when it's active.
400 + * It should work by default, but since we interfere with WordPress' builtin CPT menus it doesn't work properly.
401 + *
402 + * @return void
403 + */
404 + private function admin_menu_set_current() {
405 + global $submenu;
406 +
407 + if ( $this->is_current_screen() ) {
408 + $library_submenu = &$submenu[ static::ADMIN_MENU_SLUG ];
409 + $library_title = $this->get_library_title();
410 +
411 + foreach ( $library_submenu as &$item ) {
412 + if ( $library_title === $item[0] ) {
413 + if ( ! isset( $item[4] ) ) {
414 + $item[4] = '';
415 + }
416 + $item[4] .= ' current';
417 + }
418 + }
419 + }
420 + }
421 +
422 + private function register_admin_menu( Admin_Menu_Manager $admin_menu ) {
423 + $admin_menu->register( static::get_admin_url( true ), new Saved_Templates_Menu_Item() );
424 + }
425 +
361 426 public function admin_title( $admin_title, $title ) {
362 427 $library_title = $this->get_library_title();
363 428
364 429 if ( $library_title ) {
@@ -368,54 +433,15 @@
368 433 return $admin_title;
369 434 }
370 435
371 436 public function replace_admin_heading() {
372 - if ( ! $this->is_current_screen() ) {
373 - return;
374 - }
375 -
376 - global $post_type_object;
377 -
378 437 $library_title = $this->get_library_title();
379 438
380 439 if ( $library_title ) {
440 + global $post_type_object;
441 +
381 442 $post_type_object->labels->name = $library_title;
382 443 }
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 444 }
419 445
420 446 /**
421 447 * Get local templates.
@@ -742,12 +768,8 @@
742 768
743 769 $data['page_settings'] = $page->get_data( 'settings' );
744 770 }
745 771
746 - if ( ! empty( $content ) ) {
747 - $this->attach_global_styles_to_data( $data, $content, $template_id );
748 - }
749 -
750 772 return $data;
751 773 }
752 774
753 775 /**
@@ -922,9 +944,9 @@
922 944 * @param string $name - The file name.
923 945 * @param string $path - The file path.
924 946 * @return \WP_Error|array An array of items on success, 'WP_Error' on failure.
925 947 */
926 - public function import_template( $name, $path, $import_mode = 'match_site' ) {
948 + public function import_template( $name, $path ) {
927 949 if ( empty( $path ) ) {
928 950 return new \WP_Error( 'file_error', 'Please upload a file to import' );
929 951 }
930 952
@@ -949,9 +971,9 @@
949 971 if ( false !== strpos( $file_path, '__MACOSX' ) || '.' === basename( $file_path )[0] ) {
950 972 continue;
951 973 }
952 974
953 - $import_result = $this->import_single_template( $file_path, $import_mode );
975 + $import_result = $this->import_single_template( $file_path );
954 976
955 977 if ( is_wp_error( $import_result ) ) {
956 978 // Skip failed files
957 979 continue;
@@ -963,9 +985,9 @@
963 985 // Delete the temporary extraction directory, since it's now not necessary.
964 986 Plugin::$instance->uploads_manager->remove_file_or_dir( $extracted_files['extraction_directory'] );
965 987 } else {
966 988 // If the import file is a single JSON file
967 - $import_result = $this->import_single_template( $path, $import_mode );
989 + $import_result = $this->import_single_template( $path );
968 990
969 991 if ( is_wp_error( $import_result ) ) {
970 992 return $import_result;
971 993 }
@@ -993,17 +1015,9 @@
993 1015 */
994 1016 public function post_row_actions( $actions, \WP_Post $post ) {
995 1017 if ( self::is_base_templates_screen() ) {
996 1018 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 );
1019 + $actions['export-template'] = sprintf( '<a href="%1$s">%2$s</a>', $this->get_export_link( $post->ID ), esc_html__( 'Export Template', 'elementor' ) );
1006 1020 }
1007 1021 }
1008 1022
1009 1023 return $actions;
@@ -1027,30 +1041,13 @@
1027 1041 }
1028 1042
1029 1043 /** @var \Elementor\Core\Common\Modules\Ajax\Module $ajax */
1030 1044 $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 1045 ?>
1049 1046 <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>
1047 + <a id="elementor-import-template-trigger" class="page-title-action"><?php echo esc_html__( 'Import Templates', 'elementor' ); ?></a>
1051 1048 <div id="elementor-import-template-area">
1052 - <div id="elementor-import-template-title"><?php echo esc_html( $description ); ?></div>
1049 + <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 1050 <form id="elementor-import-template-form" method="post" action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>" enctype="multipart/form-data">
1054 1051 <input type="hidden" name="action" value="elementor_library_direct_actions">
1055 1052 <input type="hidden" name="library_action" value="direct_import_template">
1056 1053 <input type="hidden" name="_nonce" value="<?php Utils::print_unescaped_internal_string( $ajax->create_nonce() ); ?>">
@@ -1081,23 +1078,8 @@
1081 1078 die;
1082 1079 }
1083 1080 }
1084 1081
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 1082 /**
1101 1083 * Is template library supports export.
1102 1084 *
1103 1085 * Whether the template library supports export.
@@ -1266,10 +1248,8 @@
1266 1248 *
1267 1249 * @param string $redirect_to The redirect URL.
1268 1250 * @param string $action The action being taken.
1269 1251 * @param array $post_ids The items to take the action on.
1270 - *
1271 - * @return string The redirect URL, unchanged when the action is not handled here.
1272 1252 */
1273 1253 public function admin_export_multiple_templates( $redirect_to, $action, $post_ids ) {
1274 1254 if ( self::BULK_EXPORT_ACTION === $action ) {
1275 1255 $result = $this->export_multiple_templates( $post_ids );
@@ -1277,10 +1257,8 @@
1277 1257 // If you reach this line, the export failed
1278 1258 // PHPCS - Not user input.
1279 1259 wp_die( $result->get_error_message() ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1280 1260 }
1281 -
1282 - return $redirect_to;
1283 1261 }
1284 1262
1285 1263 /**
1286 1264 * Print admin tabs.
@@ -1420,24 +1398,14 @@
1420 1398 }
1421 1399
1422 1400 private function render_blank_state( $current_type, array $args = [] ) {
1423 1401 $current_type_label = $this->get_template_label_by_type( $current_type );
1424 - $type_labels = $this->get_template_labels_by_type( $current_type );
1425 - $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' );
1426 -
1427 - if ( $type_labels['plural'] ) {
1428 - $description = sprintf(
1429 - /* translators: %s: Template label (plural). */
1430 - esc_html__( 'Add %s and reuse them across your website. Easily export and import them to any other project, for an optimized workflow.', 'elementor' ),
1431 - $type_labels['plural']
1432 - );
1433 - }
1434 1402 $inline_style = '#posts-filter .wp-list-table, #posts-filter .tablenav.top, .tablenav.bottom .actions, .wrap .subsubsub { display:none;}';
1435 1403
1436 1404 $args = wp_parse_args( $args, [
1437 1405 'additional_inline_style' => '',
1438 1406 'href' => '',
1439 - 'description' => $description,
1407 + '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' ),
1440 1408 ] );
1441 1409 $inline_style .= $args['additional_inline_style'];
1442 1410 ?>
1443 1411 <style type="text/css"><?php Utils::print_unescaped_internal_string( $inline_style ); ?></style>
@@ -1532,10 +1500,10 @@
1532 1500 *
1533 1501 * @return \WP_Error|int|array Local template array, or template ID, or
1534 1502 * `WP_Error`.
1535 1503 */
1536 - private function import_single_template( $file_path, $import_mode = 'match_site' ) {
1537 - $data = $this->prepare_import_template_data( $file_path, $import_mode );
1504 + private function import_single_template( $file_path ) {
1505 + $data = $this->prepare_import_template_data( $file_path );
1538 1506
1539 1507 if ( is_wp_error( $data ) ) {
1540 1508 return $data;
1541 1509 }
@@ -1591,10 +1559,8 @@
1591 1559 'title' => $document->get_main_post()->post_title,
1592 1560 'type' => self::get_template_type( $template_id ),
1593 1561 ];
1594 1562
1595 - $this->attach_global_styles_to_data( $export_data, $content, $template_id );
1596 -
1597 1563 return [
1598 1564 'name' => 'elementor-' . $template_id . '-' . gmdate( 'Y-m-d' ) . '.json',
1599 1565 'content' => wp_json_encode( $export_data ),
1600 1566 ];
@@ -1635,68 +1601,8 @@
1635 1601
1636 1602 return $template_label;
1637 1603 }
1638 1604
1639 - private function get_template_labels_by_type( $template_type ) {
1640 - $labels = [
1641 - 'singular' => '',
1642 - 'plural' => '',
1643 - ];
1644 -
1645 - if ( ! $template_type ) {
1646 - return $labels;
1647 - }
1648 -
1649 - $document_types = Plugin::instance()->documents->get_document_types();
1650 -
1651 - if ( isset( $document_types[ $template_type ] ) ) {
1652 - $doc_type = $document_types[ $template_type ];
1653 - $labels['singular'] = call_user_func( [ $doc_type, 'get_title' ] );
1654 - $labels['plural'] = call_user_func( [ $doc_type, 'get_plural_title' ] );
1655 - } else {
1656 - $labels['singular'] = $this->get_template_label_by_type( $template_type );
1657 - }
1658 -
1659 - if ( ! $labels['plural'] ) {
1660 - $labels['plural'] = $labels['singular'];
1661 - }
1662 -
1663 - return $labels;
1664 - }
1665 -
1666 - private function get_current_template_labels() {
1667 - $labels = [
1668 - 'singular' => '',
1669 - 'plural' => '',
1670 - ];
1671 -
1672 - $template_type = Utils::get_super_global_value( $_GET, self::TAXONOMY_TYPE_SLUG );
1673 -
1674 - if ( $template_type ) {
1675 - return $this->get_template_labels_by_type( $template_type );
1676 - }
1677 -
1678 - $current_tabs_group = $this->get_current_tab_group();
1679 -
1680 - if ( $current_tabs_group ) {
1681 - $doc_types = Plugin::$instance->documents->get_document_types( [
1682 - 'admin_tab_group' => $current_tabs_group,
1683 - ], 'and' );
1684 -
1685 - if ( 1 === count( $doc_types ) ) {
1686 - $doc_type = reset( $doc_types );
1687 - $labels['singular'] = call_user_func( [ $doc_type, 'get_title' ] );
1688 - $labels['plural'] = call_user_func( [ $doc_type, 'get_plural_title' ] );
1689 - }
1690 - }
1691 -
1692 - if ( ! $labels['plural'] ) {
1693 - $labels['plural'] = $labels['singular'];
1694 - }
1695 -
1696 - return $labels;
1697 - }
1698 -
1699 1605 /**
1700 1606 * Filter template types in admin query.
1701 1607 *
1702 1608 * Update the template types in the main admin query.
@@ -1740,32 +1646,20 @@
1740 1646 * @access private
1741 1647 */
1742 1648 private function add_actions() {
1743 1649 if ( is_admin() ) {
1744 - add_action( 'admin_init', [ $this, 'redirect_categories_page_to_saved_templates_page' ] );
1650 + add_action( 'elementor/admin/menu/register', function ( Admin_Menu_Manager $admin_menu ) {
1651 + $this->register_admin_menu( $admin_menu );
1652 + }, static::ADMIN_MENU_PRIORITY );
1745 1653
1746 - add_action( 'elementor/editor-one/menu/register', function ( Menu_Data_Provider $menu_data_provider ) {
1747 - $this->register_editor_one_menu( $menu_data_provider );
1748 - } );
1654 + add_action( 'elementor/admin/menu/register', function ( Admin_Menu_Manager $admin_menu ) {
1655 + $this->admin_menu_reorder( $admin_menu );
1656 + }, 800 );
1749 1657
1750 - add_action( 'elementor/editor-one/menu/excluded_level4_slugs', function ( array $excluded_slugs ): array {
1751 - $excluded_slugs[] = 'edit.php?post_type=elementor_library#add_new';
1752 - $excluded_slugs[] = 'edit-tags.php?taxonomy=elementor_library_category&amp;post_type=elementor_library';
1753 - return $excluded_slugs;
1658 + add_action( 'elementor/admin/menu/after_register', function () {
1659 + $this->admin_menu_set_current();
1754 1660 } );
1755 1661
1756 - add_filter( 'elementor/editor-one/menu/elementor_post_types', function ( array $elementor_post_types ): array {
1757 - $elementor_post_types[ self::CPT ] = [];
1758 -
1759 - return $elementor_post_types;
1760 - } );
1761 -
1762 - add_filter( 'elementor/editor-one/admin-edit-post-types', function ( array $post_types ): array {
1763 - $post_types[] = self::CPT;
1764 -
1765 - return $post_types;
1766 - } );
1767 -
1768 1662 add_filter( 'admin_title', [ $this, 'admin_title' ], 10, 2 );
1769 1663 add_action( 'all_admin_notices', [ $this, 'replace_admin_heading' ] );
1770 1664 add_filter( 'post_row_actions', [ $this, 'post_row_actions' ], 10, 2 );
1771 1665 add_action( 'admin_footer', [ $this, 'admin_import_template_form' ] );
@@ -1846,10 +1740,12 @@
1846 1740 return $posts_columns;
1847 1741 }
1848 1742
1849 1743 public function get_current_tab_group() {
1850 - $current_tabs_group = Utils::get_super_global_value( $_GET, 'tabs_group' ) ?? '';
1851 - $type_slug = Utils::get_super_global_value( $_GET, self::TAXONOMY_TYPE_SLUG );
1744 + //phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce verification is not required here.
1745 + $current_tabs_group = Utils::get_super_global_value( $_REQUEST, 'tabs_group' ) ?? '';
1746 + //phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce verification is not required here.
1747 + $type_slug = Utils::get_super_global_value( $_REQUEST, self::TAXONOMY_TYPE_SLUG );
1852 1748
1853 1749 if ( $type_slug ) {
1854 1750 $doc_type = Plugin::$instance->documents->get_document_type( $type_slug, '' );
1855 1751 if ( $doc_type ) {
@@ -2000,18 +1896,33 @@
2000 1896 if ( null === $this->wordpress_adapter ) {
2001 1897 $this->set_wordpress_adapter( new WordPress_Adapter() );
2002 1898 }
2003 1899
1900 + if ( ! $this->should_check_permissions( $args ) ) {
1901 + return true;
1902 + }
1903 +
2004 1904 $post_id = intval( $args['template_id'] );
2005 1905 $post_status = $this->wordpress_adapter->get_post_status( $post_id );
1906 + $is_private_or_non_published = ( 'private' === $post_status && ! $this->wordpress_adapter->current_user_can( 'read_private_posts', $post_id ) ) || ( 'publish' !== $post_status );
2006 1907
2007 - if ( 'publish' === $post_status && ! post_password_required( $post_id ) ) {
2008 - return true;
1908 + $can_read_template = $is_private_or_non_published || $this->wordpress_adapter->current_user_can( 'edit_post', $post_id );
1909 +
1910 + return apply_filters( 'elementor/template-library/is_allowed_to_read_template', $can_read_template, $args );
1911 + }
1912 +
1913 + private function should_check_permissions( array $args ): bool {
1914 + if ( null === $this->elementor_adapter ) {
1915 + $this->set_elementor_adapter( new Elementor_Adapter() );
2009 1916 }
2010 1917
2011 - $can_read_template = $this->wordpress_adapter->current_user_can( 'edit_post', $post_id );
1918 + $check_permissions = isset( $args['check_permissions'] ) && false === $args['check_permissions'];
2012 1919
2013 - return apply_filters( 'elementor/template-library/is_allowed_to_read_template', $can_read_template, $args );
1920 + if ( $check_permissions ) {
1921 + return false;
1922 + }
1923 +
1924 + return true;
2014 1925 }
2015 1926
2016 1927 public function set_wordpress_adapter( Wordpress_Adapter_Interface $wordpress_adapter ) {
2017 1928 $this->wordpress_adapter = $wordpress_adapter;