| @@ -2,24 +2,13 @@ | ||
| 2 | 2 | namespace Elementor\TemplateLibrary; |
| 3 | 3 | |
| 4 | 4 | use Elementor\Core\Base\Document; |
| 5 | 5 | use Elementor\Core\Editor\Editor; |
| 6 | -use Elementor\Core\Utils\Collection; | |
| 7 | 6 | use Elementor\DB; |
| 8 | 7 | use Elementor\Core\Settings\Manager as SettingsManager; |
| 9 | -use Elementor\Includes\TemplateLibrary\Sources\AdminMenuItems\Add_New_Template_Menu_Item; | |
| 10 | -use Elementor\Includes\TemplateLibrary\Sources\AdminMenuItems\Saved_Templates_Menu_Item; | |
| 11 | -use Elementor\Includes\TemplateLibrary\Sources\AdminMenuItems\Templates_Categories_Menu_Item; | |
| 8 | +use Elementor\Core\Settings\Page\Model; | |
| 12 | 9 | use Elementor\Modules\Library\Documents\Library_Document; |
| 13 | 10 | use Elementor\Plugin; |
| 14 | -use Elementor\Utils; | |
| 15 | -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_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 | 11 | |
| 23 | 12 | if ( ! defined( 'ABSPATH' ) ) { |
| 24 | 13 | exit; // Exit if accessed directly. |
| 25 | 14 | } |
| @@ -50,10 +39,9 @@ | ||
| 50 | 39 | const TAXONOMY_CATEGORY_SLUG = 'elementor_library_category'; |
| 51 | 40 | |
| 52 | 41 | /** |
| 53 | 42 | * Elementor template-library meta key. |
| 54 | - * | |
| 55 | - * @deprecated 2.3.0 Use `Elementor\Core\Base\Document::TYPE_META_KEY` const instead. | |
| 43 | + * @deprecated 2.3.0 Use \Elementor\Core\Base\Document::TYPE_META_KEY instead | |
| 56 | 44 | */ |
| 57 | 45 | const TYPE_META_KEY = '_elementor_template_type'; |
| 58 | 46 | |
| 59 | 47 | /** |
| @@ -67,10 +55,8 @@ | ||
| 67 | 55 | const BULK_EXPORT_ACTION = 'elementor_export_multiple_templates'; |
| 68 | 56 | |
| 69 | 57 | const ADMIN_MENU_SLUG = 'edit.php?post_type=elementor_library'; |
| 70 | 58 | |
| 71 | - const ADMIN_MENU_PRIORITY = 10; | |
| 72 | - | |
| 73 | 59 | const ADMIN_SCREEN_ID = 'edit-elementor_library'; |
| 74 | 60 | |
| 75 | 61 | /** |
| 76 | 62 | * Template types. |
| @@ -95,18 +81,8 @@ | ||
| 95 | 81 | */ |
| 96 | 82 | private $post_type_object; |
| 97 | 83 | |
| 98 | 84 | /** |
| 99 | - * @var Wordpress_Adapter_Interface | |
| 100 | - */ | |
| 101 | - protected $wordpress_adapter = null; | |
| 102 | - | |
| 103 | - /** | |
| 104 | - * @var Elementor_Adapter_Interface | |
| 105 | - */ | |
| 106 | - protected $elementor_adapter = null; | |
| 107 | - | |
| 108 | - /** | |
| 109 | 85 | * @since 2.3.0 |
| 110 | 86 | * @access public |
| 111 | 87 | * @static |
| 112 | 88 | * @return array |
| @@ -219,9 +195,9 @@ | ||
| 219 | 195 | * |
| 220 | 196 | * @return string The local template title. |
| 221 | 197 | */ |
| 222 | 198 | public function get_title() { |
| 223 | - return esc_html__( 'Local', 'elementor' ); | |
| 199 | + return __( 'Local', 'elementor' ); | |
| 224 | 200 | } |
| 225 | 201 | |
| 226 | 202 | /** |
| 227 | 203 | * Register local template data. |
| @@ -237,21 +213,21 @@ | ||
| 237 | 213 | * @access public |
| 238 | 214 | */ |
| 239 | 215 | public function register_data() { |
| 240 | 216 | $labels = [ |
| 241 | - 'name' => esc_html_x( 'My Templates', 'Template Library', 'elementor' ), | |
| 242 | - 'singular_name' => esc_html_x( 'Template', 'Template Library', 'elementor' ), | |
| 243 | - 'add_new' => esc_html__( 'Add New Template', 'elementor' ), | |
| 244 | - 'add_new_item' => esc_html__( 'Add New Template', 'elementor' ), | |
| 245 | - 'edit_item' => esc_html__( 'Edit Template', 'elementor' ), | |
| 246 | - 'new_item' => esc_html__( 'New Template', 'elementor' ), | |
| 247 | - 'all_items' => esc_html__( 'All Templates', 'elementor' ), | |
| 248 | - 'view_item' => esc_html__( 'View Template', 'elementor' ), | |
| 249 | - 'search_items' => esc_html__( 'Search Template', 'elementor' ), | |
| 250 | - 'not_found' => esc_html__( 'No Templates found', 'elementor' ), | |
| 251 | - 'not_found_in_trash' => esc_html__( 'No Templates found in Trash', 'elementor' ), | |
| 252 | - 'parent_item_colon' => esc_html__( 'Parent Template:', 'elementor' ), | |
| 253 | - 'menu_name' => esc_html_x( 'Templates', 'Template Library', 'elementor' ), | |
| 217 | + 'name' => _x( 'My Templates', 'Template Library', 'elementor' ), | |
| 218 | + 'singular_name' => _x( 'Template', 'Template Library', 'elementor' ), | |
| 219 | + 'add_new' => _x( 'Add New', 'Template Library', 'elementor' ), | |
| 220 | + 'add_new_item' => _x( 'Add New Template', 'Template Library', 'elementor' ), | |
| 221 | + 'edit_item' => _x( 'Edit Template', 'Template Library', 'elementor' ), | |
| 222 | + 'new_item' => _x( 'New Template', 'Template Library', 'elementor' ), | |
| 223 | + 'all_items' => _x( 'All Templates', 'Template Library', 'elementor' ), | |
| 224 | + 'view_item' => _x( 'View Template', 'Template Library', 'elementor' ), | |
| 225 | + 'search_items' => _x( 'Search Template', 'Template Library', 'elementor' ), | |
| 226 | + 'not_found' => _x( 'No Templates found', 'Template Library', 'elementor' ), | |
| 227 | + 'not_found_in_trash' => _x( 'No Templates found in Trash', 'Template Library', 'elementor' ), | |
| 228 | + 'parent_item_colon' => '', | |
| 229 | + 'menu_name' => _x( 'Templates', 'Template Library', 'elementor' ), | |
| 254 | 230 | ]; |
| 255 | 231 | |
| 256 | 232 | $args = [ |
| 257 | 233 | 'labels' => $labels, |
| @@ -263,14 +239,11 @@ | ||
| 263 | 239 | 'show_in_nav_menus' => false, |
| 264 | 240 | 'exclude_from_search' => true, |
| 265 | 241 | 'capability_type' => 'post', |
| 266 | 242 | 'hierarchical' => false, |
| 267 | - 'supports' => [ 'title', 'thumbnail', 'author', 'elementor', 'custom-fields' ], | |
| 268 | - 'show_in_rest' => true, | |
| 243 | + 'supports' => [ 'title', 'thumbnail', 'author', 'elementor' ], | |
| 269 | 244 | ]; |
| 270 | 245 | |
| 271 | - $this->avoid_rest_access_for_non_admins(); | |
| 272 | - | |
| 273 | 246 | /** |
| 274 | 247 | * Register template library post type args. |
| 275 | 248 | * |
| 276 | 249 | * Filters the post type arguments when registering elementor template library post type. |
| @@ -290,9 +263,9 @@ | ||
| 290 | 263 | 'show_admin_column' => true, |
| 291 | 264 | 'query_var' => is_admin(), |
| 292 | 265 | 'rewrite' => false, |
| 293 | 266 | 'public' => false, |
| 294 | - 'label' => esc_html_x( 'Type', 'Template Library', 'elementor' ), | |
| 267 | + 'label' => _x( 'Type', 'Template Library', 'elementor' ), | |
| 295 | 268 | ]; |
| 296 | 269 | |
| 297 | 270 | /** |
| 298 | 271 | * Register template library taxonomy args. |
| @@ -304,21 +277,10 @@ | ||
| 304 | 277 | * @param array $args Arguments for registering a taxonomy. |
| 305 | 278 | */ |
| 306 | 279 | $args = apply_filters( 'elementor/template_library/sources/local/register_taxonomy_args', $args ); |
| 307 | 280 | |
| 308 | - $cpts_to_associate = [ self::CPT ]; | |
| 281 | + $cpts_to_associate = apply_filters( 'elementor/template_library/sources/local/register_taxonomy_cpts', [ self::CPT ] ); | |
| 309 | 282 | |
| 310 | - /** | |
| 311 | - * Custom post types to associate. | |
| 312 | - * | |
| 313 | - * Filters the list of custom post types when registering elementor template library taxonomy. | |
| 314 | - * | |
| 315 | - * @since 1.0.0 | |
| 316 | - * | |
| 317 | - * @param array $cpts_to_associate Custom post types. Default is `elementor_library` post type. | |
| 318 | - */ | |
| 319 | - $cpts_to_associate = apply_filters( 'elementor/template_library/sources/local/register_taxonomy_cpts', $cpts_to_associate ); | |
| 320 | - | |
| 321 | 283 | register_taxonomy( self::TAXONOMY_TYPE_SLUG, $cpts_to_associate, $args ); |
| 322 | 284 | |
| 323 | 285 | /** |
| 324 | 286 | * Categories |
| @@ -331,11 +293,11 @@ | ||
| 331 | 293 | 'query_var' => is_admin(), |
| 332 | 294 | 'rewrite' => false, |
| 333 | 295 | 'public' => false, |
| 334 | 296 | 'labels' => [ |
| 335 | - 'name' => esc_html_x( 'Categories', 'Template Library', 'elementor' ), | |
| 336 | - 'singular_name' => esc_html_x( 'Category', 'Template Library', 'elementor' ), | |
| 337 | - 'all_items' => esc_html_x( 'All Categories', 'Template Library', 'elementor' ), | |
| 297 | + 'name' => _x( 'Categories', 'Template Library', 'elementor' ), | |
| 298 | + 'singular_name' => _x( 'Category', 'Template Library', 'elementor' ), | |
| 299 | + 'all_items' => _x( 'All Categories', 'Template Library', 'elementor' ), | |
| 338 | 300 | ], |
| 339 | 301 | ]; |
| 340 | 302 | |
| 341 | 303 | /** |
| @@ -351,14 +313,58 @@ | ||
| 351 | 313 | |
| 352 | 314 | register_taxonomy( self::TAXONOMY_CATEGORY_SLUG, self::CPT, $args ); |
| 353 | 315 | } |
| 354 | 316 | |
| 317 | + /** | |
| 318 | + * Remove Add New item from admin menu. | |
| 319 | + * | |
| 320 | + * Fired by `admin_menu` action. | |
| 321 | + * | |
| 322 | + * @since 2.4.0 | |
| 323 | + * @access public | |
| 324 | + */ | |
| 325 | + public function admin_menu_reorder() { | |
| 326 | + global $submenu; | |
| 355 | 327 | |
| 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() ); | |
| 328 | + if ( ! isset( $submenu[ self::ADMIN_MENU_SLUG ] ) ) { | |
| 329 | + return; | |
| 330 | + } | |
| 331 | + $library_submenu = &$submenu[ self::ADMIN_MENU_SLUG ]; | |
| 332 | + | |
| 333 | + // Remove 'All Templates' menu. | |
| 334 | + unset( $library_submenu[5] ); | |
| 335 | + | |
| 336 | + // If current use can 'Add New' - move the menu to end, and add the '#add_new' anchor. | |
| 337 | + if ( isset( $library_submenu[10][2] ) ) { | |
| 338 | + $library_submenu[700] = $library_submenu[10]; | |
| 339 | + unset( $library_submenu[10] ); | |
| 340 | + $library_submenu[700][2] = admin_url( self::ADMIN_MENU_SLUG . '#add_new' ); | |
| 341 | + } | |
| 342 | + | |
| 343 | + // Move the 'Categories' menu to end. | |
| 344 | + if ( isset( $library_submenu[15] ) ) { | |
| 345 | + $library_submenu[800] = $library_submenu[15]; | |
| 346 | + unset( $library_submenu[15] ); | |
| 347 | + } | |
| 348 | + | |
| 349 | + if ( $this->is_current_screen() ) { | |
| 350 | + $library_title = $this->get_library_title(); | |
| 351 | + | |
| 352 | + foreach ( $library_submenu as &$item ) { | |
| 353 | + if ( $library_title === $item[0] ) { | |
| 354 | + if ( ! isset( $item[4] ) ) { | |
| 355 | + $item[4] = ''; | |
| 356 | + } | |
| 357 | + $item[4] .= ' current'; | |
| 358 | + } | |
| 359 | + } | |
| 360 | + } | |
| 359 | 361 | } |
| 360 | 362 | |
| 363 | + public function admin_menu() { | |
| 364 | + add_submenu_page( self::ADMIN_MENU_SLUG, '', __( 'Saved Templates', 'elementor' ), Editor::EDITING_CAPABILITY, self::get_admin_url( true ) ); | |
| 365 | + } | |
| 366 | + | |
| 361 | 367 | public function admin_title( $admin_title, $title ) { |
| 362 | 368 | $library_title = $this->get_library_title(); |
| 363 | 369 | |
| 364 | 370 | if ( $library_title ) { |
| @@ -368,54 +374,15 @@ | ||
| 368 | 374 | return $admin_title; |
| 369 | 375 | } |
| 370 | 376 | |
| 371 | 377 | public function replace_admin_heading() { |
| 372 | - if ( ! $this->is_current_screen() ) { | |
| 373 | - return; | |
| 374 | - } | |
| 375 | - | |
| 376 | - global $post_type_object; | |
| 377 | - | |
| 378 | 378 | $library_title = $this->get_library_title(); |
| 379 | 379 | |
| 380 | 380 | if ( $library_title ) { |
| 381 | + global $post_type_object; | |
| 382 | + | |
| 381 | 383 | $post_type_object->labels->name = $library_title; |
| 382 | 384 | } |
| 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 | 385 | } |
| 419 | 386 | |
| 420 | 387 | /** |
| 421 | 388 | * Get local templates. |
| @@ -480,35 +447,25 @@ | ||
| 480 | 447 | * @return \WP_Error|int The ID of the saved/updated template, `WP_Error` otherwise. |
| 481 | 448 | */ |
| 482 | 449 | public function save_item( $template_data ) { |
| 483 | 450 | if ( ! current_user_can( $this->post_type_object->cap->edit_posts ) ) { |
| 484 | - return new \WP_Error( 'save_error', esc_html__( 'Access denied.', 'elementor' ) ); | |
| 451 | + return new \WP_Error( 'save_error', __( 'Access denied.', 'elementor' ) ); | |
| 485 | 452 | } |
| 486 | 453 | |
| 487 | 454 | $defaults = [ |
| 488 | - 'title' => esc_html__( '(no title)', 'elementor' ), | |
| 455 | + 'title' => __( '(no title)', 'elementor' ), | |
| 489 | 456 | 'page_settings' => [], |
| 457 | + 'status' => current_user_can( 'publish_posts' ) ? 'publish' : 'pending', | |
| 490 | 458 | ]; |
| 491 | 459 | |
| 492 | 460 | $template_data = wp_parse_args( $template_data, $defaults ); |
| 493 | - $template_data['status'] = current_user_can( 'publish_posts' ) ? 'publish' : 'pending'; | |
| 494 | 461 | |
| 495 | - // BC: Allow importing any template type when using CLI | |
| 496 | - // to support users that rely on this mechanism. | |
| 497 | - $should_check_template_type = ! $this->is_wp_cli(); | |
| 498 | - | |
| 499 | - if ( | |
| 500 | - $should_check_template_type && | |
| 501 | - ! $this->is_valid_template_type( $template_data['type'] ) | |
| 502 | - ) { | |
| 503 | - return new \WP_Error( 'invalid_template_type', esc_html__( 'Invalid template type.', 'elementor' ) ); | |
| 504 | - } | |
| 505 | - | |
| 506 | 462 | $document = Plugin::$instance->documents->create( |
| 507 | 463 | $template_data['type'], |
| 508 | 464 | [ |
| 509 | 465 | 'post_title' => $template_data['title'], |
| 510 | 466 | 'post_status' => $template_data['status'], |
| 467 | + 'post_type' => self::CPT, | |
| 511 | 468 | ] |
| 512 | 469 | ); |
| 513 | 470 | |
| 514 | 471 | if ( is_wp_error( $document ) ) { |
| @@ -555,35 +512,8 @@ | ||
| 555 | 512 | |
| 556 | 513 | return $template_id; |
| 557 | 514 | } |
| 558 | 515 | |
| 559 | - protected function is_valid_template_type( $type ) { | |
| 560 | - $document_class = Plugin::$instance->documents->get_document_type( $type, false ); | |
| 561 | - | |
| 562 | - if ( ! $document_class ) { | |
| 563 | - return false; | |
| 564 | - } | |
| 565 | - | |
| 566 | - $cpt = $document_class::get_property( 'cpt' ); | |
| 567 | - | |
| 568 | - if ( ! $cpt || ! is_array( $cpt ) || 1 !== count( $cpt ) ) { | |
| 569 | - return false; | |
| 570 | - } | |
| 571 | - | |
| 572 | - $is_valid_template_type = in_array( static::CPT, $cpt, true ); | |
| 573 | - | |
| 574 | - return apply_filters( | |
| 575 | - 'elementor/template_library/sources/local/is_valid_template_type', | |
| 576 | - $is_valid_template_type, | |
| 577 | - $cpt, | |
| 578 | - ); | |
| 579 | - } | |
| 580 | - | |
| 581 | - /** For testing purposes only, in order to be able to mock the `WP_CLI` constant. */ | |
| 582 | - protected function is_wp_cli() { | |
| 583 | - return Utils::is_wp_cli(); | |
| 584 | - } | |
| 585 | - | |
| 586 | 516 | /** |
| 587 | 517 | * Update local template. |
| 588 | 518 | * |
| 589 | 519 | * Update template on the database. |
| @@ -596,29 +526,21 @@ | ||
| 596 | 526 | * @return \WP_Error|true True if template updated, `WP_Error` otherwise. |
| 597 | 527 | */ |
| 598 | 528 | public function update_item( $new_data ) { |
| 599 | 529 | if ( ! current_user_can( $this->post_type_object->cap->edit_post, $new_data['id'] ) ) { |
| 600 | - return new \WP_Error( 'save_error', esc_html__( 'Access denied.', 'elementor' ) ); | |
| 530 | + return new \WP_Error( 'save_error', __( 'Access denied.', 'elementor' ) ); | |
| 601 | 531 | } |
| 602 | 532 | |
| 603 | 533 | $document = Plugin::$instance->documents->get( $new_data['id'] ); |
| 604 | 534 | |
| 605 | 535 | if ( ! $document ) { |
| 606 | - return new \WP_Error( 'save_error', esc_html__( 'Template not exist.', 'elementor' ) ); | |
| 536 | + return new \WP_Error( 'save_error', __( 'Template not exist.', 'elementor' ) ); | |
| 607 | 537 | } |
| 608 | 538 | |
| 609 | - $save_data = []; | |
| 539 | + $document->save( [ | |
| 540 | + 'elements' => $new_data['content'], | |
| 541 | + ] ); | |
| 610 | 542 | |
| 611 | - if ( isset( $new_data['title'] ) ) { | |
| 612 | - $save_data['post_title'] = $new_data['title']; | |
| 613 | - } | |
| 614 | - | |
| 615 | - if ( isset( $new_data['content'] ) ) { | |
| 616 | - $save_data['elements'] = $new_data['content']; | |
| 617 | - } | |
| 618 | - | |
| 619 | - $document->save( $save_data ); | |
| 620 | - | |
| 621 | 543 | /** |
| 622 | 544 | * After template library update. |
| 623 | 545 | * |
| 624 | 546 | * Fires after Elementor template library was updated. |
| @@ -715,22 +637,8 @@ | ||
| 715 | 637 | } |
| 716 | 638 | |
| 717 | 639 | if ( ! empty( $content ) ) { |
| 718 | 640 | $content = $this->replace_elements_ids( $content ); |
| 719 | - | |
| 720 | - /** | |
| 721 | - * Filters the template content data. | |
| 722 | - * | |
| 723 | - * This filter allows third-party plugins to modify template content | |
| 724 | - * when loaded via get_template_data(), making the behavior consistent | |
| 725 | - * with Frontend::get_builder_content(). | |
| 726 | - * | |
| 727 | - * @since 3.34.0 | |
| 728 | - * | |
| 729 | - * @param array $content The template content data. | |
| 730 | - * @param int $template_id The template ID. | |
| 731 | - */ | |
| 732 | - $content = apply_filters( 'elementor/frontend/builder_content_data', $content, $template_id ); | |
| 733 | 641 | } |
| 734 | 642 | } |
| 735 | 643 | |
| 736 | 644 | $data = [ |
| @@ -742,12 +650,8 @@ | ||
| 742 | 650 | |
| 743 | 651 | $data['page_settings'] = $page->get_data( 'settings' ); |
| 744 | 652 | } |
| 745 | 653 | |
| 746 | - if ( ! empty( $content ) ) { | |
| 747 | - $this->attach_global_styles_to_data( $data, $content, $template_id ); | |
| 748 | - } | |
| 749 | - | |
| 750 | 654 | return $data; |
| 751 | 655 | } |
| 752 | 656 | |
| 753 | 657 | /** |
| @@ -764,28 +668,14 @@ | ||
| 764 | 668 | * or 'WP_Error' on failure. |
| 765 | 669 | */ |
| 766 | 670 | public function delete_template( $template_id ) { |
| 767 | 671 | if ( ! current_user_can( $this->post_type_object->cap->delete_post, $template_id ) ) { |
| 768 | - return new \WP_Error( 'template_error', esc_html__( 'Access denied.', 'elementor' ) ); | |
| 672 | + return new \WP_Error( 'template_error', __( 'Access denied.', 'elementor' ) ); | |
| 769 | 673 | } |
| 770 | 674 | |
| 771 | 675 | return wp_delete_post( $template_id, true ); |
| 772 | 676 | } |
| 773 | 677 | |
| 774 | - public function bulk_delete_items( array $template_ids ) { | |
| 775 | - foreach ( $template_ids as $template_id ) { | |
| 776 | - if ( ! current_user_can( $this->post_type_object->cap->delete_post, $template_id ) ) { | |
| 777 | - return new \WP_Error( 'template_error', esc_html__( 'Access denied.', 'elementor' ) ); | |
| 778 | - } | |
| 779 | - } | |
| 780 | - | |
| 781 | - foreach ( $template_ids as $template_id ) { | |
| 782 | - wp_delete_post( $template_id, true ); | |
| 783 | - } | |
| 784 | - | |
| 785 | - return true; | |
| 786 | - } | |
| 787 | - | |
| 788 | 678 | /** |
| 789 | 679 | * Export local template. |
| 790 | 680 | * |
| 791 | 681 | * Export template to a file. |
| @@ -797,14 +687,8 @@ | ||
| 797 | 687 | * |
| 798 | 688 | * @return \WP_Error WordPress error if template export failed. |
| 799 | 689 | */ |
| 800 | 690 | public function export_template( $template_id ) { |
| 801 | - $permissions_error = $this->validate_template_export_permissions( $template_id ); | |
| 802 | - | |
| 803 | - if ( is_wp_error( $permissions_error ) ) { | |
| 804 | - return $permissions_error; | |
| 805 | - } | |
| 806 | - | |
| 807 | 691 | $file_data = $this->prepare_template_export( $template_id ); |
| 808 | 692 | |
| 809 | 693 | if ( is_wp_error( $file_data ) ) { |
| 810 | 694 | return $file_data; |
| @@ -811,29 +695,17 @@ | ||
| 811 | 695 | } |
| 812 | 696 | |
| 813 | 697 | $this->send_file_headers( $file_data['name'], strlen( $file_data['content'] ) ); |
| 814 | 698 | |
| 815 | - $this->serve_file( $file_data['content'] ); | |
| 699 | + // Clear buffering just in case. | |
| 700 | + @ob_end_clean(); | |
| 816 | 701 | |
| 817 | - die; | |
| 818 | - } | |
| 702 | + flush(); | |
| 819 | 703 | |
| 820 | - private function validate_template_export_permissions( $template_id ) { | |
| 821 | - $post_id = intval( $template_id ); | |
| 822 | - if ( get_post_type( $post_id ) !== self::CPT ) { | |
| 823 | - return new \WP_Error( 'template_error', esc_html__( 'Invalid template type or template does not exist.', 'elementor' ) ); | |
| 824 | - } | |
| 704 | + // Output file contents. | |
| 705 | + echo $file_data['content']; | |
| 825 | 706 | |
| 826 | - $post_status = get_post_status( $post_id ); | |
| 827 | - if ( 'private' === $post_status && ! current_user_can( 'read_private_posts', $post_id ) ) { | |
| 828 | - return new \WP_Error( 'template_error', esc_html__( 'You do not have permission to access this template.', 'elementor' ) ); | |
| 829 | - } | |
| 830 | - | |
| 831 | - if ( 'publish' !== $post_status && ! current_user_can( 'edit_post', $post_id ) ) { | |
| 832 | - return new \WP_Error( 'template_error', esc_html__( 'You do not have permission to export this template.', 'elementor' ) ); | |
| 833 | - } | |
| 834 | - | |
| 835 | - return null; | |
| 707 | + die; | |
| 836 | 708 | } |
| 837 | 709 | |
| 838 | 710 | /** |
| 839 | 711 | * Export multiple local templates. |
| @@ -901,12 +773,14 @@ | ||
| 901 | 773 | foreach ( $files as $file ) { |
| 902 | 774 | unlink( $file['path'] ); |
| 903 | 775 | } |
| 904 | 776 | |
| 905 | - $this->send_file_headers( $zip_archive_filename, $this->filesize( $zip_complete_path ) ); | |
| 777 | + $this->send_file_headers( $zip_archive_filename, filesize( $zip_complete_path ) ); | |
| 906 | 778 | |
| 907 | - $this->serve_zip( $zip_complete_path ); | |
| 779 | + @ob_end_flush(); | |
| 908 | 780 | |
| 781 | + @readfile( $zip_complete_path ); | |
| 782 | + | |
| 909 | 783 | unlink( $zip_complete_path ); |
| 910 | 784 | |
| 911 | 785 | die; |
| 912 | 786 | } |
| @@ -911,8 +785,46 @@ | ||
| 911 | 785 | die; |
| 912 | 786 | } |
| 913 | 787 | |
| 914 | 788 | /** |
| 789 | + * Find temporary files. | |
| 790 | + * | |
| 791 | + * Recursively finds a list of temporary files from the extracted zip file. | |
| 792 | + * | |
| 793 | + * Example return data: | |
| 794 | + * | |
| 795 | + * [ | |
| 796 | + * 0 => '/www/wp-content/uploads/elementor/tmp/5eb3a7a411d44/templates/block-2-col-marble-title.json', | |
| 797 | + * 1 => '/www/wp-content/uploads/elementor/tmp/5eb3a7a411d44/templates/block-2-col-text-and-photo.json', | |
| 798 | + * ] | |
| 799 | + * | |
| 800 | + * @since 2.9.8 | |
| 801 | + * @access private | |
| 802 | + * | |
| 803 | + * @param string $temp_path - The temporary file path to scan for template files | |
| 804 | + * | |
| 805 | + * @return array An array of temporary files on the filesystem | |
| 806 | + */ | |
| 807 | + private function find_temp_files( $temp_path ) { | |
| 808 | + | |
| 809 | + $file_names = []; | |
| 810 | + | |
| 811 | + $possible_file_names = array_diff( scandir( $temp_path ), [ '.', '..' ] ); | |
| 812 | + | |
| 813 | + // Find nested files in the unzipped path. This happens for example when the user imports a Template Kit. | |
| 814 | + foreach ( $possible_file_names as $possible_file_name ) { | |
| 815 | + $full_possible_file_name = $temp_path . '/' . $possible_file_name; | |
| 816 | + if ( is_dir( $full_possible_file_name ) ) { | |
| 817 | + $file_names = $file_names + $this->find_temp_files( $full_possible_file_name ); | |
| 818 | + } else { | |
| 819 | + $file_names[] = $full_possible_file_name; | |
| 820 | + } | |
| 821 | + } | |
| 822 | + | |
| 823 | + return $file_names; | |
| 824 | + } | |
| 825 | + | |
| 826 | + /** | |
| 915 | 827 | * Import local template. |
| 916 | 828 | * |
| 917 | 829 | * Import template from a file. |
| 918 | 830 | * |
| @@ -918,54 +830,70 @@ | ||
| 918 | 830 | * |
| 919 | 831 | * @since 1.0.0 |
| 920 | 832 | * @access public |
| 921 | 833 | * |
| 922 | - * @param string $name - The file name. | |
| 923 | - * @param string $path - The file path. | |
| 834 | + * @param string $name - The file name | |
| 835 | + * @param string $path - The file path | |
| 836 | + * | |
| 924 | 837 | * @return \WP_Error|array An array of items on success, 'WP_Error' on failure. |
| 925 | 838 | */ |
| 926 | - public function import_template( $name, $path, $import_mode = 'match_site' ) { | |
| 839 | + public function import_template( $name, $path ) { | |
| 927 | 840 | if ( empty( $path ) ) { |
| 928 | 841 | return new \WP_Error( 'file_error', 'Please upload a file to import' ); |
| 929 | 842 | } |
| 930 | 843 | |
| 931 | - // Set the Request's state as an Elementor upload request, in order to support unfiltered file uploads. | |
| 932 | - Plugin::$instance->uploads_manager->set_elementor_upload_state( true ); | |
| 844 | + $items = []; | |
| 933 | 845 | |
| 934 | - $items = []; | |
| 846 | + $file_extension = pathinfo( $name, PATHINFO_EXTENSION ); | |
| 935 | 847 | |
| 936 | - // If the import file is a Zip file with potentially multiple JSON files | |
| 937 | - if ( 'zip' === pathinfo( $name, PATHINFO_EXTENSION ) ) { | |
| 938 | - $extracted_files = Plugin::$instance->uploads_manager->extract_and_validate_zip( $path, [ 'json' ] ); | |
| 848 | + if ( 'zip' === $file_extension ) { | |
| 849 | + if ( ! class_exists( '\ZipArchive' ) ) { | |
| 850 | + return new \WP_Error( 'zip_error', 'PHP Zip extension not loaded' ); | |
| 851 | + } | |
| 939 | 852 | |
| 940 | - if ( is_wp_error( $extracted_files ) ) { | |
| 941 | - // Delete the temporary extraction directory, since it's now not necessary. | |
| 942 | - Plugin::$instance->uploads_manager->remove_file_or_dir( $extracted_files['extraction_directory'] ); | |
| 853 | + $zip = new \ZipArchive(); | |
| 943 | 854 | |
| 944 | - return $extracted_files; | |
| 855 | + $wp_upload_dir = wp_upload_dir(); | |
| 856 | + | |
| 857 | + $temp_path = $wp_upload_dir['basedir'] . '/' . self::TEMP_FILES_DIR . '/' . uniqid(); | |
| 858 | + | |
| 859 | + $zip->open( $path ); | |
| 860 | + | |
| 861 | + $valid_entries = []; | |
| 862 | + | |
| 863 | + // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase | |
| 864 | + for ( $i = 0; $i < $zip->numFiles; $i++ ) { | |
| 865 | + $zipped_file_name = $zip->getNameIndex( $i ); | |
| 866 | + $zipped_extension = pathinfo( $zipped_file_name, PATHINFO_EXTENSION ); | |
| 867 | + // Template Kit zip files contain a `manifest.json` file, this is not a valid Elementor template so ensure we skip it. | |
| 868 | + if ( 'json' === $zipped_extension && 'manifest.json' !== $zipped_file_name ) { | |
| 869 | + $valid_entries[] = $zipped_file_name; | |
| 870 | + } | |
| 945 | 871 | } |
| 946 | 872 | |
| 947 | - foreach ( $extracted_files['files'] as $file_path ) { | |
| 948 | - // Skip macOS metadata files and folders | |
| 949 | - if ( false !== strpos( $file_path, '__MACOSX' ) || '.' === basename( $file_path )[0] ) { | |
| 950 | - continue; | |
| 951 | - } | |
| 873 | + if ( ! empty( $valid_entries ) ) { | |
| 874 | + $zip->extractTo( $temp_path, $valid_entries ); | |
| 875 | + } | |
| 952 | 876 | |
| 953 | - $import_result = $this->import_single_template( $file_path, $import_mode ); | |
| 877 | + $zip->close(); | |
| 954 | 878 | |
| 879 | + $file_names = $this->find_temp_files( $temp_path ); | |
| 880 | + | |
| 881 | + foreach ( $file_names as $full_file_name ) { | |
| 882 | + $import_result = $this->import_single_template( $full_file_name ); | |
| 883 | + | |
| 884 | + unlink( $full_file_name ); | |
| 885 | + | |
| 955 | 886 | if ( is_wp_error( $import_result ) ) { |
| 956 | - // Skip failed files | |
| 957 | - continue; | |
| 887 | + return $import_result; | |
| 958 | 888 | } |
| 959 | 889 | |
| 960 | 890 | $items[] = $import_result; |
| 961 | 891 | } |
| 962 | 892 | |
| 963 | - // Delete the temporary extraction directory, since it's now not necessary. | |
| 964 | - Plugin::$instance->uploads_manager->remove_file_or_dir( $extracted_files['extraction_directory'] ); | |
| 893 | + rmdir( $temp_path ); | |
| 965 | 894 | } else { |
| 966 | - // If the import file is a single JSON file | |
| 967 | - $import_result = $this->import_single_template( $path, $import_mode ); | |
| 895 | + $import_result = $this->import_single_template( $path ); | |
| 968 | 896 | |
| 969 | 897 | if ( is_wp_error( $import_result ) ) { |
| 970 | 898 | return $import_result; |
| 971 | 899 | } |
| @@ -993,17 +921,9 @@ | ||
| 993 | 921 | */ |
| 994 | 922 | public function post_row_actions( $actions, \WP_Post $post ) { |
| 995 | 923 | if ( self::is_base_templates_screen() ) { |
| 996 | 924 | 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 ); | |
| 925 | + $actions['export-template'] = sprintf( '<a href="%1$s">%2$s</a>', $this->get_export_link( $post->ID ), __( 'Export Template', 'elementor' ) ); | |
| 1006 | 926 | } |
| 1007 | 927 | } |
| 1008 | 928 | |
| 1009 | 929 | return $actions; |
| @@ -1021,43 +941,26 @@ | ||
| 1021 | 941 | * @since 1.0.0 |
| 1022 | 942 | * @access public |
| 1023 | 943 | */ |
| 1024 | 944 | public function admin_import_template_form() { |
| 1025 | - if ( ! self::is_base_templates_screen() || ! User::is_current_user_can_upload_json() ) { | |
| 945 | + if ( ! self::is_base_templates_screen() ) { | |
| 1026 | 946 | return; |
| 1027 | 947 | } |
| 1028 | 948 | |
| 1029 | 949 | /** @var \Elementor\Core\Common\Modules\Ajax\Module $ajax */ |
| 1030 | 950 | $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 | 951 | ?> |
| 1049 | 952 | <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> | |
| 953 | + <a id="elementor-import-template-trigger" class="page-title-action"><?php echo __( 'Import Templates', 'elementor' ); ?></a> | |
| 1051 | 954 | <div id="elementor-import-template-area"> |
| 1052 | - <div id="elementor-import-template-title"><?php echo esc_html( $description ); ?></div> | |
| 1053 | - <form id="elementor-import-template-form" method="post" action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>" enctype="multipart/form-data"> | |
| 955 | + <div id="elementor-import-template-title"><?php echo __( '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> | |
| 956 | + <form id="elementor-import-template-form" method="post" action="<?php echo admin_url( 'admin-ajax.php' ); ?>" enctype="multipart/form-data"> | |
| 1054 | 957 | <input type="hidden" name="action" value="elementor_library_direct_actions"> |
| 1055 | 958 | <input type="hidden" name="library_action" value="direct_import_template"> |
| 1056 | - <input type="hidden" name="_nonce" value="<?php Utils::print_unescaped_internal_string( $ajax->create_nonce() ); ?>"> | |
| 959 | + <input type="hidden" name="_nonce" value="<?php echo $ajax->create_nonce(); ?>"> | |
| 1057 | 960 | <fieldset id="elementor-import-template-form-inputs"> |
| 1058 | 961 | <input type="file" name="file" accept=".json,application/json,.zip,application/octet-stream,application/zip,application/x-zip,application/x-zip-compressed" required> |
| 1059 | - <input id="e-import-template-action" type="submit" class="button" value="<?php echo esc_attr__( 'Import Now', 'elementor' ); ?>"> | |
| 962 | + <input type="submit" class="button" value="<?php echo esc_attr__( 'Import Now', 'elementor' ); ?>"> | |
| 1060 | 963 | </fieldset> |
| 1061 | 964 | </form> |
| 1062 | 965 | </div> |
| 1063 | 966 | </div> |
| @@ -1081,27 +984,12 @@ | ||
| 1081 | 984 | die; |
| 1082 | 985 | } |
| 1083 | 986 | } |
| 1084 | 987 | |
| 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 | 988 | /** |
| 1101 | 989 | * Is template library supports export. |
| 1102 | 990 | * |
| 1103 | - * Whether the template library supports export. | |
| 991 | + * whether the template library supports export. | |
| 1104 | 992 | * |
| 1105 | 993 | * Template saved by the user locally on his site, support export by default |
| 1106 | 994 | * but this can be changed using a filter. |
| 1107 | 995 | * |
| @@ -1248,9 +1136,9 @@ | ||
| 1248 | 1136 | * |
| 1249 | 1137 | * @return array An array of the available bulk actions. |
| 1250 | 1138 | */ |
| 1251 | 1139 | public function admin_add_bulk_export_action( $actions ) { |
| 1252 | - $actions[ self::BULK_EXPORT_ACTION ] = esc_html__( 'Export', 'elementor' ); | |
| 1140 | + $actions[ self::BULK_EXPORT_ACTION ] = __( 'Export', 'elementor' ); | |
| 1253 | 1141 | |
| 1254 | 1142 | return $actions; |
| 1255 | 1143 | } |
| 1256 | 1144 | |
| @@ -1272,10 +1160,9 @@ | ||
| 1272 | 1160 | if ( self::BULK_EXPORT_ACTION === $action ) { |
| 1273 | 1161 | $result = $this->export_multiple_templates( $post_ids ); |
| 1274 | 1162 | |
| 1275 | 1163 | // If you reach this line, the export failed |
| 1276 | - // PHPCS - Not user input. | |
| 1277 | - wp_die( $result->get_error_message() ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 1164 | + wp_die( $result->get_error_message() ); | |
| 1278 | 1165 | } |
| 1279 | 1166 | } |
| 1280 | 1167 | |
| 1281 | 1168 | /** |
| @@ -1292,13 +1179,17 @@ | ||
| 1292 | 1179 | * |
| 1293 | 1180 | * @return array An updated array of available list table views. |
| 1294 | 1181 | */ |
| 1295 | 1182 | public function admin_print_tabs( $views ) { |
| 1296 | - //phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce is not required to retrieve the value. | |
| 1297 | - $current_type = Utils::get_super_global_value( $_REQUEST, self::TAXONOMY_TYPE_SLUG ) ?? ''; | |
| 1298 | - $active_class = $current_type ? '' : ' nav-tab-active'; | |
| 1183 | + $current_type = ''; | |
| 1184 | + $active_class = ' nav-tab-active'; | |
| 1299 | 1185 | $current_tabs_group = $this->get_current_tab_group(); |
| 1300 | 1186 | |
| 1187 | + if ( ! empty( $_REQUEST[ self::TAXONOMY_TYPE_SLUG ] ) ) { | |
| 1188 | + $current_type = $_REQUEST[ self::TAXONOMY_TYPE_SLUG ]; | |
| 1189 | + $active_class = ''; | |
| 1190 | + } | |
| 1191 | + | |
| 1301 | 1192 | $url_args = [ |
| 1302 | 1193 | 'post_type' => self::CPT, |
| 1303 | 1194 | 'tabs_group' => $current_tabs_group, |
| 1304 | 1195 | ]; |
| @@ -1322,15 +1213,15 @@ | ||
| 1322 | 1213 | } |
| 1323 | 1214 | |
| 1324 | 1215 | ?> |
| 1325 | 1216 | <div id="elementor-template-library-tabs-wrapper" class="nav-tab-wrapper"> |
| 1326 | - <a class="nav-tab<?php echo esc_attr( $active_class ); ?>" href="<?php echo esc_url( $baseurl ); ?>"> | |
| 1217 | + <a class="nav-tab<?php echo $active_class; ?>" href="<?php echo $baseurl; ?>"> | |
| 1327 | 1218 | <?php |
| 1328 | 1219 | $all_title = $this->get_library_title(); |
| 1329 | 1220 | if ( ! $all_title ) { |
| 1330 | - $all_title = esc_html__( 'All', 'elementor' ); | |
| 1221 | + $all_title = __( 'All', 'elementor' ); | |
| 1331 | 1222 | } |
| 1332 | - Utils::print_unescaped_internal_string( $all_title ); ?> | |
| 1223 | + echo $all_title; ?> | |
| 1333 | 1224 | </a> |
| 1334 | 1225 | <?php |
| 1335 | 1226 | foreach ( $doc_types as $type => $class_name ) : |
| 1336 | 1227 | $active_class = ''; |
| @@ -1338,11 +1229,12 @@ | ||
| 1338 | 1229 | if ( $current_type === $type ) { |
| 1339 | 1230 | $active_class = ' nav-tab-active'; |
| 1340 | 1231 | } |
| 1341 | 1232 | |
| 1342 | - $type_url = esc_url( add_query_arg( self::TAXONOMY_TYPE_SLUG, $type, $baseurl ) ); | |
| 1233 | + $type_url = add_query_arg( self::TAXONOMY_TYPE_SLUG, $type, $baseurl ); | |
| 1343 | 1234 | $type_label = $this->get_template_label_by_type( $type ); |
| 1344 | - Utils::print_unescaped_internal_string( "<a class='nav-tab{$active_class}' href='{$type_url}'>{$type_label}</a>" ); | |
| 1235 | + | |
| 1236 | + echo "<a class='nav-tab{$active_class}' href='{$type_url}'>{$type_label}</a>"; | |
| 1345 | 1237 | endforeach; |
| 1346 | 1238 | ?> |
| 1347 | 1239 | </div> |
| 1348 | 1240 | <?php |
| @@ -1360,9 +1252,9 @@ | ||
| 1360 | 1252 | * @since 2.0.0 |
| 1361 | 1253 | * @access public |
| 1362 | 1254 | * |
| 1363 | 1255 | * @param string $which The location of the extra table nav markup: 'top' or 'bottom'. |
| 1364 | - * @param array $args | |
| 1256 | + * @param array $args | |
| 1365 | 1257 | */ |
| 1366 | 1258 | public function maybe_render_blank_state( $which, array $args = [] ) { |
| 1367 | 1259 | global $post_type; |
| 1368 | 1260 | |
| @@ -1378,9 +1270,8 @@ | ||
| 1378 | 1270 | global $wp_list_table; |
| 1379 | 1271 | |
| 1380 | 1272 | $total_items = $wp_list_table->get_pagination_arg( 'total_items' ); |
| 1381 | 1273 | |
| 1382 | - //phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce is not required to retrieve the value. | |
| 1383 | 1274 | if ( ! empty( $total_items ) || ! empty( $_REQUEST['s'] ) ) { |
| 1384 | 1275 | return; |
| 1385 | 1276 | } |
| 1386 | 1277 | |
| @@ -1400,9 +1291,9 @@ | ||
| 1400 | 1291 | // TODO: This code maybe unreachable see if above `if ( empty( $document_types[ $current_type ] ) )`. |
| 1401 | 1292 | if ( empty( $current_type ) ) { |
| 1402 | 1293 | $counts = (array) wp_count_posts( self::CPT ); |
| 1403 | 1294 | unset( $counts['auto-draft'] ); |
| 1404 | - $count = array_sum( $counts ); | |
| 1295 | + $count = array_sum( $counts ); | |
| 1405 | 1296 | |
| 1406 | 1297 | if ( 0 < $count ) { |
| 1407 | 1298 | return; |
| 1408 | 1299 | } |
| @@ -1416,28 +1307,18 @@ | ||
| 1416 | 1307 | } |
| 1417 | 1308 | |
| 1418 | 1309 | private function render_blank_state( $current_type, array $args = [] ) { |
| 1419 | 1310 | $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 | 1311 | $inline_style = '#posts-filter .wp-list-table, #posts-filter .tablenav.top, .tablenav.bottom .actions, .wrap .subsubsub { display:none;}'; |
| 1431 | 1312 | |
| 1432 | 1313 | $args = wp_parse_args( $args, [ |
| 1433 | 1314 | 'additional_inline_style' => '', |
| 1434 | 1315 | 'href' => '', |
| 1435 | - 'description' => $description, | |
| 1316 | + 'description' => __( 'Add templates and reuse them across your website. Easily export and import them to any other project, for an optimized workflow.', 'elementor' ), | |
| 1436 | 1317 | ] ); |
| 1437 | 1318 | $inline_style .= $args['additional_inline_style']; |
| 1438 | 1319 | ?> |
| 1439 | - <style type="text/css"><?php Utils::print_unescaped_internal_string( $inline_style ); ?></style> | |
| 1320 | + <style type="text/css"><?php echo $inline_style; ?></style> | |
| 1440 | 1321 | <div class="elementor-template_library-blank_state"> |
| 1441 | 1322 | <?php $this->print_blank_state_template( $current_type_label, $args['href'], $args['description'] ); ?> |
| 1442 | 1323 | </div> |
| 1443 | 1324 | <?php |
| @@ -1453,27 +1334,27 @@ | ||
| 1453 | 1334 | * |
| 1454 | 1335 | * @since 3.1.0 |
| 1455 | 1336 | * @access public |
| 1456 | 1337 | * |
| 1457 | - * @param string $current_type_label The Entity title. | |
| 1458 | - * @param string $href The URL for the 'Add New' button. | |
| 1459 | - * @param string $description The sub title describing the Entity (Post Type, Taxonomy, etc.). | |
| 1338 | + * @param string $current_type_label The Entity title | |
| 1339 | + * @param string $href The URL for the 'Add New' button | |
| 1340 | + * @param string $description The sub title describing the Entity (Post Type, Taxonomy, etc.) | |
| 1460 | 1341 | */ |
| 1461 | 1342 | public function print_blank_state_template( $current_type_label, $href, $description ) { |
| 1462 | 1343 | ?> |
| 1463 | 1344 | <div class="elementor-blank_state"> |
| 1464 | 1345 | <i class="eicon-folder"></i> |
| 1465 | - <h3> | |
| 1346 | + <h2> | |
| 1466 | 1347 | <?php |
| 1467 | 1348 | /* translators: %s: Template type label. */ |
| 1468 | - printf( esc_html__( 'Create Your First %s', 'elementor' ), esc_html( $current_type_label ) ); | |
| 1349 | + printf( __( 'Create Your First %s', 'elementor' ), $current_type_label ); | |
| 1469 | 1350 | ?> |
| 1470 | - </h3> | |
| 1471 | - <p><?php echo wp_kses_post( $description ); ?></p> | |
| 1472 | - <a id="elementor-template-library-add-new" class="elementor-button e-primary" href="<?php echo esc_url( $href ); ?>"> | |
| 1351 | + </h2> | |
| 1352 | + <p><?php echo $description; ?></p> | |
| 1353 | + <a id="elementor-template-library-add-new" class="elementor-button elementor-button-success" href="<?php echo $href; ?>"> | |
| 1473 | 1354 | <?php |
| 1474 | 1355 | /* translators: %s: Template type label. */ |
| 1475 | - printf( esc_html__( 'Add New %s', 'elementor' ), esc_html( $current_type_label ) ); | |
| 1356 | + printf( __( 'Add New %s', 'elementor' ), $current_type_label ); | |
| 1476 | 1357 | ?> |
| 1477 | 1358 | </a> |
| 1478 | 1359 | </div> |
| 1479 | 1360 | <?php |
| @@ -1478,17 +1359,8 @@ | ||
| 1478 | 1359 | </div> |
| 1479 | 1360 | <?php |
| 1480 | 1361 | } |
| 1481 | 1362 | |
| 1482 | - /** | |
| 1483 | - * Add filter by category. | |
| 1484 | - * | |
| 1485 | - * In the templates library, add a filter by Elementor library category. | |
| 1486 | - * | |
| 1487 | - * @access public | |
| 1488 | - * | |
| 1489 | - * @param string $post_type The post type slug. | |
| 1490 | - */ | |
| 1491 | 1363 | public function add_filter_by_category( $post_type ) { |
| 1492 | 1364 | if ( self::CPT !== $post_type ) { |
| 1493 | 1365 | return; |
| 1494 | 1366 | } |
| @@ -1493,9 +1365,10 @@ | ||
| 1493 | 1365 | return; |
| 1494 | 1366 | } |
| 1495 | 1367 | |
| 1496 | 1368 | $all_items = get_taxonomy( self::TAXONOMY_CATEGORY_SLUG )->labels->all_items; |
| 1497 | - $dropdown_options = [ | |
| 1369 | + | |
| 1370 | + $dropdown_options = array( | |
| 1498 | 1371 | 'show_option_all' => $all_items, |
| 1499 | 1372 | 'show_option_none' => $all_items, |
| 1500 | 1373 | 'hide_empty' => 0, |
| 1501 | 1374 | 'hierarchical' => 1, |
| @@ -1503,17 +1376,12 @@ | ||
| 1503 | 1376 | 'orderby' => 'name', |
| 1504 | 1377 | 'value_field' => 'slug', |
| 1505 | 1378 | 'taxonomy' => self::TAXONOMY_CATEGORY_SLUG, |
| 1506 | 1379 | 'name' => self::TAXONOMY_CATEGORY_SLUG, |
| 1507 | - //phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce is not required to retrieve the value. | |
| 1508 | - 'selected' => Utils::get_super_global_value( $_GET, self::TAXONOMY_CATEGORY_SLUG ) ?? '', | |
| 1509 | - ]; | |
| 1380 | + 'selected' => empty( $_GET[ self::TAXONOMY_CATEGORY_SLUG ] ) ? '' : $_GET[ self::TAXONOMY_CATEGORY_SLUG ], | |
| 1381 | + ); | |
| 1510 | 1382 | |
| 1511 | - printf( | |
| 1512 | - '<label class="screen-reader-text" for="%1$s">%2$s</label>', | |
| 1513 | - esc_attr( self::TAXONOMY_CATEGORY_SLUG ), | |
| 1514 | - esc_html_x( 'Filter by category', 'Template Library', 'elementor' ) | |
| 1515 | - ); | |
| 1383 | + echo '<label class="screen-reader-text" for="cat">' . _x( 'Filter by category', 'Template Library', 'elementor' ) . '</label>'; | |
| 1516 | 1384 | wp_dropdown_categories( $dropdown_options ); |
| 1517 | 1385 | } |
| 1518 | 1386 | |
| 1519 | 1387 | /** |
| @@ -1523,29 +1391,48 @@ | ||
| 1523 | 1391 | * |
| 1524 | 1392 | * @since 1.6.0 |
| 1525 | 1393 | * @access private |
| 1526 | 1394 | * |
| 1527 | - * @param string $file_path File name. | |
| 1395 | + * @param string $file_name File name. | |
| 1528 | 1396 | * |
| 1529 | 1397 | * @return \WP_Error|int|array Local template array, or template ID, or |
| 1530 | 1398 | * `WP_Error`. |
| 1531 | 1399 | */ |
| 1532 | - private function import_single_template( $file_path, $import_mode = 'match_site' ) { | |
| 1533 | - $data = $this->prepare_import_template_data( $file_path, $import_mode ); | |
| 1400 | + private function import_single_template( $file_name ) { | |
| 1401 | + $data = json_decode( file_get_contents( $file_name ), true ); | |
| 1534 | 1402 | |
| 1535 | - if ( is_wp_error( $data ) ) { | |
| 1536 | - return $data; | |
| 1403 | + if ( empty( $data ) ) { | |
| 1404 | + return new \WP_Error( 'file_error', 'Invalid File' ); | |
| 1537 | 1405 | } |
| 1538 | 1406 | |
| 1539 | - if ( empty( $data ) ) { | |
| 1540 | - return new \WP_Error( 'file_error', 'Invalid File' ); | |
| 1407 | + $content = $data['content']; | |
| 1408 | + | |
| 1409 | + if ( ! is_array( $content ) ) { | |
| 1410 | + return new \WP_Error( 'file_error', 'Invalid Content In File' ); | |
| 1541 | 1411 | } |
| 1542 | 1412 | |
| 1413 | + $content = $this->process_export_import_content( $content, 'on_import' ); | |
| 1414 | + | |
| 1415 | + $page_settings = []; | |
| 1416 | + | |
| 1417 | + if ( ! empty( $data['page_settings'] ) ) { | |
| 1418 | + $page = new Model( [ | |
| 1419 | + 'id' => 0, | |
| 1420 | + 'settings' => $data['page_settings'], | |
| 1421 | + ] ); | |
| 1422 | + | |
| 1423 | + $page_settings_data = $this->process_element_export_import_content( $page, 'on_import' ); | |
| 1424 | + | |
| 1425 | + if ( ! empty( $page_settings_data['settings'] ) ) { | |
| 1426 | + $page_settings = $page_settings_data['settings']; | |
| 1427 | + } | |
| 1428 | + } | |
| 1429 | + | |
| 1543 | 1430 | $template_id = $this->save_item( [ |
| 1544 | - 'content' => $data['content'], | |
| 1431 | + 'content' => $content, | |
| 1545 | 1432 | 'title' => $data['title'], |
| 1546 | 1433 | 'type' => $data['type'], |
| 1547 | - 'page_settings' => $data['page_settings'], | |
| 1434 | + 'page_settings' => $page_settings, | |
| 1548 | 1435 | ] ); |
| 1549 | 1436 | |
| 1550 | 1437 | if ( is_wp_error( $template_id ) ) { |
| 1551 | 1438 | return $template_id; |
| @@ -1574,23 +1461,16 @@ | ||
| 1574 | 1461 | if ( empty( $template_data['content'] ) ) { |
| 1575 | 1462 | return new \WP_Error( 'empty_template', 'The template is empty' ); |
| 1576 | 1463 | } |
| 1577 | 1464 | |
| 1578 | - $content = apply_filters( | |
| 1579 | - 'elementor/template_library/sources/local/export/elements', | |
| 1580 | - $template_data['content'] | |
| 1581 | - ); | |
| 1582 | - | |
| 1583 | 1465 | $export_data = [ |
| 1584 | - 'content' => $content, | |
| 1466 | + 'content' => $template_data['content'], | |
| 1585 | 1467 | 'page_settings' => $template_data['settings'], |
| 1586 | 1468 | 'version' => DB::DB_VERSION, |
| 1587 | - 'title' => $document->get_main_post()->post_title, | |
| 1469 | + 'title' => get_the_title( $template_id ), | |
| 1588 | 1470 | 'type' => self::get_template_type( $template_id ), |
| 1589 | 1471 | ]; |
| 1590 | 1472 | |
| 1591 | - $this->attach_global_styles_to_data( $export_data, $content, $template_id ); | |
| 1592 | - | |
| 1593 | 1473 | return [ |
| 1594 | 1474 | 'name' => 'elementor-' . $template_id . '-' . gmdate( 'Y-m-d' ) . '.json', |
| 1595 | 1475 | 'content' => wp_json_encode( $export_data ), |
| 1596 | 1476 | ]; |
| @@ -1596,8 +1476,28 @@ | ||
| 1596 | 1476 | ]; |
| 1597 | 1477 | } |
| 1598 | 1478 | |
| 1599 | 1479 | /** |
| 1480 | + * Send file headers. | |
| 1481 | + * | |
| 1482 | + * Set the file header when export template data to a file. | |
| 1483 | + * | |
| 1484 | + * @since 1.6.0 | |
| 1485 | + * @access private | |
| 1486 | + * | |
| 1487 | + * @param string $file_name File name. | |
| 1488 | + * @param int $file_size File size. | |
| 1489 | + */ | |
| 1490 | + private function send_file_headers( $file_name, $file_size ) { | |
| 1491 | + header( 'Content-Type: application/octet-stream' ); | |
| 1492 | + header( 'Content-Disposition: attachment; filename=' . $file_name ); | |
| 1493 | + header( 'Expires: 0' ); | |
| 1494 | + header( 'Cache-Control: must-revalidate' ); | |
| 1495 | + header( 'Pragma: public' ); | |
| 1496 | + header( 'Content-Length: ' . $file_size ); | |
| 1497 | + } | |
| 1498 | + | |
| 1499 | + /** | |
| 1600 | 1500 | * Get template label by type. |
| 1601 | 1501 | * |
| 1602 | 1502 | * Retrieve the template label for any given template type. |
| 1603 | 1503 | * |
| @@ -1631,68 +1531,8 @@ | ||
| 1631 | 1531 | |
| 1632 | 1532 | return $template_label; |
| 1633 | 1533 | } |
| 1634 | 1534 | |
| 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 | 1535 | /** |
| 1696 | 1536 | * Filter template types in admin query. |
| 1697 | 1537 | * |
| 1698 | 1538 | * Update the template types in the main admin query. |
| @@ -1736,32 +1576,10 @@ | ||
| 1736 | 1576 | * @access private |
| 1737 | 1577 | */ |
| 1738 | 1578 | private function add_actions() { |
| 1739 | 1579 | if ( is_admin() ) { |
| 1740 | - add_action( 'admin_init', [ $this, 'redirect_categories_page_to_saved_templates_page' ] ); | |
| 1741 | - | |
| 1742 | - add_action( 'elementor/editor-one/menu/register', function ( Menu_Data_Provider $menu_data_provider ) { | |
| 1743 | - $this->register_editor_one_menu( $menu_data_provider ); | |
| 1744 | - } ); | |
| 1745 | - | |
| 1746 | - add_action( 'elementor/editor-one/menu/excluded_level4_slugs', function ( array $excluded_slugs ): array { | |
| 1747 | - $excluded_slugs[] = 'edit.php?post_type=elementor_library#add_new'; | |
| 1748 | - $excluded_slugs[] = 'edit-tags.php?taxonomy=elementor_library_category&post_type=elementor_library'; | |
| 1749 | - return $excluded_slugs; | |
| 1750 | - } ); | |
| 1751 | - | |
| 1752 | - add_filter( 'elementor/editor-one/menu/elementor_post_types', function ( array $elementor_post_types ): array { | |
| 1753 | - $elementor_post_types[ self::CPT ] = []; | |
| 1754 | - | |
| 1755 | - return $elementor_post_types; | |
| 1756 | - } ); | |
| 1757 | - | |
| 1758 | - add_filter( 'elementor/editor-one/admin-edit-post-types', function ( array $post_types ): array { | |
| 1759 | - $post_types[] = self::CPT; | |
| 1760 | - | |
| 1761 | - return $post_types; | |
| 1762 | - } ); | |
| 1763 | - | |
| 1580 | + add_action( 'admin_menu', [ $this, 'admin_menu' ] ); | |
| 1581 | + add_action( 'admin_menu', [ $this, 'admin_menu_reorder' ], 800 ); | |
| 1764 | 1582 | add_filter( 'admin_title', [ $this, 'admin_title' ], 10, 2 ); |
| 1765 | 1583 | add_action( 'all_admin_notices', [ $this, 'replace_admin_heading' ] ); |
| 1766 | 1584 | add_filter( 'post_row_actions', [ $this, 'post_row_actions' ], 10, 2 ); |
| 1767 | 1585 | add_action( 'admin_footer', [ $this, 'admin_import_template_form' ] ); |
| @@ -1787,30 +1605,11 @@ | ||
| 1787 | 1605 | // Show blank state. |
| 1788 | 1606 | add_action( 'manage_posts_extra_tablenav', [ $this, 'maybe_render_blank_state' ] ); |
| 1789 | 1607 | } |
| 1790 | 1608 | |
| 1791 | - add_action( 'elementor/document/after_save', [ $this, 'on_template_update' ], 10, 2 ); | |
| 1792 | - | |
| 1793 | 1609 | add_action( 'template_redirect', [ $this, 'block_template_frontend' ] ); |
| 1794 | - | |
| 1795 | - // Remove elementor library templates from WP Sitemap | |
| 1796 | - add_filter( | |
| 1797 | - 'wp_sitemaps_post_types', | |
| 1798 | - function( $post_types ) { | |
| 1799 | - return $this->remove_elementor_cpt_from_sitemap( $post_types ); | |
| 1800 | - } | |
| 1801 | - ); | |
| 1802 | 1610 | } |
| 1803 | 1611 | |
| 1804 | - public function on_template_update( \Elementor\Core\Base\Document $document, array $data ) { | |
| 1805 | - if ( ! empty( $data['post_title'] ) ) { | |
| 1806 | - wp_update_post( [ | |
| 1807 | - 'ID' => $document->get_main_id(), | |
| 1808 | - 'post_title' => $data['post_title'], | |
| 1809 | - ] ); | |
| 1810 | - } | |
| 1811 | - } | |
| 1812 | - | |
| 1813 | 1612 | /** |
| 1814 | 1613 | * @since 2.0.6 |
| 1815 | 1614 | * @access public |
| 1816 | 1615 | */ |
| @@ -1835,24 +1634,26 @@ | ||
| 1835 | 1634 | |
| 1836 | 1635 | $offset = 2; |
| 1837 | 1636 | |
| 1838 | 1637 | $posts_columns = array_slice( $posts_columns, 0, $offset, true ) + [ |
| 1839 | - 'elementor_library_type' => esc_html__( 'Type', 'elementor' ), | |
| 1638 | + 'elementor_library_type' => __( 'Type', 'elementor' ), | |
| 1840 | 1639 | ] + array_slice( $posts_columns, $offset, null, true ); |
| 1841 | 1640 | |
| 1842 | 1641 | return $posts_columns; |
| 1843 | 1642 | } |
| 1844 | 1643 | |
| 1845 | - 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 ); | |
| 1644 | + public function get_current_tab_group( $default = '' ) { | |
| 1645 | + $current_tabs_group = $default; | |
| 1848 | 1646 | |
| 1849 | - if ( $type_slug ) { | |
| 1850 | - $doc_type = Plugin::$instance->documents->get_document_type( $type_slug, '' ); | |
| 1647 | + if ( ! empty( $_REQUEST[ self::TAXONOMY_TYPE_SLUG ] ) ) { | |
| 1648 | + $doc_type = Plugin::$instance->documents->get_document_type( $_REQUEST[ self::TAXONOMY_TYPE_SLUG ], '' ); | |
| 1851 | 1649 | if ( $doc_type ) { |
| 1852 | 1650 | $current_tabs_group = $doc_type::get_property( 'admin_tab_group' ); |
| 1853 | 1651 | } |
| 1652 | + } elseif ( ! empty( $_REQUEST['tabs_group'] ) ) { | |
| 1653 | + $current_tabs_group = $_REQUEST['tabs_group']; | |
| 1854 | 1654 | } |
| 1655 | + | |
| 1855 | 1656 | return $current_tabs_group; |
| 1856 | 1657 | } |
| 1857 | 1658 | |
| 1858 | 1659 | private function get_library_title() { |
| @@ -1862,11 +1663,11 @@ | ||
| 1862 | 1663 | $current_tab_group = $this->get_current_tab_group(); |
| 1863 | 1664 | |
| 1864 | 1665 | if ( $current_tab_group ) { |
| 1865 | 1666 | $titles = [ |
| 1866 | - 'library' => esc_html__( 'Saved Templates', 'elementor' ), | |
| 1867 | - 'theme' => esc_html__( 'Theme Builder', 'elementor' ), | |
| 1868 | - 'popup' => esc_html__( 'Popups', 'elementor' ), | |
| 1667 | + 'library' => __( 'Saved Templates', 'elementor' ), | |
| 1668 | + 'theme' => __( 'Theme Builder', 'elementor' ), | |
| 1669 | + 'popup' => __( 'Popups', 'elementor' ), | |
| 1869 | 1670 | ]; |
| 1870 | 1671 | |
| 1871 | 1672 | if ( ! empty( $titles[ $current_tab_group ] ) ) { |
| 1872 | 1673 | $title = $titles[ $current_tab_group ]; |
| @@ -1883,46 +1684,8 @@ | ||
| 1883 | 1684 | return 'edit.php' === $pagenow && self::CPT === $typenow; |
| 1884 | 1685 | } |
| 1885 | 1686 | |
| 1886 | 1687 | /** |
| 1887 | - * @param array $post_types | |
| 1888 | - * | |
| 1889 | - * @return array | |
| 1890 | - */ | |
| 1891 | - private function remove_elementor_cpt_from_sitemap( array $post_types ) { | |
| 1892 | - unset( $post_types[ self::CPT ] ); | |
| 1893 | - | |
| 1894 | - return $post_types; | |
| 1895 | - } | |
| 1896 | - | |
| 1897 | - private function avoid_rest_access_for_non_admins(): void { | |
| 1898 | - add_filter( 'rest_pre_dispatch', function ( $value, \WP_REST_Server $server, \WP_REST_Request $request ) { | |
| 1899 | - if ( strpos( $request->get_route(), self::CPT ) !== false ) { | |
| 1900 | - if ( ! current_user_can( 'manage_options' ) ) { | |
| 1901 | - return new \WP_Error( 'rest_forbidden', esc_html__( 'Sorry, you are not allowed to do that.', 'elementor' ), [ 'status' => rest_authorization_required_code() ] ); | |
| 1902 | - } | |
| 1903 | - } | |
| 1904 | - | |
| 1905 | - return $value; | |
| 1906 | - }, 10, 3 ); | |
| 1907 | - } | |
| 1908 | - | |
| 1909 | - public function save_bulk_items( array $args = [] ) { | |
| 1910 | - $items = []; | |
| 1911 | - | |
| 1912 | - foreach ( $args as $item ) { | |
| 1913 | - $items[] = $this->save_item( [ | |
| 1914 | - 'content' => $item['content'], | |
| 1915 | - 'title' => $item['title'], | |
| 1916 | - 'type' => $item['type'], | |
| 1917 | - 'page_settings' => $item['page_settings'], | |
| 1918 | - ] ); | |
| 1919 | - } | |
| 1920 | - | |
| 1921 | - return $items; | |
| 1922 | - } | |
| 1923 | - | |
| 1924 | - /** | |
| 1925 | 1688 | * Template library local source constructor. |
| 1926 | 1689 | * |
| 1927 | 1690 | * Initializing the template library local source base by registering custom |
| 1928 | 1691 | * template data and running custom actions. |
| @@ -1933,87 +1696,6 @@ | ||
| 1933 | 1696 | public function __construct() { |
| 1934 | 1697 | parent::__construct(); |
| 1935 | 1698 | |
| 1936 | 1699 | $this->add_actions(); |
| 1937 | - } | |
| 1938 | - | |
| 1939 | - public function format_args_for_bulk_action( $args ) { | |
| 1940 | - $bulk_args = []; | |
| 1941 | - | |
| 1942 | - foreach ( $args['from_template_id'] as $from_template_id ) { | |
| 1943 | - if ( ! $this->is_allowed_to_read_template( [ | |
| 1944 | - 'template_id' => $from_template_id, | |
| 1945 | - ] ) ) { | |
| 1946 | - continue; | |
| 1947 | - } | |
| 1948 | - | |
| 1949 | - $document = Plugin::$instance->documents->get( $from_template_id ); | |
| 1950 | - | |
| 1951 | - if ( ! $document ) { | |
| 1952 | - continue; | |
| 1953 | - } | |
| 1954 | - | |
| 1955 | - $page = SettingsManager::get_settings_managers( 'page' )->get_model( $from_template_id ); | |
| 1956 | - | |
| 1957 | - $bulk_args[] = array_merge( | |
| 1958 | - $args, | |
| 1959 | - [ | |
| 1960 | - 'title' => $document->get_post()->post_title, | |
| 1961 | - 'type' => $document::get_type(), | |
| 1962 | - 'content' => $document->get_elements_data(), | |
| 1963 | - 'page_settings' => $page->get_data( 'settings' ), | |
| 1964 | - ] | |
| 1965 | - ); | |
| 1966 | - } | |
| 1967 | - | |
| 1968 | - return $bulk_args; | |
| 1969 | - } | |
| 1970 | - | |
| 1971 | - public function format_args_for_single_action( $args ) { | |
| 1972 | - if ( ! $this->is_allowed_to_read_template( [ | |
| 1973 | - 'template_id' => $args['from_template_id'], | |
| 1974 | - ] ) ) { | |
| 1975 | - return new \WP_Error( | |
| 1976 | - 'template_error', | |
| 1977 | - esc_html__( 'You do not have permission to access this template.', 'elementor' ) | |
| 1978 | - ); | |
| 1979 | - } | |
| 1980 | - | |
| 1981 | - $document = Plugin::$instance->documents->get( $args['from_template_id'] ); | |
| 1982 | - | |
| 1983 | - if ( ! $document ) { | |
| 1984 | - return new \WP_Error( 'template_error', 'Document not found.' ); | |
| 1985 | - } | |
| 1986 | - | |
| 1987 | - $args['content'] = $document->get_elements_data(); | |
| 1988 | - | |
| 1989 | - $page = SettingsManager::get_settings_managers( 'page' )->get_model( $args['from_template_id'] ); | |
| 1990 | - $args['page_settings'] = $page->get_data( 'settings' ); | |
| 1991 | - | |
| 1992 | - return $args; | |
| 1993 | - } | |
| 1994 | - | |
| 1995 | - public function is_allowed_to_read_template( array $args ): bool { | |
| 1996 | - if ( null === $this->wordpress_adapter ) { | |
| 1997 | - $this->set_wordpress_adapter( new WordPress_Adapter() ); | |
| 1998 | - } | |
| 1999 | - | |
| 2000 | - $post_id = intval( $args['template_id'] ); | |
| 2001 | - $post_status = $this->wordpress_adapter->get_post_status( $post_id ); | |
| 2002 | - | |
| 2003 | - if ( 'publish' === $post_status && ! post_password_required( $post_id ) ) { | |
| 2004 | - return true; | |
| 2005 | - } | |
| 2006 | - | |
| 2007 | - $can_read_template = $this->wordpress_adapter->current_user_can( 'edit_post', $post_id ); | |
| 2008 | - | |
| 2009 | - return apply_filters( 'elementor/template-library/is_allowed_to_read_template', $can_read_template, $args ); | |
| 2010 | - } | |
| 2011 | - | |
| 2012 | - public function set_wordpress_adapter( Wordpress_Adapter_Interface $wordpress_adapter ) { | |
| 2013 | - $this->wordpress_adapter = $wordpress_adapter; | |
| 2014 | - } | |
| 2015 | - | |
| 2016 | - public function set_elementor_adapter( Elementor_Adapter_Interface $elementor_adapter ): void { | |
| 2017 | - $this->elementor_adapter = $elementor_adapter; | |
| 2018 | 1700 | } |
| 2019 | 1701 | } |