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