PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.5.3
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.5.3
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 +190 -39 3.1.103.5.3 View file →
@@ -36,10 +36,10 @@
36 36 }
37 37
38 38 public function register_routes() {
39 39 $this->get( $this->endpoint, [ $this, 'get_dependencies' ] );
40 - $this->get( $this->endpoint . '/plugins', [ $this, 'get_plugins' ] );
41 - $this->get( $this->endpoint . '/themes', [ $this, 'get_themes' ] );
40 + $this->post( $this->endpoint . '/plugins', [ $this, 'get_plugins' ] );
41 + $this->post( $this->endpoint . '/themes', [ $this, 'get_themes' ] );
42 42 $this->post( $this->endpoint . '/check', [$this, 'check_dependencies'] );
43 43 $this->post( $this->endpoint . '/install', [$this, 'install_dependencies'] );
44 44 }
45 45
@@ -150,16 +150,17 @@
150 150
151 151 public function get_plugins() {
152 152 require_once ABSPATH . 'wp-admin/includes/plugin.php';
153 153
154 - $plugins = array();
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 );
155 158
159 + // Get all plugins for checking status
160 + $all_plugins = array();
156 161 foreach ( get_plugins() as $file => $data ) {
157 - // if ( is_wp_error( $this->check_read_permission( $file ) ) ) {
158 - // continue;
159 - // }
160 -
161 - $data = array(
162 + $plugin_data = array(
162 163 'plugin' => substr( $file, 0, - 4 ),
163 164 'status' => $this->get_plugin_status( $file ),
164 165 'name' => $data['Name'],
165 166 'plugin_uri' => $data['PluginURI'],
@@ -174,58 +175,208 @@
174 175 'requires_wp' => $data['RequiresWP'],
175 176 'requires_php' => $data['RequiresPHP'],
176 177 'textdomain' => $data['TextDomain'],
177 178 );
179 + $all_plugins[] = $plugin_data;
180 + }
178 181
179 - $plugins[] = $data;
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 + }
180 216 }
181 217
182 - return new \WP_REST_Response( $plugins );
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 + ) );
183 312 }
184 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 +
185 330 public function get_themes() {
186 - $themes = array();
331 + // Get platform parameter from request
332 + $platform = $this->get_param( 'platform', 'elementor' );
187 333
188 334 $active_themes = wp_get_themes();
189 335 $current_theme = wp_get_theme();
190 336
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 - );
337 + $recommended_theme = array();
197 338
339 + if ( $platform === 'elementor' ) {
340 + // Look for Hello Elementor theme
341 + $target_stylesheet = 'hello-elementor';
342 + $elementor_theme = null;
198 343
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 );
344 + foreach ( $active_themes as $theme ) {
345 + if ( $theme->get_stylesheet() === $target_stylesheet ) {
346 + $elementor_theme = $theme;
347 + break;
348 + }
208 349 }
209 350
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',
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',
217 356 );
218 357
219 - foreach ( $rich_field_mappings as $field => $header ) {
220 - $data[ $field ]['raw'] = $theme->display( $header, false, true );
221 - $data[ $field ]['rendered'] = $theme->display( $header );
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 + }
222 368 }
223 369
224 - $themes[] = $data;
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 + );
225 376 }
226 377
227 - return new \WP_REST_Response( $themes );
378 + return new \WP_REST_Response( $recommended_theme );
228 379 }
229 380
230 381 /**
231 382 * Get's the activation status for a plugin.
@@ -246,5 +397,5 @@
246 397
247 398 return 'inactive';
248 399 }
249 400
250 -}
401 +}