PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.7.5
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.7.5
3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.10 All 111 releases
templately / includes / API / TemplateTypes.php

TemplateTypes.php in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! 3.7.5, at includes/API/TemplateTypes.php

79 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Templately\API;
3
4 use Templately\Utils\Database;
5 use WP_REST_Request;
6
7 /**
8 * TemplateTypes Class
9 *
10 * @since 2.0.0
11 * @package Templately\API
12 */
13 class TemplateTypes extends API {
14 private $endpoint = 'templateTypes';
15 private array $_items = [];
16
17 public function permission_check( WP_REST_Request $request ) {
18 $this->request = $request;
19 return true;
20 }
21
22 public function register_routes() {
23 $this->get( $this->endpoint, [ $this, 'get_types' ] );
24 }
25
26 public function get_types() {
27 /**
28 * Return if there is any cache data.
29 */
30 $_type = $this->get_param( 'itemType', 'page' );
31 $_type = rtrim( $_type, 's');
32
33 $types = Database::get_transient( $this->endpoint );
34 if( ! empty( $types ) && ! empty( $types[ $_type ] ) ){
35 return $this->success( $types[ $_type ] );
36 }
37
38 $id = $this->get_param( 'id', 0, 'intval' );
39 $funcArgs = [];
40
41 if ( $id > 0 ) {
42 $funcArgs['id'] = $id;
43 }
44
45 $query_params = 'item_template_types{id, name, slug}, page_template_types{id, name, slug}, pack_template_types{id, name, slug}';
46 $response = $this->http()->query( 'groupedTemplateTypes', $query_params, $funcArgs )->post();
47 /**
48 * Caching the response in transient.
49 */
50 if( ! is_wp_error( $response ) ) {
51 $this->_items = [
52 'block' => [],
53 'page' => [],
54 'pack' => [],
55 ];
56 if( is_array( $response ) ) {
57 array_walk( $response, function( $_item, $key ) {
58 switch( $key ) {
59 case 'item_template_types':
60 $this->_items['block'] = $_item;
61 break;
62 case 'page_template_types':
63 $this->_items['page'] = $_item;
64 break;
65 case 'pack_template_types':
66 $this->_items['pack'] = $_item;
67 break;
68 }
69 } );
70
71 Database::set_transient( $this->endpoint, $this->_items );
72 }
73
74 return $this->_items[ $_type ];
75 }
76
77 return $response;
78 }
79 }