PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.2.0
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.2.0
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.2.0, at includes/API/TemplateTypes.php

80 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 * @property mixed $_items
11 *
12 * @since 2.0.0
13 * @package Templately\API
14 */
15 class TemplateTypes extends API {
16 private $endpoint = 'templateTypes';
17
18 public function permission_check( WP_REST_Request $request ) {
19 $this->request = $request;
20 return true;
21 }
22
23 public function register_routes() {
24 $this->get( $this->endpoint, [ $this, 'get_types' ] );
25 }
26
27 public function get_types() {
28 /**
29 * Return if there is any cache data.
30 */
31 $_type = $this->get_param( 'itemType', 'page' );
32 $_type = rtrim( $_type, 's');
33
34 $types = Database::get_transient( $this->endpoint );
35 if( ! empty( $types ) && ! empty( $types[ $_type ] ) ){
36 return $this->success( $types[ $_type ] );
37 }
38
39 $id = $this->get_param( 'id', 0, 'intval' );
40 $funcArgs = [];
41
42 if ( $id > 0 ) {
43 $funcArgs['id'] = $id;
44 }
45
46 $query_params = 'item_template_types{id, name, slug}, page_template_types{id, name, slug}, pack_template_types{id, name, slug}';
47 $response = $this->http()->query( 'groupedTemplateTypes', $query_params, $funcArgs )->post();
48 /**
49 * Caching the response in transient.
50 */
51 if( ! is_wp_error( $response ) ) {
52 $this->_items = [
53 'block' => [],
54 'page' => [],
55 'pack' => [],
56 ];
57 if( is_array( $response ) ) {
58 array_walk( $response, function( $_item, $key ) {
59 switch( $key ) {
60 case 'item_template_types':
61 $this->_items['block'] = $_item;
62 break;
63 case 'page_template_types':
64 $this->_items['page'] = $_item;
65 break;
66 case 'pack_template_types':
67 $this->_items['pack'] = $_item;
68 break;
69 }
70 } );
71
72 Database::set_transient( $this->endpoint, $this->_items );
73 }
74
75 return $this->_items[ $_type ];
76 }
77
78 return $response;
79 }
80 }