PluginProbe
Vimeography: Vimeo Video Gallery WordPress Plugin / 2.4.8
Vimeography: Vimeo Video Gallery WordPress Plugin v2.4.8
2.4.9 2.4.8 trunk 0.5.1 0.5.2 0.5.3 0.5.4 0.5.5 0.5.6 0.5.7 0.6 0.6.1 0.6.2 0.6.3 0.6.4 0.6.5 0.6.6 0.6.7 0.6.8 0.6.8.1 0.6.9 0.6.9.1 0.6.9.2 0.7 0.8 All 103 releases
vimeography / lib / api / themes.php

themes.php in Vimeography: Vimeo Video Gallery WordPress Plugin 2.4.8, at lib/api/themes.php

162 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Vimeography\Api;
3
4 class Themes extends \WP_REST_Controller
5 {
6 public function __construct()
7 {
8 add_action('rest_api_init', function () {
9 $this->register_routes();
10 });
11 }
12 /**
13 * Register the routes for the objects of the controller.
14 */
15 public function register_routes()
16 {
17 $version = '1';
18 $namespace = 'vimeography/v' . $version;
19 $base = 'themes';
20 register_rest_route($namespace, '/' . $base, array(
21 array(
22 'methods' => \WP_REST_Server::READABLE,
23 'callback' => array($this, 'get_items'),
24 'permission_callback' => array($this, 'get_items_permissions_check'),
25 'args' => array()
26 )
27 ));
28
29 register_rest_route($namespace, '/' . $base . '/schema', array(
30 'methods' => \WP_REST_Server::READABLE,
31 'callback' => array($this, 'get_public_item_schema'),
32 'permission_callback' => '__return_true'
33 ));
34 }
35
36 /**
37 * Get a collection of items
38 *
39 * @param WP_REST_Request $request Full data about the request.
40 * @return WP_Error|WP_REST_Response
41 */
42 public function get_items($request)
43 {
44 $themes = \Vimeography::get_instance()->addons->themes;
45 $activated_themes = get_option('vimeography_activation_keys');
46
47 $items = array();
48 foreach ($themes as $theme) {
49 if (is_array($activated_themes)) {
50 foreach ($activated_themes as $activation) {
51 if (
52 strtolower($activation->plugin_name) == strtolower($theme['slug'])
53 ) {
54 $theme['is_licensed'] = true;
55 } else {
56 $theme['is_licensed'] = false;
57 }
58 }
59 } else {
60 $theme['is_licensed'] = false;
61 }
62
63 $theme["settings"] = array();
64
65 if (file_exists($theme['settings_file'])) {
66 $this->theme_supports_settings = true;
67 include $theme['settings_file'];
68
69 /* $settings is defined in the theme settings file */
70 $theme["settings"] = $settings;
71 }
72
73 $out = array(
74 "name" => $theme['name'],
75 "description" => $theme['description'],
76 "version" => $theme['version'],
77 "thumbnail" => $theme['thumbnail'],
78 "is_licensed" => $theme['is_licensed'],
79 "settings" => $theme["settings"]
80 );
81
82 $items[] = $out;
83 }
84
85 return $items;
86 }
87
88 /**
89 * Check if a given request has access to get items
90 *
91 * @param WP_REST_Request $request Full data about the request.
92 * @return WP_Error|bool
93 */
94 public function get_items_permissions_check($request)
95 {
96 return true;
97 }
98
99 /**
100 * Check if a given request has access to get a specific item
101 *
102 * @param WP_REST_Request $request Full data about the request.
103 * @return WP_Error|bool
104 */
105 public function get_item_permissions_check($request)
106 {
107 return $this->get_items_permissions_check($request);
108 }
109
110 /**
111 * Prepare the item for create or update operation
112 *
113 * @param WP_REST_Request $request Request object
114 * @return WP_Error|object $prepared_item
115 */
116 protected function prepare_item_for_database($request)
117 {
118 return array();
119 }
120
121 /**
122 * Prepare the item for the REST response
123 *
124 * @param mixed $item WordPress representation of the item.
125 * @param WP_REST_Request $request Request object.
126 * @return mixed
127 */
128 public function prepare_item_for_response($item, $request)
129 {
130 return array();
131 }
132
133 /**
134 * Get the query params for collections
135 *
136 * @return array
137 */
138 public function get_collection_params()
139 {
140 return array(
141 'page' => array(
142 'description' => 'Current page of the collection.',
143 'type' => 'integer',
144 'default' => 1,
145 'sanitize_callback' => 'absint'
146 ),
147 'per_page' => array(
148 'description' =>
149 'Maximum number of items to be returned in result set.',
150 'type' => 'integer',
151 'default' => 10,
152 'sanitize_callback' => 'absint'
153 ),
154 'search' => array(
155 'description' => 'Limit results to those matching a string.',
156 'type' => 'string',
157 'sanitize_callback' => 'sanitize_text_field'
158 )
159 );
160 }
161 }
162