PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.7.2
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.7.2
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 +283 -7 3.0.43.7.2 View file →
@@ -15,14 +15,30 @@
15 15
16 16 private $endpoint = 'dependencies';
17 17 public $query = 'dependencies{ id, name, icon, plugin_file, plugin_original_slug, is_pro, link }';
18 18
19 + public function __construct() {
20 + parent::__construct();
21 +
22 + if(!empty($_GET['disable_redirect'])) {
23 + add_filter('wp_redirect', '__return_false', 999);
24 + }
25 + }
26 +
19 27 public function permission_check( WP_REST_Request $request ) {
20 28 $this->request = $request;
21 - $_route = $request->get_route();
22 29
23 - if( $_route === '/templately/v1/dependencies/install' && ! current_user_can( 'install_plugins' ) ) {
24 - return $this->error('invalid_permission', __( 'Sorry, you do not have permission to install a plugin.', 'templately' ), 'dependencies/install', 403 );
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 + );
25 41 }
26 42
27 43 return true;
28 44 }
@@ -28,8 +44,10 @@
28 44 }
29 45
30 46 public function register_routes() {
31 47 $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' ] );
32 50 $this->post( $this->endpoint . '/check', [$this, 'check_dependencies'] );
33 51 $this->post( $this->endpoint . '/install', [$this, 'install_dependencies'] );
34 52 }
35 53
@@ -76,14 +94,15 @@
76 94
77 95 $_inactive_plugins = [];
78 96 $_plugins = Helper::get_plugins();
79 97
80 - if( ! Helper::is_plugin_active( 'elementor/elementor.php' ) && $platform === 'elementor' ) {
98 + if( $platform === 'elementor' ) {
81 99 $elementor_plugin = new stdClass();
82 100 $elementor_plugin->name = __( 'Elementor', 'templately' );
83 101 $elementor_plugin->plugin_file = 'elementor/elementor.php';
84 102 $elementor_plugin->slug = 'elementor';
85 103 $elementor_plugin->is_pro = false;
104 + $elementor_plugin->is_active = Helper::is_plugin_active( 'elementor/elementor.php' );
86 105
87 106 $_inactive_plugins[] = $elementor_plugin;
88 107 }
89 108
@@ -93,12 +112,14 @@
93 112 continue;
94 113 }
95 114
96 115 $dependency = ( object ) $dependency;
97 - if ( is_null( $dependency->plugin_file ) || Helper::is_plugin_active( $dependency->plugin_file ) ) {
116 + if ( is_null( $dependency->plugin_file ) ) {
98 117 continue;
99 118 }
100 119
120 + $dependency->is_active = Helper::is_plugin_active( $dependency->plugin_file );
121 +
101 122 if( isset( $dependency->plugin_original_slug ) ) {
102 123 $dependency->slug = $dependency->plugin_original_slug;
103 124 unset( $dependency->plugin_original_slug );
104 125 }
@@ -127,7 +148,262 @@
127 148 '/install',
128 149 400
129 150 );
130 151 }
131 - return Installer::get_instance()->install( $requirements );
152 + $installed = Installer::get_instance()->install( $requirements );
153 + if(empty($installed['success'])){
154 + return $this->error($installed['code'], $installed['message'], 'dependencies/install', 403 );
155 + }
156 + return $installed;
132 157 }
133 -}
158 +
159 + public function get_plugins() {
160 + require_once ABSPATH . 'wp-admin/includes/plugin.php';
161 +
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 );
166 +
167 + // Get all plugins for checking status
168 + $all_plugins = array();
169 + foreach ( get_plugins() as $file => $data ) {
170 + $plugin_data = array(
171 + 'plugin' => substr( $file, 0, - 4 ),
172 + 'status' => $this->get_plugin_status( $file ),
173 + 'name' => $data['Name'],
174 + 'plugin_uri' => $data['PluginURI'],
175 + 'author' => $data['Author'],
176 + 'author_uri' => $data['AuthorURI'],
177 + 'description' => array(
178 + 'raw' => $data['Description'],
179 + 'rendered' => $data['Description'],
180 + ),
181 + 'version' => $data['Version'],
182 + 'network_only' => $data['Network'],
183 + 'requires_wp' => $data['RequiresWP'],
184 + 'requires_php' => $data['RequiresPHP'],
185 + 'textdomain' => $data['TextDomain'],
186 + );
187 + $all_plugins[] = $plugin_data;
188 + }
189 +
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 + }
224 + }
225 +
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 + ) );
320 + }
321 +
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 + public function get_themes() {
339 + // Get platform parameter from request
340 + $platform = $this->get_param( 'platform', 'elementor' );
341 +
342 + $active_themes = wp_get_themes();
343 + $current_theme = wp_get_theme();
344 +
345 + $recommended_theme = array();
346 +
347 + if ( $platform === 'elementor' ) {
348 + // Look for Hello Elementor theme
349 + $target_stylesheet = 'hello-elementor';
350 + $elementor_theme = null;
351 +
352 + foreach ( $active_themes as $theme ) {
353 + if ( $theme->get_stylesheet() === $target_stylesheet ) {
354 + $elementor_theme = $theme;
355 + break;
356 + }
357 + }
358 +
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',
364 + );
365 +
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 + }
376 + }
377 +
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 + );
384 + }
385 +
386 + return new \WP_REST_Response( $recommended_theme );
387 + }
388 +
389 + /**
390 + * Get's the activation status for a plugin.
391 + *
392 + * @since 5.5.0
393 + *
394 + * @param string $plugin The plugin file to check.
395 + * @return string Either 'active' or 'inactive'.
396 + */
397 + protected function get_plugin_status( $plugin ) {
398 + if ( is_plugin_active_for_network( $plugin ) ) {
399 + return 'active';
400 + }
401 +
402 + if ( is_plugin_active( $plugin ) ) {
403 + return 'active';
404 + }
405 +
406 + return 'inactive';
407 + }
408 +
409 +}