PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 2.2.9
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v2.2.9
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 +8 -276 3.6.82.2.9 View file →
@@ -15,23 +15,15 @@
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 -
27 19 public function permission_check( WP_REST_Request $request ) {
28 20 $this->request = $request;
29 - // $_route = $request->get_route();
21 + $_route = $request->get_route();
30 22
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 - // }
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 );
25 + }
34 26
35 27 return true;
36 28 }
37 29
@@ -36,10 +28,8 @@
36 28 }
37 29
38 30 public function register_routes() {
39 31 $this->get( $this->endpoint, [ $this, 'get_dependencies' ] );
40 - $this->post( $this->endpoint . '/plugins', [ $this, 'get_plugins' ] );
41 - $this->post( $this->endpoint . '/themes', [ $this, 'get_themes' ] );
42 32 $this->post( $this->endpoint . '/check', [$this, 'check_dependencies'] );
43 33 $this->post( $this->endpoint . '/install', [$this, 'install_dependencies'] );
44 34 }
45 35
@@ -86,15 +76,14 @@
86 76
87 77 $_inactive_plugins = [];
88 78 $_plugins = Helper::get_plugins();
89 79
90 - if( $platform === 'elementor' ) {
80 + if( ! Helper::is_plugin_active( 'elementor/elementor.php' ) && $platform === 'elementor' ) {
91 81 $elementor_plugin = new stdClass();
92 82 $elementor_plugin->name = __( 'Elementor', 'templately' );
93 83 $elementor_plugin->plugin_file = 'elementor/elementor.php';
94 84 $elementor_plugin->slug = 'elementor';
95 85 $elementor_plugin->is_pro = false;
96 - $elementor_plugin->is_active = Helper::is_plugin_active( 'elementor/elementor.php' );
97 86
98 87 $_inactive_plugins[] = $elementor_plugin;
99 88 }
100 89
@@ -104,14 +93,12 @@
104 93 continue;
105 94 }
106 95
107 96 $dependency = ( object ) $dependency;
108 - if ( is_null( $dependency->plugin_file ) ) {
97 + if ( is_null( $dependency->plugin_file ) || Helper::is_plugin_active( $dependency->plugin_file ) ) {
109 98 continue;
110 99 }
111 100
112 - $dependency->is_active = Helper::is_plugin_active( $dependency->plugin_file );
113 -
114 101 if( isset( $dependency->plugin_original_slug ) ) {
115 102 $dependency->slug = $dependency->plugin_original_slug;
116 103 unset( $dependency->plugin_original_slug );
117 104 }
@@ -140,262 +127,7 @@
140 127 '/install',
141 128 400
142 129 );
143 130 }
144 - $installed = Installer::get_instance()->install( $requirements );
145 - if(empty($installed['success'])){
146 - return $this->error($installed['code'], $installed['message'], 'dependencies/install', 403 );
147 - }
148 - return $installed;
131 + return Installer::get_instance()->install( $requirements );
149 132 }
150 -
151 - public function get_plugins() {
152 - require_once ABSPATH . 'wp-admin/includes/plugin.php';
153 -
154 - // Get parameters from request
155 - $dependencies = $this->get_param( 'dependencies', [], null );
156 - $platform = $this->get_param( 'platform', 'elementor' );
157 - $categories = $this->get_param( 'categories', [], null );
158 -
159 - // Get all plugins for checking status
160 - $all_plugins = array();
161 - foreach ( get_plugins() as $file => $data ) {
162 - $plugin_data = array(
163 - 'plugin' => substr( $file, 0, - 4 ),
164 - 'status' => $this->get_plugin_status( $file ),
165 - 'name' => $data['Name'],
166 - 'plugin_uri' => $data['PluginURI'],
167 - 'author' => $data['Author'],
168 - 'author_uri' => $data['AuthorURI'],
169 - 'description' => array(
170 - 'raw' => $data['Description'],
171 - 'rendered' => $data['Description'],
172 - ),
173 - 'version' => $data['Version'],
174 - 'network_only' => $data['Network'],
175 - 'requires_wp' => $data['RequiresWP'],
176 - 'requires_php' => $data['RequiresPHP'],
177 - 'textdomain' => $data['TextDomain'],
178 - );
179 - $all_plugins[] = $plugin_data;
180 - }
181 -
182 - // Process dependencies and return only necessary data
183 - $new_dependency_list = [];
184 - $new_required_plugins = [];
185 -
186 - // Platform-specific plugins
187 - if ( $platform === 'elementor' ) {
188 - $elementor_plugin = $this->find_plugin_by_name( $all_plugins, 'elementor/elementor' );
189 - $e_plugin = array(
190 - 'plugin_file' => 'elementor/elementor.php',
191 - 'plugin_original_slug' => 'elementor',
192 - 'name' => $elementor_plugin ? $elementor_plugin['name'] : 'Elementor',
193 - 'installed' => $elementor_plugin ? ( $elementor_plugin['status'] === 'active' ) : false,
194 - 'mustHave' => true,
195 - );
196 - $new_dependency_list[] = $e_plugin;
197 - if ( ! $elementor_plugin || $elementor_plugin['status'] !== 'active' ) {
198 - $new_required_plugins[] = $e_plugin;
199 - }
200 - } elseif ( $platform === 'gutenberg' ) {
201 - // Check if WordPress supports Gutenberg natively or if Gutenberg plugin is needed
202 - $gutenberg_plugin = $this->find_plugin_by_name( $all_plugins, 'gutenberg/gutenberg' );
203 -
204 - // Note: templately.is_wp_support_gutenberg is a frontend variable,
205 - // we'll assume Gutenberg plugin is needed if it exists and is inactive
206 - if ( $gutenberg_plugin && $gutenberg_plugin['status'] === 'inactive' ) {
207 - $g_plugin = array(
208 - 'plugin_file' => 'gutenberg/gutenberg.php',
209 - 'plugin_original_slug' => 'gutenberg',
210 - 'name' => $gutenberg_plugin['name'],
211 - 'mustHave' => true,
212 - );
213 - $new_dependency_list[] = $g_plugin;
214 - $new_required_plugins[] = $g_plugin;
215 - }
216 - }
217 -
218 - // Process template dependencies
219 - if ( ! empty( $dependencies ) && is_array( $dependencies ) ) {
220 - foreach ( $dependencies as $plugin_file => $plugin_obj ) {
221 - if ( ! is_array( $plugin_obj ) ) {
222 - continue;
223 - }
224 -
225 - $plugin_name = str_replace( '.php', '', $plugin_file );
226 - $plugin = $this->find_plugin_by_name( $all_plugins, $plugin_name );
227 -
228 - if ( $plugin && $plugin['status'] === 'active' ) {
229 - $plugin_obj['installed'] = true;
230 - $new_dependency_list[] = $plugin_obj;
231 - } else {
232 - $new_dependency_list[] = $plugin_obj;
233 - $new_required_plugins[] = $plugin_obj;
234 - }
235 - }
236 - }
237 -
238 - // Category-based plugins
239 - $included_categories = array(
240 - 'blog-magazine',
241 - 'construction',
242 - 'ecommerce',
243 - 'education',
244 - 'entertainment',
245 - 'fashion-lifestyle',
246 - 'features-services',
247 - 'food-restaurant',
248 - 'marketing',
249 - 'miscellaneous',
250 - 'multipurpose',
251 - 'nft-cryptocurrency',
252 - 'non-profit',
253 - 'technology',
254 - 'travel',
255 - );
256 -
257 - $is_any_category_included = false;
258 - if ( ! empty( $categories ) && is_array( $categories ) ) {
259 - foreach ( $categories as $category ) {
260 - if ( isset( $category['slug'] ) && in_array( $category['slug'], $included_categories, true ) ) {
261 - $is_any_category_included = true;
262 - break;
263 - }
264 - }
265 - }
266 -
267 - if ( $is_any_category_included ) {
268 - $nx_plugin = $this->find_plugin_by_name( $all_plugins, 'notificationx/notificationx' );
269 - $notificationx = array(
270 - 'name' => 'NotificationX',
271 - 'icon' => 'https://ps.w.org/notificationx/assets/icon-256x256.gif?rev=2783824',
272 - 'plugin_file' => 'notificationx/notificationx.php',
273 - 'plugin_original_slug' => 'notificationx',
274 - 'is_pro' => false,
275 - 'installed' => $nx_plugin ? ( $nx_plugin['status'] === 'active' ) : false,
276 - 'link' => 'https://wordpress.org/plugins/notificationx/',
277 - );
278 - $new_dependency_list[] = $notificationx;
279 - $new_required_plugins[] = $notificationx;
280 - }
281 -
282 - // EmbedPress for blog-magazine category
283 - $ep_is_any_category_included = false;
284 - if ( ! empty( $categories ) && is_array( $categories ) ) {
285 - foreach ( $categories as $category ) {
286 - if ( isset( $category['slug'] ) && $category['slug'] === 'blog-magazine' ) {
287 - $ep_is_any_category_included = true;
288 - break;
289 - }
290 - }
291 - }
292 -
293 - if ( $ep_is_any_category_included ) {
294 - $ep_plugin = $this->find_plugin_by_name( $all_plugins, 'embedpress/embedpress' );
295 - $embed_press = array(
296 - 'name' => 'EmbedPress',
297 - 'icon' => 'https://ps.w.org/embedpress/assets/icon-256x256.gif?rev=2783824',
298 - 'plugin_file' => 'embedpress/embedpress.php',
299 - 'plugin_original_slug' => 'embedpress',
300 - 'is_pro' => false,
301 - 'installed' => $ep_plugin ? ( $ep_plugin['status'] === 'active' ) : false,
302 - 'link' => 'https://wordpress.org/plugins/embedpress/',
303 - );
304 - $new_dependency_list[] = $embed_press;
305 - $new_required_plugins[] = $embed_press;
306 - }
307 -
308 - return new \WP_REST_Response( array(
309 - 'dependencyList' => $new_dependency_list,
310 - 'requiredPlugins' => $new_required_plugins
311 - ) );
312 - }
313 -
314 - /**
315 - * Helper method to find a plugin by its name/slug
316 - *
317 - * @param array $plugins Array of all plugins
318 - * @param string $plugin_name Plugin name to search for
319 - * @return array|null Plugin data or null if not found
320 - */
321 - private function find_plugin_by_name( $plugins, $plugin_name ) {
322 - foreach ( $plugins as $plugin ) {
323 - if ( $plugin['plugin'] === $plugin_name ) {
324 - return $plugin;
325 - }
326 - }
327 - return null;
328 - }
329 -
330 - public function get_themes() {
331 - // Get platform parameter from request
332 - $platform = $this->get_param( 'platform', 'elementor' );
333 -
334 - $active_themes = wp_get_themes();
335 - $current_theme = wp_get_theme();
336 -
337 - $recommended_theme = array();
338 -
339 - if ( $platform === 'elementor' ) {
340 - // Look for Hello Elementor theme
341 - $target_stylesheet = 'hello-elementor';
342 - $elementor_theme = null;
343 -
344 - foreach ( $active_themes as $theme ) {
345 - if ( $theme->get_stylesheet() === $target_stylesheet ) {
346 - $elementor_theme = $theme;
347 - break;
348 - }
349 - }
350 -
351 - $recommended_theme = array(
352 - 'name' => $elementor_theme ? $elementor_theme->display( 'Name' ) : 'Hello Elementor',
353 - 'status' => $elementor_theme ? ( $elementor_theme->get_stylesheet() === $current_theme->get_stylesheet() ? 'active' : 'inactive' ) : 'inactive',
354 - 'template' => $elementor_theme ? $elementor_theme->get_template() : 'hello-elementor',
355 - 'stylesheet' => $elementor_theme ? $elementor_theme->get_stylesheet() : 'hello-elementor',
356 - );
357 -
358 - } elseif ( $platform === 'gutenberg' ) {
359 - // Look for Twenty Twenty-Four theme
360 - $target_stylesheet = 'twentytwentyfour';
361 - $gutenberg_theme = null;
362 -
363 - foreach ( $active_themes as $theme ) {
364 - if ( $theme->get_stylesheet() === $target_stylesheet ) {
365 - $gutenberg_theme = $theme;
366 - break;
367 - }
368 - }
369 -
370 - $recommended_theme = array(
371 - 'name' => $gutenberg_theme ? $gutenberg_theme->display( 'Name' ) : 'Twenty Twenty-Four',
372 - 'status' => $gutenberg_theme ? ( $gutenberg_theme->get_stylesheet() === $current_theme->get_stylesheet() ? 'active' : 'inactive' ) : 'inactive',
373 - 'template' => $gutenberg_theme ? $gutenberg_theme->get_template() : 'twentytwentyfour',
374 - 'stylesheet' => $gutenberg_theme ? $gutenberg_theme->get_stylesheet() : 'twentytwentyfour',
375 - );
376 - }
377 -
378 - return new \WP_REST_Response( $recommended_theme );
379 - }
380 -
381 - /**
382 - * Get's the activation status for a plugin.
383 - *
384 - * @since 5.5.0
385 - *
386 - * @param string $plugin The plugin file to check.
387 - * @return string Either 'active' or 'inactive'.
388 - */
389 - protected function get_plugin_status( $plugin ) {
390 - if ( is_plugin_active_for_network( $plugin ) ) {
391 - return 'active';
392 - }
393 -
394 - if ( is_plugin_active( $plugin ) ) {
395 - return 'active';
396 - }
397 -
398 - return 'inactive';
399 - }
400 -
401 -}
133 +}