← All changes
|
includes/template-library/data/endpoints/templates.php
+1
-69
4.3.0-beta3
→
3.6.3
View file →
| @@ -2,9 +2,8 @@ | ||
| 2 | 2 | namespace Elementor\Includes\TemplateLibrary\Data\Endpoints; |
| 3 | 3 | |
| 4 | 4 | use Elementor\Data\V2\Base\Endpoint; |
| 5 | 5 | use Elementor\Plugin; |
| 6 | -use Elementor\TemplateLibrary\Source_Local; | |
| 7 | 6 | |
| 8 | 7 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | 8 | exit; // Exit if accessed directly. |
| 10 | 9 | } |
| @@ -9,37 +8,8 @@ | ||
| 9 | 8 | exit; // Exit if accessed directly. |
| 10 | 9 | } |
| 11 | 10 | |
| 12 | 11 | class Templates extends Endpoint { |
| 13 | - | |
| 14 | - protected function register() { | |
| 15 | - parent::register(); | |
| 16 | - | |
| 17 | - $document_types = Plugin::$instance->documents->get_document_types( [ | |
| 18 | - 'show_in_library' => true, | |
| 19 | - ] ); | |
| 20 | - | |
| 21 | - $this->register_route( '', \WP_REST_Server::CREATABLE, [ | |
| 22 | - 'is_multi' => true, | |
| 23 | - 'title' => [ | |
| 24 | - 'required' => false, | |
| 25 | - 'type' => 'string', | |
| 26 | - 'description' => 'The title of the document', | |
| 27 | - ], | |
| 28 | - 'type' => [ | |
| 29 | - 'required' => true, | |
| 30 | - 'description' => 'The document type.', | |
| 31 | - 'type' => 'string', | |
| 32 | - 'enum' => array_keys( $document_types ), | |
| 33 | - ], | |
| 34 | - 'content' => [ | |
| 35 | - 'required' => false, | |
| 36 | - 'description' => 'Elementor data object', | |
| 37 | - 'type' => 'object', | |
| 38 | - ], | |
| 39 | - ] ); | |
| 40 | - } | |
| 41 | - | |
| 42 | 12 | public function get_name() { |
| 43 | 13 | return 'templates'; |
| 44 | 14 | } |
| 45 | 15 | |
| @@ -47,45 +17,7 @@ | ||
| 47 | 17 | return 'template-library/templates'; |
| 48 | 18 | } |
| 49 | 19 | |
| 50 | 20 | public function get_items( $request ) { |
| 51 | - return $this->reorder_categories( Plugin::$instance->templates_manager->get_library_data( [ 'filter_sources' => [ $request->get_param( 'source' ) ] ] ) ); | |
| 52 | - } | |
| 53 | - | |
| 54 | - /** | |
| 55 | - * Move the '404 page' category to the end of the list | |
| 56 | - * | |
| 57 | - * @param array $library_data | |
| 58 | - * @return array | |
| 59 | - */ | |
| 60 | - private function reorder_categories( array $library_data ): array { | |
| 61 | - $not_found_category = '404 page'; | |
| 62 | - | |
| 63 | - $key = array_search( $not_found_category, $library_data['config']['block']['categories'] ); | |
| 64 | - if ( false === $key ) { | |
| 65 | - return $library_data; | |
| 66 | - } | |
| 67 | - | |
| 68 | - array_splice( $library_data['config']['block']['categories'], $key, 1 ); | |
| 69 | - $library_data['config']['block']['categories'][] = $not_found_category; | |
| 70 | - | |
| 71 | - return $library_data; | |
| 72 | - } | |
| 73 | - | |
| 74 | - public function create_items( $request ) { | |
| 75 | - /** @var Source_Local $source */ | |
| 76 | - $source = Plugin::$instance->templates_manager->get_source( 'local' ); | |
| 77 | - | |
| 78 | - $result = $source->save_item( [ | |
| 79 | - 'title' => $request->get_param( 'title' ), | |
| 80 | - 'type' => $request->get_param( 'type' ), | |
| 81 | - 'content' => $request->get_param( 'content' ), | |
| 82 | - 'page_settings' => $request->get_param( 'page_settings' ), | |
| 83 | - ] ); | |
| 84 | - | |
| 85 | - if ( is_wp_error( $result ) ) { | |
| 86 | - return $result; | |
| 87 | - } | |
| 88 | - | |
| 89 | - return $source->get_item( $result ); | |
| 21 | + return Plugin::$instance->templates_manager->get_library_data( [ 'filter_sources' => [ $request->get_param( 'source' ) ] ] ); | |
| 90 | 22 | } |
| 91 | 23 | } |