PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / trunk
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! vtrunk
3.8.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 All 112 releases
templately / modules / template-browsing / REST / Categories.php

Categories.php in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! trunk, at modules/template-browsing/REST/Categories.php

51 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Templately\Modules\TemplateBrowsing\REST;
3
4 use Templately\API\API;
5
6 use Templately\Utils\Database;
7 use WP_REST_Request;
8
9 class Categories extends API {
10 private $endpoint = 'categories';
11
12 public function permission_check( WP_REST_Request $request ) {
13 $this->request = $request;
14 return true;
15 }
16
17 public function register_routes() {
18 $this->get( $this->endpoint, [ $this, 'get_categories' ] );
19 }
20
21 public function get_categories() {
22 /** @noinspection SpellCheckingInspection */
23 $id = $this->get_param( 'id', 0, 'intval' );
24 $funcArgs = [];
25
26 if ( $id > 0 ) {
27 $funcArgs['id'] = $id;
28 }
29
30 $fields = 'id, name, slug, status, packs_count';
31 $transient_key = $this->endpoint . '_' . md5( $fields . json_encode( $funcArgs ) );
32
33 /**
34 * Return if there is any cache data.
35 */
36 $types = Database::get_transient( $transient_key );
37 if( ! empty( $types ) ){
38 return $this->success( $types );
39 }
40
41 $response = $this->http()->query( $this->endpoint, $fields, $funcArgs )->post();
42 /**
43 * Caching the response in transient.
44 */
45 if( ! is_wp_error( $response ) ) {
46 Database::set_transient( $transient_key, $response );
47 }
48
49 return $response;
50 }
51 }