PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.2.7
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.2.7
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
← All changes | includes/API/Dependencies.php +43 -216 3.7.53.2.7 View file →
@@ -6,9 +6,8 @@
6 6 use Templately\Utils\Helper;
7 7 use Templately\Utils\Database;
8 8 use Templately\Utils\Installer;
9 9 use WP_REST_Request;
10 -use Templately\Utils\Caching;
11 10
12 11 use function current_user_can;
13 12
14 13
@@ -14,9 +13,8 @@
14 13
15 14 class Dependencies extends API {
16 15
17 16 private $endpoint = 'dependencies';
18 -
19 17 public $query = 'dependencies{ id, name, icon, plugin_file, plugin_original_slug, is_pro, link }';
20 18
21 19 public function __construct() {
22 20 parent::__construct();
@@ -27,21 +25,13 @@
27 25 }
28 26
29 27 public function permission_check( WP_REST_Request $request ) {
30 28 $this->request = $request;
29 + // $_route = $request->get_route();
31 30
32 - // Installing reaches beyond template content, so it does not ride the
33 - // `delete_posts` base gate the read routes are happy with. Installer::install()
34 - // checks `install_plugins` / `activate_plugins` per plugin as well; this is the
35 - // front gate, so the route cannot be probed at all without the capability.
36 - if ( $request->get_route() === '/templately/v1/dependencies/install' && ! Helper::current_user_can( 'install_plugins' ) ) {
37 - return $this->error(
38 - 'invalid_permission',
39 - __( 'Sorry, you do not have permission to install a plugin.', 'templately' ),
40 - 'dependencies/install',
41 - rest_authorization_required_code()
42 - );
43 - }
31 + // if( $_route === '/templately/v1/dependencies/install' && ! Helper::current_user_can( 'install_plugins' ) ) {
32 + // return Helper::error('invalid_permission', __( 'Sorry, you do not have permission to install a plugin.', 'templately' ), 'dependencies/install', 403 );
33 + // }
44 34
45 35 return true;
46 36 }
47 37
@@ -46,10 +36,10 @@
46 36 }
47 37
48 38 public function register_routes() {
49 39 $this->get( $this->endpoint, [ $this, 'get_dependencies' ] );
50 - $this->post( $this->endpoint . '/plugins', [ $this, 'get_plugins' ] );
51 - $this->post( $this->endpoint . '/themes', [ $this, 'get_themes' ] );
40 + $this->get( $this->endpoint . '/plugins', [ $this, 'get_plugins' ] );
41 + $this->get( $this->endpoint . '/themes', [ $this, 'get_themes' ] );
52 42 $this->post( $this->endpoint . '/check', [$this, 'check_dependencies'] );
53 43 $this->post( $this->endpoint . '/install', [$this, 'install_dependencies'] );
54 44 }
55 45
@@ -160,17 +150,16 @@
160 150
161 151 public function get_plugins() {
162 152 require_once ABSPATH . 'wp-admin/includes/plugin.php';
163 153
164 - // Get parameters from request
165 - $dependencies = $this->get_param( 'dependencies', [], null );
166 - $platform = $this->get_param( 'platform', 'elementor' );
167 - $categories = $this->get_param( 'categories', [], null );
154 + $plugins = array();
168 155
169 - // Get all plugins for checking status
170 - $all_plugins = array();
171 156 foreach ( get_plugins() as $file => $data ) {
172 - $plugin_data = array(
157 + // if ( is_wp_error( $this->check_read_permission( $file ) ) ) {
158 + // continue;
159 + // }
160 +
161 + $data = array(
173 162 'plugin' => substr( $file, 0, - 4 ),
174 163 'status' => $this->get_plugin_status( $file ),
175 164 'name' => $data['Name'],
176 165 'plugin_uri' => $data['PluginURI'],
@@ -185,220 +174,58 @@
185 174 'requires_wp' => $data['RequiresWP'],
186 175 'requires_php' => $data['RequiresPHP'],
187 176 'textdomain' => $data['TextDomain'],
188 177 );
189 - $all_plugins[] = $plugin_data;
190 - }
191 178
192 - // Process dependencies and return only necessary data
193 - $new_dependency_list = [];
194 - $new_required_plugins = [];
195 -
196 - // Platform-specific plugins
197 - if ( $platform === 'elementor' ) {
198 - $elementor_plugin = $this->find_plugin_by_name( $all_plugins, 'elementor/elementor' );
199 - $e_plugin = array(
200 - 'plugin_file' => 'elementor/elementor.php',
201 - 'plugin_original_slug' => 'elementor',
202 - 'name' => $elementor_plugin ? $elementor_plugin['name'] : 'Elementor',
203 - 'installed' => $elementor_plugin ? ( $elementor_plugin['status'] === 'active' ) : false,
204 - 'mustHave' => true,
205 - );
206 - $new_dependency_list[] = $e_plugin;
207 - if ( ! $elementor_plugin || $elementor_plugin['status'] !== 'active' ) {
208 - $new_required_plugins[] = $e_plugin;
209 - }
210 - } elseif ( $platform === 'gutenberg' ) {
211 - // Check if WordPress supports Gutenberg natively or if Gutenberg plugin is needed
212 - $gutenberg_plugin = $this->find_plugin_by_name( $all_plugins, 'gutenberg/gutenberg' );
213 -
214 - // Note: templately.is_wp_support_gutenberg is a frontend variable,
215 - // we'll assume Gutenberg plugin is needed if it exists and is inactive
216 - if ( $gutenberg_plugin && $gutenberg_plugin['status'] === 'inactive' ) {
217 - $g_plugin = array(
218 - 'plugin_file' => 'gutenberg/gutenberg.php',
219 - 'plugin_original_slug' => 'gutenberg',
220 - 'name' => $gutenberg_plugin['name'],
221 - 'mustHave' => true,
222 - );
223 - $new_dependency_list[] = $g_plugin;
224 - $new_required_plugins[] = $g_plugin;
225 - }
179 + $plugins[] = $data;
226 180 }
227 181
228 - // Process template dependencies
229 - if ( ! empty( $dependencies ) && is_array( $dependencies ) ) {
230 - foreach ( $dependencies as $plugin_file => $plugin_obj ) {
231 - if ( ! is_array( $plugin_obj ) ) {
232 - continue;
233 - }
234 -
235 - $plugin_name = str_replace( '.php', '', $plugin_file );
236 - $plugin = $this->find_plugin_by_name( $all_plugins, $plugin_name );
237 -
238 - if ( $plugin && $plugin['status'] === 'active' ) {
239 - $plugin_obj['installed'] = true;
240 - $new_dependency_list[] = $plugin_obj;
241 - } else {
242 - $new_dependency_list[] = $plugin_obj;
243 - $new_required_plugins[] = $plugin_obj;
244 - }
245 - }
246 - }
247 -
248 - if ( $this->should_offer_caching() ) {
249 - $caching = Caching::dependency_entry();
250 - Caching::mark_offered();
251 -
252 - $new_dependency_list[] = $caching;
253 - $new_required_plugins[] = $caching;
254 - } else {
255 - // Category-based plugins
256 - $included_categories = array(
257 - 'blog-magazine',
258 - 'construction',
259 - 'ecommerce',
260 - 'education',
261 - 'entertainment',
262 - 'fashion-lifestyle',
263 - 'features-services',
264 - 'food-restaurant',
265 - 'marketing',
266 - 'miscellaneous',
267 - 'multipurpose',
268 - 'nft-cryptocurrency',
269 - 'non-profit',
270 - 'technology',
271 - 'travel',
272 - );
273 -
274 - $is_any_category_included = false;
275 - if ( ! empty( $categories ) && is_array( $categories ) ) {
276 - foreach ( $categories as $category ) {
277 - if ( isset( $category['slug'] ) && in_array( $category['slug'], $included_categories, true ) ) {
278 - $is_any_category_included = true;
279 - break;
280 - }
281 - }
282 - }
283 -
284 - if ( $is_any_category_included ) {
285 - $nx_plugin = $this->find_plugin_by_name( $all_plugins, 'notificationx/notificationx' );
286 - $notificationx = array(
287 - 'name' => 'NotificationX',
288 - 'icon' => 'https://ps.w.org/notificationx/assets/icon-256x256.gif?rev=2783824',
289 - 'plugin_file' => 'notificationx/notificationx.php',
290 - 'plugin_original_slug' => 'notificationx',
291 - 'is_pro' => false,
292 - 'installed' => $nx_plugin ? ( $nx_plugin['status'] === 'active' ) : false,
293 - 'link' => 'https://wordpress.org/plugins/notificationx/',
294 - );
295 - $new_dependency_list[] = $notificationx;
296 - $new_required_plugins[] = $notificationx;
297 - }
298 -
299 - // EmbedPress for blog-magazine category
300 - $ep_is_any_category_included = false;
301 - if ( ! empty( $categories ) && is_array( $categories ) ) {
302 - foreach ( $categories as $category ) {
303 - if ( isset( $category['slug'] ) && $category['slug'] === 'blog-magazine' ) {
304 - $ep_is_any_category_included = true;
305 - break;
306 - }
307 - }
308 - }
309 -
310 - if ( $ep_is_any_category_included ) {
311 - $ep_plugin = $this->find_plugin_by_name( $all_plugins, 'embedpress/embedpress' );
312 - $embed_press = array(
313 - 'name' => 'EmbedPress',
314 - 'icon' => 'https://ps.w.org/embedpress/assets/icon-256x256.gif?rev=2783824',
315 - 'plugin_file' => 'embedpress/embedpress.php',
316 - 'plugin_original_slug' => 'embedpress',
317 - 'is_pro' => false,
318 - 'installed' => $ep_plugin ? ( $ep_plugin['status'] === 'active' ) : false,
319 - 'link' => 'https://wordpress.org/plugins/embedpress/',
320 - );
321 - $new_dependency_list[] = $embed_press;
322 - $new_required_plugins[] = $embed_press;
323 - }
324 - }
325 -
326 - return new \WP_REST_Response( array(
327 - 'dependencyList' => $new_dependency_list,
328 - 'requiredPlugins' => $new_required_plugins
329 - ) );
182 + return new \WP_REST_Response( $plugins );
330 183 }
331 184
332 - protected function should_offer_caching(): bool {
333 - return Caching::should_offer();
334 - }
335 -
336 - /**
337 - * Helper method to find a plugin by its name/slug
338 - *
339 - * @param array $plugins Array of all plugins
340 - * @param string $plugin_name Plugin name to search for
341 - * @return array|null Plugin data or null if not found
342 - */
343 - private function find_plugin_by_name( $plugins, $plugin_name ) {
344 - foreach ( $plugins as $plugin ) {
345 - if ( $plugin['plugin'] === $plugin_name ) {
346 - return $plugin;
347 - }
348 - }
349 - return null;
350 - }
351 -
352 185 public function get_themes() {
353 - // Get platform parameter from request
354 - $platform = $this->get_param( 'platform', 'elementor' );
186 + $themes = array();
355 187
356 188 $active_themes = wp_get_themes();
357 189 $current_theme = wp_get_theme();
358 190
359 - $recommended_theme = array();
191 + foreach ( $active_themes as $theme_name => $theme ) {
192 + $data = array(
193 + 'status' => $theme->get_stylesheet() === $current_theme->get_stylesheet() ? 'active' : 'inactive',
194 + 'template' => $theme->get_template(),
195 + 'stylesheet' => $theme->get_stylesheet(),
196 + );
360 197
361 - if ( $platform === 'elementor' ) {
362 - // Look for Hello Elementor theme
363 - $target_stylesheet = 'hello-elementor';
364 - $elementor_theme = null;
365 198
366 - foreach ( $active_themes as $theme ) {
367 - if ( $theme->get_stylesheet() === $target_stylesheet ) {
368 - $elementor_theme = $theme;
369 - break;
370 - }
199 + $plain_field_mappings = array(
200 + 'requires_php' => 'RequiresPHP',
201 + 'requires_wp' => 'RequiresWP',
202 + 'textdomain' => 'TextDomain',
203 + 'version' => 'Version',
204 + );
205 +
206 + foreach ( $plain_field_mappings as $field => $header ) {
207 + $data[ $field ] = $theme->get( $header );
371 208 }
372 209
373 - $recommended_theme = array(
374 - 'name' => $elementor_theme ? $elementor_theme->display( 'Name' ) : 'Hello Elementor',
375 - 'status' => $elementor_theme ? ( $elementor_theme->get_stylesheet() === $current_theme->get_stylesheet() ? 'active' : 'inactive' ) : 'inactive',
376 - 'template' => $elementor_theme ? $elementor_theme->get_template() : 'hello-elementor',
377 - 'stylesheet' => $elementor_theme ? $elementor_theme->get_stylesheet() : 'hello-elementor',
210 + $rich_field_mappings = array(
211 + 'author' => 'Author',
212 + 'author_uri' => 'AuthorURI',
213 + 'description' => 'Description',
214 + 'name' => 'Name',
215 + 'tags' => 'Tags',
216 + 'theme_uri' => 'ThemeURI',
378 217 );
379 218
380 - } elseif ( $platform === 'gutenberg' ) {
381 - // Look for Twenty Twenty-Four theme
382 - $target_stylesheet = 'twentytwentyfour';
383 - $gutenberg_theme = null;
384 -
385 - foreach ( $active_themes as $theme ) {
386 - if ( $theme->get_stylesheet() === $target_stylesheet ) {
387 - $gutenberg_theme = $theme;
388 - break;
389 - }
219 + foreach ( $rich_field_mappings as $field => $header ) {
220 + $data[ $field ]['raw'] = $theme->display( $header, false, true );
221 + $data[ $field ]['rendered'] = $theme->display( $header );
390 222 }
391 223
392 - $recommended_theme = array(
393 - 'name' => $gutenberg_theme ? $gutenberg_theme->display( 'Name' ) : 'Twenty Twenty-Four',
394 - 'status' => $gutenberg_theme ? ( $gutenberg_theme->get_stylesheet() === $current_theme->get_stylesheet() ? 'active' : 'inactive' ) : 'inactive',
395 - 'template' => $gutenberg_theme ? $gutenberg_theme->get_template() : 'twentytwentyfour',
396 - 'stylesheet' => $gutenberg_theme ? $gutenberg_theme->get_stylesheet() : 'twentytwentyfour',
397 - );
224 + $themes[] = $data;
398 225 }
399 226
400 - return new \WP_REST_Response( $recommended_theme );
227 + return new \WP_REST_Response( $themes );
401 228 }
402 229
403 230 /**
404 231 * Get's the activation status for a plugin.
@@ -419,5 +246,5 @@
419 246
420 247 return 'inactive';
421 248 }
422 249
423 -}
250 +}