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

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