PluginProbe
Elementor Website Builder – more than just a page builder / 3.32.2
Elementor Website Builder – more than just a page builder v3.32.2
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 +99 -331 4.1.03.32.2 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;
@@ -12,15 +14,8 @@
12 14 use Elementor\Modules\Library\Documents\Library_Document;
13 15 use Elementor\Plugin;
14 16 use Elementor\Utils;
15 17 use Elementor\User;
16 -use Elementor\Core\Isolation\Wordpress_Adapter;
17 -use Elementor\Core\Isolation\Wordpress_Adapter_Interface;
18 -use Elementor\Core\Isolation\Elementor_Adapter;
19 -use Elementor\Core\Isolation\Elementor_Adapter_Interface;
20 -use Elementor\Modules\EditorOne\Classes\Menu_Data_Provider;
21 -use Elementor\Includes\TemplateLibrary\Sources\AdminMenuItems\Editor_One_Saved_Templates_Menu;
22 -use Elementor\Includes\TemplateLibrary\Sources\AdminMenuItems\Editor_One_Templates_Menu;
23 18
24 19 if ( ! defined( 'ABSPATH' ) ) {
25 20 exit; // Exit if accessed directly.
26 21 }
@@ -96,18 +91,8 @@
96 91 */
97 92 private $post_type_object;
98 93
99 94 /**
100 - * @var Wordpress_Adapter_Interface
101 - */
102 - protected $wordpress_adapter = null;
103 -
104 - /**
105 - * @var Elementor_Adapter_Interface
106 - */
107 - protected $elementor_adapter = null;
108 -
109 - /**
110 95 * @since 2.3.0
111 96 * @access public
112 97 * @static
113 98 * @return array
@@ -352,14 +337,79 @@
352 337
353 338 register_taxonomy( self::TAXONOMY_CATEGORY_SLUG, self::CPT, $args );
354 339 }
355 340
341 + /**
342 + * Remove Add New item from admin menu.
343 + *
344 + * Fired by `admin_menu` action.
345 + *
346 + * @since 2.4.0
347 + * @access public
348 + */
349 + private function admin_menu_reorder( Admin_Menu_Manager $admin_menu ) {
350 + global $submenu;
356 351
357 - private function register_editor_one_menu( Menu_Data_Provider $menu_data_provider ) {
358 - $menu_data_provider->register_menu( new Editor_One_Templates_Menu() );
359 - $menu_data_provider->register_menu( new Editor_One_Saved_Templates_Menu() );
352 + if ( ! isset( $submenu[ static::ADMIN_MENU_SLUG ] ) ) {
353 + return;
354 + }
355 +
356 + remove_submenu_page( static::ADMIN_MENU_SLUG, static::ADMIN_MENU_SLUG );
357 +
358 + $add_new_slug = 'post-new.php?post_type=' . static::CPT;
359 + $category_slug = 'edit-tags.php?taxonomy=' . static::TAXONOMY_CATEGORY_SLUG . '&amp;post_type=' . static::CPT;
360 +
361 + $library_submenu = new Collection( $submenu[ static::ADMIN_MENU_SLUG ] );
362 +
363 + $add_new_item = $library_submenu->find( function ( $item ) use ( $add_new_slug ) {
364 + return $add_new_slug === $item[2];
365 + } );
366 +
367 + $categories_item = $library_submenu->find( function ( $item ) use ( $category_slug ) {
368 + return $category_slug === $item[2];
369 + } );
370 +
371 + if ( $add_new_item ) {
372 + remove_submenu_page( static::ADMIN_MENU_SLUG, $add_new_slug );
373 +
374 + $admin_menu->register( admin_url( static::ADMIN_MENU_SLUG . '#add_new' ), new Add_New_Template_Menu_Item() );
375 + }
376 +
377 + if ( $categories_item ) {
378 + remove_submenu_page( static::ADMIN_MENU_SLUG, $category_slug );
379 +
380 + $admin_menu->register( $category_slug, new Templates_Categories_Menu_Item() );
381 + }
360 382 }
361 383
384 + /**
385 + * Add a `current` CSS class to the `Saved Templates` submenu page when it's active.
386 + * It should work by default, but since we interfere with WordPress' builtin CPT menus it doesn't work properly.
387 + *
388 + * @return void
389 + */
390 + private function admin_menu_set_current() {
391 + global $submenu;
392 +
393 + if ( $this->is_current_screen() ) {
394 + $library_submenu = &$submenu[ static::ADMIN_MENU_SLUG ];
395 + $library_title = $this->get_library_title();
396 +
397 + foreach ( $library_submenu as &$item ) {
398 + if ( $library_title === $item[0] ) {
399 + if ( ! isset( $item[4] ) ) {
400 + $item[4] = '';
401 + }
402 + $item[4] .= ' current';
403 + }
404 + }
405 + }
406 + }
407 +
408 + private function register_admin_menu( Admin_Menu_Manager $admin_menu ) {
409 + $admin_menu->register( static::get_admin_url( true ), new Saved_Templates_Menu_Item() );
410 + }
411 +
362 412 public function admin_title( $admin_title, $title ) {
363 413 $library_title = $this->get_library_title();
364 414
365 415 if ( $library_title ) {
@@ -369,54 +419,15 @@
369 419 return $admin_title;
370 420 }
371 421
372 422 public function replace_admin_heading() {
373 - if ( ! $this->is_current_screen() ) {
374 - return;
375 - }
376 -
377 - global $post_type_object;
378 -
379 423 $library_title = $this->get_library_title();
380 424
381 425 if ( $library_title ) {
426 + global $post_type_object;
427 +
382 428 $post_type_object->labels->name = $library_title;
383 429 }
384 -
385 - $labels = $this->get_current_template_labels();
386 - $template_singular = $labels['singular'];
387 - $template_plural = $labels['plural'];
388 -
389 - if ( ! $template_plural && $library_title ) {
390 - $template_plural = $library_title;
391 - }
392 -
393 - if ( $template_singular ) {
394 - $labels = $post_type_object->labels;
395 - $labels->name = $template_plural;
396 - $labels->singular_name = $template_singular;
397 - /* translators: %s: Template label (plural). */
398 - $labels->all_items = sprintf( esc_html__( 'All %s', 'elementor' ), $template_plural );
399 - /* translators: %s: Template label (singular). */
400 - $labels->add_new = sprintf( esc_html__( 'Add New %s', 'elementor' ), $template_singular );
401 - $labels->add_new_item = $labels->add_new;
402 - /* translators: %s: Template label (singular). */
403 - $labels->edit_item = sprintf( esc_html__( 'Edit %s', 'elementor' ), $template_singular );
404 - /* translators: %s: Template label (singular). */
405 - $labels->new_item = sprintf( esc_html__( 'New %s', 'elementor' ), $template_singular );
406 - /* translators: %s: Template label (singular). */
407 - $labels->view_item = sprintf( esc_html__( 'View %s', 'elementor' ), $template_singular );
408 - /* translators: %s: Template label (plural). */
409 - $labels->search_items = sprintf( esc_html__( 'Search %s', 'elementor' ), $template_plural );
410 - /* translators: %s: Template label (plural). */
411 - $labels->not_found = sprintf( esc_html__( 'No %s found', 'elementor' ), $template_plural );
412 - /* translators: %s: Template label (plural). */
413 - $labels->not_found_in_trash = sprintf( esc_html__( 'No %s found in Trash', 'elementor' ), $template_plural );
414 - /* translators: %s: Template label (singular). */
415 - $labels->parent_item_colon = sprintf( esc_html__( 'Parent %s:', 'elementor' ), $template_singular );
416 - $labels->menu_name = $template_plural;
417 - $post_type_object->labels = $labels;
418 - }
419 430 }
420 431
421 432 /**
422 433 * Get local templates.
@@ -716,22 +727,8 @@
716 727 }
717 728
718 729 if ( ! empty( $content ) ) {
719 730 $content = $this->replace_elements_ids( $content );
720 -
721 - /**
722 - * Filters the template content data.
723 - *
724 - * This filter allows third-party plugins to modify template content
725 - * when loaded via get_template_data(), making the behavior consistent
726 - * with Frontend::get_builder_content().
727 - *
728 - * @since 3.34.0
729 - *
730 - * @param array $content The template content data.
731 - * @param int $template_id The template ID.
732 - */
733 - $content = apply_filters( 'elementor/frontend/builder_content_data', $content, $template_id );
734 731 }
735 732 }
736 733
737 734 $data = [
@@ -743,12 +740,8 @@
743 740
744 741 $data['page_settings'] = $page->get_data( 'settings' );
745 742 }
746 743
747 - if ( ! empty( $content ) ) {
748 - $this->attach_global_styles_to_data( $data, $content, $template_id );
749 - }
750 -
751 744 return $data;
752 745 }
753 746
754 747 /**
@@ -923,9 +916,9 @@
923 916 * @param string $name - The file name.
924 917 * @param string $path - The file path.
925 918 * @return \WP_Error|array An array of items on success, 'WP_Error' on failure.
926 919 */
927 - public function import_template( $name, $path, $import_mode = 'match_site' ) {
920 + public function import_template( $name, $path ) {
928 921 if ( empty( $path ) ) {
929 922 return new \WP_Error( 'file_error', 'Please upload a file to import' );
930 923 }
931 924
@@ -945,18 +938,15 @@
945 938 return $extracted_files;
946 939 }
947 940
948 941 foreach ( $extracted_files['files'] as $file_path ) {
949 - // Skip macOS metadata files and folders
950 - if ( false !== strpos( $file_path, '__MACOSX' ) || '.' === basename( $file_path )[0] ) {
951 - continue;
952 - }
942 + $import_result = $this->import_single_template( $file_path );
953 943
954 - $import_result = $this->import_single_template( $file_path, $import_mode );
944 + if ( is_wp_error( $import_result ) ) {
945 + // Delete the temporary extraction directory, since it's now not necessary.
946 + Plugin::$instance->uploads_manager->remove_file_or_dir( $extracted_files['extraction_directory'] );
955 947
956 - if ( is_wp_error( $import_result ) ) {
957 - // Skip failed files
958 - continue;
948 + return $import_result;
959 949 }
960 950
961 951 $items[] = $import_result;
962 952 }
@@ -964,9 +954,9 @@
964 954 // Delete the temporary extraction directory, since it's now not necessary.
965 955 Plugin::$instance->uploads_manager->remove_file_or_dir( $extracted_files['extraction_directory'] );
966 956 } else {
967 957 // If the import file is a single JSON file
968 - $import_result = $this->import_single_template( $path, $import_mode );
958 + $import_result = $this->import_single_template( $path );
969 959
970 960 if ( is_wp_error( $import_result ) ) {
971 961 return $import_result;
972 962 }
@@ -994,17 +984,9 @@
994 984 */
995 985 public function post_row_actions( $actions, \WP_Post $post ) {
996 986 if ( self::is_base_templates_screen() ) {
997 987 if ( $this->is_template_supports_export( $post->ID ) ) {
998 - $template_labels = $this->get_template_labels_by_type( self::get_template_type( $post->ID ) );
999 - $export_label = esc_html__( 'Export Template', 'elementor' );
1000 -
1001 - if ( $template_labels['singular'] ) {
1002 - /* translators: %s: Template label (singular). */
1003 - $export_label = sprintf( esc_html__( 'Export %s', 'elementor' ), $template_labels['singular'] );
1004 - }
1005 -
1006 - $actions['export-template'] = sprintf( '<a href="%1$s">%2$s</a>', $this->get_export_link( $post->ID ), $export_label );
988 + $actions['export-template'] = sprintf( '<a href="%1$s">%2$s</a>', $this->get_export_link( $post->ID ), esc_html__( 'Export Template', 'elementor' ) );
1007 989 }
1008 990 }
1009 991
1010 992 return $actions;
@@ -1028,30 +1010,13 @@
1028 1010 }
1029 1011
1030 1012 /** @var \Elementor\Core\Common\Modules\Ajax\Module $ajax */
1031 1013 $ajax = Plugin::$instance->common->get_component( 'ajax' );
1032 - $template_labels = $this->get_current_template_labels();
1033 - $import_label = esc_html__( 'Import Templates', 'elementor' );
1034 - $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' );
1035 -
1036 - if ( $template_labels['plural'] ) {
1037 - /* translators: %s: Template label (plural). */
1038 - $import_label = sprintf( esc_html__( 'Import %s', 'elementor' ), $template_labels['plural'] );
1039 - }
1040 -
1041 - if ( $template_labels['singular'] && $template_labels['plural'] ) {
1042 - $description = sprintf(
1043 - /* translators: 1: Template label (singular). 2: Template label (plural). */
1044 - 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' ),
1045 - $template_labels['singular'],
1046 - $template_labels['plural']
1047 - );
1048 - }
1049 1014 ?>
1050 1015 <div id="elementor-hidden-area">
1051 - <a id="elementor-import-template-trigger" class="page-title-action button button-secondary"><?php echo esc_html( $import_label ); ?></a>
1016 + <a id="elementor-import-template-trigger" class="page-title-action"><?php echo esc_html__( 'Import Templates', 'elementor' ); ?></a>
1052 1017 <div id="elementor-import-template-area">
1053 - <div id="elementor-import-template-title"><?php echo esc_html( $description ); ?></div>
1018 + <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>
1054 1019 <form id="elementor-import-template-form" method="post" action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>" enctype="multipart/form-data">
1055 1020 <input type="hidden" name="action" value="elementor_library_direct_actions">
1056 1021 <input type="hidden" name="library_action" value="direct_import_template">
1057 1022 <input type="hidden" name="_nonce" value="<?php Utils::print_unescaped_internal_string( $ajax->create_nonce() ); ?>">
@@ -1082,23 +1047,8 @@
1082 1047 die;
1083 1048 }
1084 1049 }
1085 1050
1086 - public function redirect_categories_page_to_saved_templates_page() {
1087 - // phpcs:ignore WordPress.Security.NonceVerification.Recommended
1088 - $taxonomy = sanitize_key( wp_unslash( $_GET['taxonomy'] ?? '' ) );
1089 - // phpcs:ignore WordPress.Security.NonceVerification.Recommended
1090 - $post_type = sanitize_key( wp_unslash( $_GET['post_type'] ?? '' ) );
1091 - $is_categories_page = 'edit-tags.php' === $GLOBALS['pagenow']
1092 - && self::TAXONOMY_CATEGORY_SLUG === $taxonomy
1093 - && self::CPT === $post_type;
1094 -
1095 - if ( $is_categories_page ) {
1096 - wp_safe_redirect( admin_url( 'edit.php?post_type=' . self::CPT . '&tabs_group=library' ) );
1097 - die;
1098 - }
1099 - }
1100 -
1101 1051 /**
1102 1052 * Is template library supports export.
1103 1053 *
1104 1054 * Whether the template library supports export.
@@ -1401,9 +1351,9 @@
1401 1351 // TODO: This code maybe unreachable see if above `if ( empty( $document_types[ $current_type ] ) )`.
1402 1352 if ( empty( $current_type ) ) {
1403 1353 $counts = (array) wp_count_posts( self::CPT );
1404 1354 unset( $counts['auto-draft'] );
1405 - $count = array_sum( $counts );
1355 + $count = array_sum( $counts );
1406 1356
1407 1357 if ( 0 < $count ) {
1408 1358 return;
1409 1359 }
@@ -1417,24 +1367,14 @@
1417 1367 }
1418 1368
1419 1369 private function render_blank_state( $current_type, array $args = [] ) {
1420 1370 $current_type_label = $this->get_template_label_by_type( $current_type );
1421 - $type_labels = $this->get_template_labels_by_type( $current_type );
1422 - $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' );
1423 -
1424 - if ( $type_labels['plural'] ) {
1425 - $description = sprintf(
1426 - /* translators: %s: Template label (plural). */
1427 - esc_html__( 'Add %s and reuse them across your website. Easily export and import them to any other project, for an optimized workflow.', 'elementor' ),
1428 - $type_labels['plural']
1429 - );
1430 - }
1431 1371 $inline_style = '#posts-filter .wp-list-table, #posts-filter .tablenav.top, .tablenav.bottom .actions, .wrap .subsubsub { display:none;}';
1432 1372
1433 1373 $args = wp_parse_args( $args, [
1434 1374 'additional_inline_style' => '',
1435 1375 'href' => '',
1436 - 'description' => $description,
1376 + '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' ),
1437 1377 ] );
1438 1378 $inline_style .= $args['additional_inline_style'];
1439 1379 ?>
1440 1380 <style type="text/css"><?php Utils::print_unescaped_internal_string( $inline_style ); ?></style>
@@ -1529,15 +1469,11 @@
1529 1469 *
1530 1470 * @return \WP_Error|int|array Local template array, or template ID, or
1531 1471 * `WP_Error`.
1532 1472 */
1533 - private function import_single_template( $file_path, $import_mode = 'match_site' ) {
1534 - $data = $this->prepare_import_template_data( $file_path, $import_mode );
1473 + private function import_single_template( $file_path ) {
1474 + $data = $this->prepare_import_template_data( $file_path );
1535 1475
1536 - if ( is_wp_error( $data ) ) {
1537 - return $data;
1538 - }
1539 -
1540 1476 if ( empty( $data ) ) {
1541 1477 return new \WP_Error( 'file_error', 'Invalid File' );
1542 1478 }
1543 1479
@@ -1588,10 +1524,8 @@
1588 1524 'title' => $document->get_main_post()->post_title,
1589 1525 'type' => self::get_template_type( $template_id ),
1590 1526 ];
1591 1527
1592 - $this->attach_global_styles_to_data( $export_data, $content, $template_id );
1593 -
1594 1528 return [
1595 1529 'name' => 'elementor-' . $template_id . '-' . gmdate( 'Y-m-d' ) . '.json',
1596 1530 'content' => wp_json_encode( $export_data ),
1597 1531 ];
@@ -1632,68 +1566,8 @@
1632 1566
1633 1567 return $template_label;
1634 1568 }
1635 1569
1636 - private function get_template_labels_by_type( $template_type ) {
1637 - $labels = [
1638 - 'singular' => '',
1639 - 'plural' => '',
1640 - ];
1641 -
1642 - if ( ! $template_type ) {
1643 - return $labels;
1644 - }
1645 -
1646 - $document_types = Plugin::instance()->documents->get_document_types();
1647 -
1648 - if ( isset( $document_types[ $template_type ] ) ) {
1649 - $doc_type = $document_types[ $template_type ];
1650 - $labels['singular'] = call_user_func( [ $doc_type, 'get_title' ] );
1651 - $labels['plural'] = call_user_func( [ $doc_type, 'get_plural_title' ] );
1652 - } else {
1653 - $labels['singular'] = $this->get_template_label_by_type( $template_type );
1654 - }
1655 -
1656 - if ( ! $labels['plural'] ) {
1657 - $labels['plural'] = $labels['singular'];
1658 - }
1659 -
1660 - return $labels;
1661 - }
1662 -
1663 - private function get_current_template_labels() {
1664 - $labels = [
1665 - 'singular' => '',
1666 - 'plural' => '',
1667 - ];
1668 -
1669 - $template_type = Utils::get_super_global_value( $_GET, self::TAXONOMY_TYPE_SLUG );
1670 -
1671 - if ( $template_type ) {
1672 - return $this->get_template_labels_by_type( $template_type );
1673 - }
1674 -
1675 - $current_tabs_group = $this->get_current_tab_group();
1676 -
1677 - if ( $current_tabs_group ) {
1678 - $doc_types = Plugin::$instance->documents->get_document_types( [
1679 - 'admin_tab_group' => $current_tabs_group,
1680 - ], 'and' );
1681 -
1682 - if ( 1 === count( $doc_types ) ) {
1683 - $doc_type = reset( $doc_types );
1684 - $labels['singular'] = call_user_func( [ $doc_type, 'get_title' ] );
1685 - $labels['plural'] = call_user_func( [ $doc_type, 'get_plural_title' ] );
1686 - }
1687 - }
1688 -
1689 - if ( ! $labels['plural'] ) {
1690 - $labels['plural'] = $labels['singular'];
1691 - }
1692 -
1693 - return $labels;
1694 - }
1695 -
1696 1570 /**
1697 1571 * Filter template types in admin query.
1698 1572 *
1699 1573 * Update the template types in the main admin query.
@@ -1737,32 +1611,20 @@
1737 1611 * @access private
1738 1612 */
1739 1613 private function add_actions() {
1740 1614 if ( is_admin() ) {
1741 - add_action( 'admin_init', [ $this, 'redirect_categories_page_to_saved_templates_page' ] );
1615 + add_action( 'elementor/admin/menu/register', function ( Admin_Menu_Manager $admin_menu ) {
1616 + $this->register_admin_menu( $admin_menu );
1617 + }, static::ADMIN_MENU_PRIORITY );
1742 1618
1743 - add_action( 'elementor/editor-one/menu/register', function ( Menu_Data_Provider $menu_data_provider ) {
1744 - $this->register_editor_one_menu( $menu_data_provider );
1745 - } );
1619 + add_action( 'elementor/admin/menu/register', function ( Admin_Menu_Manager $admin_menu ) {
1620 + $this->admin_menu_reorder( $admin_menu );
1621 + }, 800 );
1746 1622
1747 - add_action( 'elementor/editor-one/menu/excluded_level4_slugs', function ( array $excluded_slugs ): array {
1748 - $excluded_slugs[] = 'edit.php?post_type=elementor_library#add_new';
1749 - $excluded_slugs[] = 'edit-tags.php?taxonomy=elementor_library_category&amp;post_type=elementor_library';
1750 - return $excluded_slugs;
1623 + add_action( 'elementor/admin/menu/after_register', function () {
1624 + $this->admin_menu_set_current();
1751 1625 } );
1752 1626
1753 - add_filter( 'elementor/editor-one/menu/elementor_post_types', function ( array $elementor_post_types ): array {
1754 - $elementor_post_types[ self::CPT ] = [];
1755 -
1756 - return $elementor_post_types;
1757 - } );
1758 -
1759 - add_filter( 'elementor/editor-one/admin-edit-post-types', function ( array $post_types ): array {
1760 - $post_types[] = self::CPT;
1761 -
1762 - return $post_types;
1763 - } );
1764 -
1765 1627 add_filter( 'admin_title', [ $this, 'admin_title' ], 10, 2 );
1766 1628 add_action( 'all_admin_notices', [ $this, 'replace_admin_heading' ] );
1767 1629 add_filter( 'post_row_actions', [ $this, 'post_row_actions' ], 10, 2 );
1768 1630 add_action( 'admin_footer', [ $this, 'admin_import_template_form' ] );
@@ -1842,11 +1704,13 @@
1842 1704
1843 1705 return $posts_columns;
1844 1706 }
1845 1707
1846 - public function get_current_tab_group() {
1847 - $current_tabs_group = Utils::get_super_global_value( $_GET, 'tabs_group' ) ?? '';
1848 - $type_slug = Utils::get_super_global_value( $_GET, self::TAXONOMY_TYPE_SLUG );
1708 + public function get_current_tab_group( $default = '' ) {
1709 + //phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce verification is not required here.
1710 + $current_tabs_group = Utils::get_super_global_value( $_REQUEST, 'tabs_group' ) ?? '';
1711 + //phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce verification is not required here.
1712 + $type_slug = Utils::get_super_global_value( $_REQUEST, self::TAXONOMY_TYPE_SLUG );
1849 1713
1850 1714 if ( $type_slug ) {
1851 1715 $doc_type = Plugin::$instance->documents->get_document_type( $type_slug, '' );
1852 1716 if ( $doc_type ) {
@@ -1934,102 +1798,6 @@
1934 1798 public function __construct() {
1935 1799 parent::__construct();
1936 1800
1937 1801 $this->add_actions();
1938 - }
1939 -
1940 - public function format_args_for_bulk_action( $args ) {
1941 - $bulk_args = [];
1942 -
1943 - foreach ( $args['from_template_id'] as $from_template_id ) {
1944 - if ( ! $this->is_allowed_to_read_template( [
1945 - 'template_id' => $from_template_id,
1946 - ] ) ) {
1947 - continue;
1948 - }
1949 -
1950 - $document = Plugin::$instance->documents->get( $from_template_id );
1951 -
1952 - if ( ! $document ) {
1953 - continue;
1954 - }
1955 -
1956 - $page = SettingsManager::get_settings_managers( 'page' )->get_model( $from_template_id );
1957 -
1958 - $bulk_args[] = array_merge(
1959 - $args,
1960 - [
1961 - 'title' => $document->get_post()->post_title,
1962 - 'type' => $document::get_type(),
1963 - 'content' => $document->get_elements_data(),
1964 - 'page_settings' => $page->get_data( 'settings' ),
1965 - ]
1966 - );
1967 - }
1968 -
1969 - return $bulk_args;
1970 - }
1971 -
1972 - public function format_args_for_single_action( $args ) {
1973 - if ( ! $this->is_allowed_to_read_template( [
1974 - 'template_id' => $args['from_template_id'],
1975 - ] ) ) {
1976 - return new \WP_Error(
1977 - 'template_error',
1978 - esc_html__( 'You do not have permission to access this template.', 'elementor' )
1979 - );
1980 - }
1981 -
1982 - $document = Plugin::$instance->documents->get( $args['from_template_id'] );
1983 -
1984 - if ( ! $document ) {
1985 - return new \WP_Error( 'template_error', 'Document not found.' );
1986 - }
1987 -
1988 - $args['content'] = $document->get_elements_data();
1989 -
1990 - $page = SettingsManager::get_settings_managers( 'page' )->get_model( $args['from_template_id'] );
1991 - $args['page_settings'] = $page->get_data( 'settings' );
1992 -
1993 - return $args;
1994 - }
1995 -
1996 - public function is_allowed_to_read_template( array $args ): bool {
1997 - if ( null === $this->wordpress_adapter ) {
1998 - $this->set_wordpress_adapter( new WordPress_Adapter() );
1999 - }
2000 -
2001 - if ( ! $this->should_check_permissions( $args ) ) {
2002 - return true;
2003 - }
2004 -
2005 - $post_id = intval( $args['template_id'] );
2006 - $post_status = $this->wordpress_adapter->get_post_status( $post_id );
2007 - $is_private_or_non_published = ( 'private' === $post_status && ! $this->wordpress_adapter->current_user_can( 'read_private_posts', $post_id ) ) || ( 'publish' !== $post_status );
2008 -
2009 - $can_read_template = ! $is_private_or_non_published || $this->wordpress_adapter->current_user_can( 'edit_post', $post_id );
2010 -
2011 - return apply_filters( 'elementor/template-library/is_allowed_to_read_template', $can_read_template, $args );
2012 - }
2013 -
2014 - private function should_check_permissions( array $args ): bool {
2015 - if ( null === $this->elementor_adapter ) {
2016 - $this->set_elementor_adapter( new Elementor_Adapter() );
2017 - }
2018 -
2019 - $check_permissions = isset( $args['check_permissions'] ) && false === $args['check_permissions'];
2020 -
2021 - if ( $check_permissions ) {
2022 - return false;
2023 - }
2024 -
2025 - return true;
2026 - }
2027 -
2028 - public function set_wordpress_adapter( Wordpress_Adapter_Interface $wordpress_adapter ) {
2029 - $this->wordpress_adapter = $wordpress_adapter;
2030 - }
2031 -
2032 - public function set_elementor_adapter( Elementor_Adapter_Interface $elementor_adapter ): void {
2033 - $this->elementor_adapter = $elementor_adapter;
2034 1802 }
2035 1803 }