PluginProbe
Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits / 3.1.0
Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits v3.1.0
3.2.2 3.2.3 3.2.1 3.2.0 3.1.9 3.1.8 3.1.7 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.9 trunk 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.3 1.1.4 1.1.5 All 174 releases
master-addons / lib / Recommended.php

Recommended.php in Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits 3.1.0, at lib/Recommended.php

462 lines 14.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace MasterAddons\Lib;
4
5 // No, Direct access Sir !!!
6 if (!defined('ABSPATH')) {
7 exit;
8 }
9
10 /*
11 * Recommended global class
12 */
13
14 if (!class_exists('Recommended')) {
15
16 /**
17 * Recommended Class
18 *
19 * Jewel Theme <support@jeweltheme.com>
20 */
21 class Recommended
22 {
23
24
25 public $menu_items;
26 public $plugins_list;
27 public $sub_menu;
28 public $menu_order;
29
30
31 /**
32 * Constructor method
33 *
34 * @param integer $menu_order .
35 * @author Jewel Theme <support@jeweltheme.com>
36 */
37 public function __construct($menu_order = 99)
38 {
39 $this->menu_order = $menu_order;
40 $this->menu_items = $this->menu_items();
41 $this->plugins_list = $this->plugins_list();
42
43 $this->includes();
44
45 add_action('admin_menu', array($this, 'admin_menu'), $this->menu_order);
46 add_action('wp_ajax_jltma_recommended_upgrade_plugin', array($this, 'jltma_recommended_upgrade_plugin'));
47 add_action('wp_ajax_jltma_recommended_activate_plugin', array($this, 'jltma_recommended_activate_plugin'));
48 }
49
50 /**
51 * Includes
52 *
53 * @author Jewel Theme <support@jeweltheme.com>
54 */
55 public function includes()
56 {
57 if (!function_exists('install_plugin_install_status')) {
58 require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
59 }
60 }
61
62 /**
63 * Menu Items
64 *
65 * @author Jewel Theme <support@jeweltheme.com>
66 */
67 public function menu_items()
68 {
69 return array();
70 }
71
72 /**
73 * Plugins list
74 *
75 * @author Jewel Theme <support@jeweltheme.com>
76 */
77 public function plugins_list()
78 {
79 return array();
80 }
81
82 /**
83 * Admin submenu
84 */
85 public function admin_menu()
86 {
87 }
88
89 /**
90 * Render recommended plugins body
91 */
92 public function render_recommended_plugins()
93 { ?>
94 <div class='jltma-recommended-wrapper'>
95 <?php $this->header(); ?>
96 <?php $this->body(); ?>
97 </div>
98 <style>
99 /* Hide WordPress default admin notices on this page */
100 .jltma-recommended-wrapper ~ .notice,
101 .jltma-recommended-wrapper ~ .error,
102 .jltma-recommended-wrapper ~ .updated {
103 display: none;
104 }
105 </style>
106 <?php
107 }
108
109 /**
110 * Header
111 */
112 public function header()
113 {
114 ?>
115 <div class='jltma-recommended-header'>
116 <div class='jltma-recommended-header-top'>
117 <div class='jltma-recommended-title'>
118 <h2><?php echo esc_html__('Recommended Plugins', 'master-addons'); ?></h2>
119 <p><?php echo esc_html__('Starter and recommended plugins to extend your WordPress experience.', 'master-addons'); ?></p>
120 </div>
121 <div class='jltma-recommended-search'>
122 <form class="search-form jltma-search-plugins" method="get">
123 <input type="hidden" name="tab" value="search">
124 <label class="screen-reader-text" for="search-plugins">
125 <?php echo esc_html__('Search Plugins', 'master-addons'); ?>
126 </label>
127 <span class="jltma-search-icon">
128 <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/></svg>
129 </span>
130 <input type="search" name="s" id="search-plugins" value="" class="jltma-search-input" placeholder="<?php echo esc_html__('Search plugins...', 'master-addons'); ?>">
131 </form>
132 </div>
133 </div>
134 <div class='jltma-recommended-tabs'>
135 <ul class="jltma-filter-links">
136 <?php
137 $i = 0;
138 foreach ($this->menu_items as $menu) {
139 $class = str_replace(' ', '-', strtolower($menu['key']));
140 ?>
141 <li>
142 <a href="#" class="jltma-tab-link <?php echo esc_attr(0 === $i ? 'current' : ''); ?>" data-type="<?php echo esc_attr($menu['key']); ?>"><?php echo esc_html($menu['label']); ?></a>
143 </li>
144 <?php
145 $i++;
146 }
147 ?>
148 </ul>
149 </div>
150 </div>
151 <?php
152 }
153
154 /**
155 * Body
156 */
157 public function body()
158 {
159 ?>
160 <div class="jltma-plugins-grid">
161 <?php $this->plugins(); ?>
162 </div>
163 <?php
164 }
165
166 /**
167 * Body
168 */
169 public function plugins()
170 {
171 foreach ($this->plugins_list as $key => $plugin) {
172 $plugin_api = (object) $plugin;
173 if (!isset($plugin_api->version)) {
174 $plugin_api->version = '';
175 }
176 $install_status = \install_plugin_install_status($plugin_api);
177 $classes = implode(' ', $plugin['type']);
178
179 $more_details = self_admin_url(
180 'plugin-install.php?tab=plugin-information&amp;plugin=' . esc_attr($plugin['slug']) .
181 '&amp;TB_iframe=true&amp;width=600&amp;height=550'
182 );
183 ?>
184 <div class="jltma-plugin-card <?php echo esc_attr($classes); ?>" data-plugin="<?php echo esc_attr($key); ?>">
185 <div class="jltma-plugin-card-body">
186 <div class="jltma-plugin-icon">
187 <img src="<?php echo esc_url($plugin['icon']); ?>" alt="<?php echo esc_attr($plugin['name']); ?>">
188 </div>
189 <div class="jltma-plugin-info">
190 <h3 class="jltma-plugin-name">
191 <a href="<?php echo esc_url($more_details); ?>" class="thickbox open-plugin-details-modal"><?php echo esc_html($plugin['name']); ?></a>
192 </h3>
193 <p class="jltma-plugin-desc"><?php echo wp_kses_post($plugin['short_description']); ?></p>
194 </div>
195 </div>
196 <div class="jltma-plugin-card-footer">
197 <span class="jltma-plugin-status">
198 <?php
199 if ('install' === $install_status['status']) {
200 ?>
201 <span class="jltma-status-badge jltma-status-not-installed" data-plugin-url="<?php echo esc_attr($plugin['download_link']); ?>"><?php echo esc_html__('Not Installed', 'master-addons'); ?></span>
202 <?php
203 } elseif ('update_available' === $install_status['status']) {
204 if (is_plugin_active($install_status['file'])) {
205 ?>
206 <span class="jltma-status-badge jltma-status-active"><?php echo esc_html__('Active', 'master-addons'); ?></span>
207 <?php
208 } else {
209 ?>
210 <span class="jltma-status-badge jltma-status-inactive" data-plugin-file="<?php echo esc_attr($install_status['file']); ?>"><?php echo esc_html__('Inactive', 'master-addons'); ?></span>
211 <?php
212 }
213 } elseif (('latest_installed' === $install_status['status']) || ('newer_installed' === $install_status['status'])) {
214 if (is_plugin_active($install_status['file'])) {
215 ?>
216 <span class="jltma-status-badge jltma-status-active"><?php echo esc_html__('Active', 'master-addons'); ?></span>
217 <?php
218 } else {
219 ?>
220 <span class="jltma-status-badge jltma-status-inactive" data-plugin-file="<?php echo esc_attr($install_status['file']); ?>"><?php echo esc_html__('Inactive', 'master-addons'); ?></span>
221 <?php
222 }
223 }
224 ?>
225 </span>
226 <div class="jltma-plugin-action">
227 <?php
228 if ('install' === $install_status['status']) {
229 ?>
230 <button class="install-now jltma-btn jltma-btn-primary" data-install-url="<?php echo esc_attr($plugin['download_link']); ?>">
231 <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
232 <?php echo esc_html__('Install', 'master-addons'); ?>
233 </button>
234 <?php
235 } elseif ('update_available' === $install_status['status']) {
236 ?>
237 <button class="update-now jltma-btn jltma-btn-warning" data-plugin="<?php echo esc_attr($install_status['file']); ?>" data-slug="<?php echo esc_attr($plugin['slug']); ?>" data-update-url="<?php echo esc_attr($install_status['url']); ?>">
238 <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 2v6h-6"/><path d="M3 12a9 9 0 0 1 15-6.7L21 8"/><path d="M3 22v-6h6"/><path d="M21 12a9 9 0 0 1-15 6.7L3 16"/></svg>
239 <?php echo esc_html__('Update', 'master-addons'); ?>
240 </button>
241 <?php
242 } elseif (('latest_installed' === $install_status['status']) || ('newer_installed' === $install_status['status'])) {
243 if (is_plugin_active($install_status['file'])) {
244 ?>
245 <button type="button" class="jltma-btn jltma-btn-activated" disabled="disabled">
246 <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20 6 9 17l-5-5"/></svg>
247 <?php echo esc_html__('Activated', 'master-addons'); ?>
248 </button>
249 <?php
250 } elseif (current_user_can('activate_plugin', $install_status['file'])) {
251 ?>
252 <button class="activate-now jltma-btn jltma-btn-success" data-plugin-file="<?php echo esc_attr($install_status['file']); ?>">
253 <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"/></svg>
254 <?php echo esc_html__('Activate', 'master-addons'); ?>
255 </button>
256 <?php
257 } else {
258 ?>
259 <button type="button" class="jltma-btn jltma-btn-activated" disabled="disabled">
260 <?php echo esc_html__('Installed', 'master-addons'); ?>
261 </button>
262 <?php
263 }
264 }
265 ?>
266 </div>
267 </div>
268 </div>
269 <?php
270 }
271 }
272
273 /**
274 * Activate Plugins
275 *
276 * @author Jewel Theme <support@jeweltheme.com>
277 */
278 public function jltma_recommended_activate_plugin()
279 {
280 try {
281 if (isset($_POST['file'])) {
282 $nonce = isset($_POST['nonce']) ? sanitize_text_field(wp_unslash($_POST['nonce'])) : '';
283
284 if (!wp_verify_nonce($nonce, 'jltma_recommended_nonce')) {
285 wp_send_json_error(array('mess' => __('Nonce is invalid', 'master-addons')));
286 }
287
288 if ((is_multisite() && !is_network_admin()) || !current_user_can('install_plugins')) {
289 wp_send_json_error(array('mess' => __('Invalid access', 'master-addons')));
290 }
291
292 $file = sanitize_text_field(wp_unslash($_POST['file']));
293 $known_slugs = array_values(wp_list_pluck($this->plugins_list, 'slug'));
294 $file_slug = dirname($file);
295
296 if (!in_array($file_slug, $known_slugs)) {
297 wp_send_json_error(array('mess' => __('Invalid plugin', 'master-addons')));
298 }
299
300 $result = activate_plugin($file);
301
302 if (is_wp_error($result)) {
303 wp_send_json_error(
304 array(
305 'mess' => $result->get_error_message(),
306 )
307 );
308 }
309 wp_send_json_success(
310 array(
311 'mess' => __('Activate success', 'master-addons'),
312 )
313 );
314 }
315 } catch (\Exception $ex) {
316 wp_send_json_error(
317 array(
318 'mess' => $ex->getMessage(),
319 )
320 );
321 } catch (\Error $ex) {
322 wp_send_json_error(
323 array(
324 'mess' => $ex->getMessage(),
325 )
326 );
327 }
328 }
329
330 /**
331 * Upgrade Plugins required Libraries
332 *
333 * @author Jewel Theme <support@jeweltheme.com>
334 */
335 public function jltma_recommended_upgrade_plugin()
336 {
337 try {
338 require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
339 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
340 require_once ABSPATH . 'wp-admin/includes/class-wp-ajax-upgrader-skin.php';
341 require_once ABSPATH . 'wp-admin/includes/class-plugin-upgrader.php';
342
343 if (isset($_POST['plugin'])) {
344 $nonce = isset($_POST['nonce']) ? sanitize_text_field(wp_unslash($_POST['nonce'])) : '';
345
346 if (!wp_verify_nonce($nonce, 'jltma_recommended_nonce')) {
347 wp_send_json_error(array('mess' => __('Nonce is invalid', 'master-addons')));
348 }
349
350 if ((is_multisite() && !is_network_admin()) || !current_user_can('install_plugins')) {
351 wp_send_json_error(array('mess' => __('Invalid access', 'master-addons')));
352 }
353
354 $plugin = sanitize_text_field(wp_unslash($_POST['plugin']));
355 $plugin_links = array_values(wp_list_pluck($this->plugins_list, 'download_link'));
356 $known_slugs = array_values(wp_list_pluck($this->plugins_list, 'slug'));
357 $plugin_slug = dirname($plugin);
358 $is_valid = in_array($plugin, $plugin_links) || ($plugin_slug !== '.' && in_array($plugin_slug, $known_slugs));
359
360 if (!$is_valid) {
361 wp_send_json_error(array('mess' => __('Invalid plugin', 'master-addons')));
362 }
363
364 $type = isset($_POST['type']) ? sanitize_text_field(wp_unslash($_POST['type'])) : 'install';
365 $skin = new \WP_Ajax_Upgrader_Skin();
366 $upgrader = new \Plugin_Upgrader($skin);
367
368 if ('install' === $type) {
369 $result = $upgrader->install($plugin);
370
371 if (is_wp_error($result)) {
372 wp_send_json_error(
373 array(
374 'mess' => $result->get_error_message(),
375 )
376 );
377 }
378 $args = array(
379 'slug' => $upgrader->result['destination_name'],
380 'fields' => array(
381 'short_description' => true,
382 'icons' => true,
383 'banners' => false,
384 'added' => false,
385 'reviews' => false,
386 'sections' => false,
387 'requires' => false,
388 'rating' => false,
389 'ratings' => false,
390 'downloaded' => false,
391 'last_updated' => false,
392 'added' => false,
393 'tags' => false,
394 'compatibility' => false,
395 'homepage' => false,
396 'donate_link' => false,
397 ),
398 );
399 $plugin_data = plugins_api('plugin_information', $args);
400
401 if ($plugin_data && !is_wp_error($plugin_data)) {
402 $install_status = \install_plugin_install_status($plugin_data);
403 $active_plugin = activate_plugin($install_status['file']);
404
405 if (is_wp_error($active_plugin)) {
406 wp_send_json_error(
407 array(
408 'mess' => $active_plugin->get_error_message(),
409 )
410 );
411 } else {
412 wp_send_json_success(
413 array(
414 'mess' => __('Install success', 'master-addons'),
415 )
416 );
417 }
418 } else {
419 wp_send_json_error(
420 array(
421 'mess' => 'Error',
422 )
423 );
424 }
425 } else {
426 $is_active = is_plugin_active($plugin);
427 $result = $upgrader->upgrade($plugin);
428
429 if (is_wp_error($result)) {
430 wp_send_json_error(
431 array(
432 'mess' => $result->get_error_message(),
433 )
434 );
435 } else {
436 activate_plugin($plugin);
437 wp_send_json_success(
438 array(
439 'mess' => __('Update success', 'master-addons'),
440 'active' => $is_active,
441 )
442 );
443 }
444 }
445 }
446 } catch (\Exception $ex) {
447 wp_send_json_error(
448 array(
449 'mess' => $ex->getMessage(),
450 )
451 );
452 } catch (\Error $ex) {
453 wp_send_json_error(
454 array(
455 'mess' => $ex->getMessage(),
456 )
457 );
458 }
459 }
460 }
461 }
462