PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 4.0.4.5
Adminify – White Label, Admin Menu Editor, Login Customizer v4.0.4.5
4.3.1 4.3.0 4.2.26 4.2.25 4.2.24 4.2.23 4.2.22 4.2.21 4.2.20 4.2.19 4.2.18 4.2.17 4.2.16 4.2.15 4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 4.1.17 All 164 releases
adminify / Libs / Addons.php

Addons.php in Adminify – White Label, Admin Menu Editor, Login Customizer 4.0.4.5, at Libs/Addons.php

679 lines 28.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPAdminify\Libs;
4
5 // No, Direct access Sir !!!
6 if (!defined('ABSPATH')) {
7 exit;
8 }
9
10 /*
11 * Addons global class
12 */
13
14 if (!class_exists('Addons')) {
15
16 /**
17 * Addons Class
18 *
19 * Jewel Theme <support@jeweltheme.com>
20 */
21 class Addons
22 {
23 public $menu_items = [];
24 public $plugins_list = [];
25 public $sub_menu;
26 public $menu_order;
27
28 public $server_url = 'https://coupon.wpadminify.com/';
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 = 70)
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'), 1000);
46 // add_action('network_admin_menu', array($this, 'admin_menu'), $this->menu_order);
47 add_action('wp_ajax_jltwp_adminify_addons_upgrade_plugin', array($this, 'jltwp_adminify_addons_upgrade_plugin'));
48 add_action('wp_ajax_jltwp_adminify_addons_activate_plugin', array($this, 'jltwp_adminify_addons_activate_plugin'));
49 add_action('plugins_loaded', array($this, 'maybe_replace_addons_path'), 1000); // 1000 is important
50 }
51
52 public function maybe_replace_addons_path() {
53
54 $addons = [
55 'sidebar-generator/adminify-sidebar-generator.php' => 'adminify-sidebar-generator/adminify-sidebar-generator.php'
56 ];
57
58 foreach ($addons as $old_plugin => $new_plugin) {
59
60 $old_plugin_path = WP_PLUGIN_DIR . '/' . $old_plugin;
61 $new_plugin_path = WP_PLUGIN_DIR . '/' . $new_plugin;
62
63 // Both files exist, delete the old one
64 if ( file_exists($old_plugin_path) && file_exists($new_plugin_path) ) {
65 unlink(dirname($old_plugin_path));
66 continue;
67 }
68
69 // If the old file exists and the new file doesn't exist, rename the old file to the new file
70 if ( file_exists($old_plugin_path) && !file_exists($new_plugin_path) ) {
71
72 // check if the old plugin is active
73 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
74
75 $is_active = is_plugin_active( $old_plugin );
76
77 if ( $is_active ) {
78 // Deactivate the old plugin
79 deactivate_plugins( $old_plugin );
80 // Rename the old plugin to the new plugin
81 rename( dirname($old_plugin_path), dirname($new_plugin_path) );
82
83 if ( file_exists($new_plugin_path) ) {
84 // Clear the plugin cache
85 wp_cache_delete( 'plugins', 'plugins' );
86
87 // Activate the new plugin
88 activate_plugin( $new_plugin );
89 }
90
91 } else {
92 // Rename the old plugin to the new plugin
93 rename( dirname($old_plugin_path), dirname($new_plugin_path) );
94 }
95 }
96
97 }
98
99 }
100
101 /**
102 * Includes
103 *
104 * @author Jewel Theme <support@jeweltheme.com>
105 */
106 public function includes()
107 {
108 // if (!function_exists('install_plugin_install_status')) {
109 // require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
110 require_once(ABSPATH . '/wp-load.php');
111 require_once(ABSPATH . 'wp-admin/includes/plugin-install.php');
112 require_once(ABSPATH . 'wp-admin/includes/file.php');
113 require_once(ABSPATH . 'wp-admin/includes/misc.php');
114 require_once(ABSPATH . 'wp-admin/includes/plugin.php');
115 require_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
116 // }
117 }
118
119 /**
120 * Menu Items
121 *
122 * @author Jewel Theme <support@jeweltheme.com>
123 */
124 public function menu_items()
125 {
126 return array();
127 }
128
129 /**
130 * Plugins list
131 *
132 * @author Jewel Theme <support@jeweltheme.com>
133 */
134 public function plugins_list()
135 {
136 return array();
137 }
138
139 /**
140 * Admin submenu
141 */
142 public function admin_menu()
143 {
144 }
145
146 /**
147 * Render addons plugins body
148 */
149 public function render_addons_plugins()
150 {
151 ?>
152 <div class='wp-adminify-addons-wrapper'>
153 <?php $this->header(); ?>
154 <?php $this->body(); ?>
155 </div>
156 <?php
157 }
158
159
160 /**
161 * Addons License Header Check
162 *
163 * @return void
164 */
165
166 public function jltwp_adminify_addons_check()
167 {
168
169 $license = jltwp_adminify()->_get_license();
170
171 if (!is_object($license) || !$license->is_valid() || !$license->is_active()) return;
172
173 if ( $this->is_eligible_for_coupon() ) {
174 // Get the coupon
175 $coupon = $this->maybe_create_and_get_coupon();
176 if (!empty($coupon) && !empty($coupon['code'])) {
177 echo sprintf(
178 __('<h3>Coupon Code: <strong style="color: red">%s</strong> Redeem this coupon code to get free access to all our premium addons (Except Admin Bar Editor, RoleMaster Suite and Master Addons). Learn how to <a href="https://wpadminify.com/redeem-addons-using-coupon-code/" target="_blank">redeem coupon code?</a></h3> ', 'adminify'),
179 esc_attr($coupon['code'])
180 );
181 }
182 }
183
184 echo '<style>
185 #fs_addons .fs-cards-list{ display: flex; }
186 #fs_addons .fs-cards-list .fs-card .fs-inner .fs-cta .button{
187 top: 112px;
188 right: 12px;
189 line-height: 26px !important;
190 border-radius: 3px !important;
191 }</style>';
192 }
193
194 public function is_eligible_for_coupon() {
195
196 $is_eligible = get_option('wp_adminify_addon__is_eligible_for_coupon', null);
197
198 if ( $is_eligible !== null ) return wp_validate_boolean($is_eligible);
199 $args = [
200 'license' => base64_encode(json_encode(jltwp_adminify()->_get_license())),
201 'action' => 'check_eligibility'
202 ];
203
204 $request_uri = add_query_arg($args, $this->server_url);
205
206 $response = wp_remote_get($request_uri);
207
208 if (!is_wp_error($response) && $response['response']['code'] === 200) {
209 $file_contents = wp_remote_retrieve_body($response);
210 $is_eligible = json_decode($file_contents, true);
211 update_option('wp_adminify_addon__is_eligible_for_coupon', wp_validate_boolean($is_eligible));
212 return $is_eligible;
213 }
214
215 return false;
216 }
217
218 public function maybe_delete_corrupted_coupon(){
219 $coupon_delete_check = get_option('wp_adminify_addon__coupon_is_deleted', false);
220 if($coupon_delete_check != true){
221 delete_option('wp_adminify_addon__coupon');
222 update_option('wp_adminify_addon__coupon_is_deleted', true);
223 }
224 }
225
226 public function maybe_create_and_get_coupon()
227 {
228 $this->maybe_delete_corrupted_coupon();
229 $coupon = get_option('wp_adminify_addon__coupon');
230
231 if (!empty($coupon)) return $coupon;
232
233 // communicate hit hserver get coupon
234 $args = [
235 'license' => base64_encode(json_encode(jltwp_adminify()->_get_license())),
236 'action' => 'get_coupon'
237 ];
238
239 $response = wp_remote_get(add_query_arg($args, $this->server_url));
240
241 if (!is_wp_error($response) && $response['response']['code'] === 200) {
242
243 $file_contents = wp_remote_retrieve_body($response);
244 $response_data = json_decode($file_contents, true);
245
246 if (!empty($response_data) && is_array($response_data) && !empty($response_data['id']) && !empty($response_data['code']) ) {
247 $coupon = [
248 'id' => $response_data['id'],
249 'code' => $response_data['code']
250 ];
251 update_option('wp_adminify_addon__coupon', $coupon);
252 }
253 }
254
255 return $coupon;
256 }
257
258
259 /**
260 * Header
261 */
262 public function header()
263 {
264 ?>
265 <div class='wp-adminify-addons-header'>
266 <div class='wp-adminify-addons-title'>
267 <h2>
268 <?php echo esc_html__('Add Ons for WP Adminify', 'adminify'); ?>
269 </h2>
270 <?php $this->jltwp_adminify_addons_check(); ?>
271 </div>
272 <div class='wp-adminify-addons-menu'>
273 <div class="wp-filter">
274 <ul class="filter-links">
275 <?php
276 $i = 0;
277
278 foreach ($this->menu_items as $menu) {
279 $class = str_replace(' ', '-', strtolower($menu['key']));
280 ?>
281 <li class="plugin-install-<?php echo esc_attr($class); ?>">
282 <a href="#" class="<?php echo esc_attr(0 === $i ? 'current' : ''); ?>" data-type="<?php echo esc_attr($menu['key']); ?>"><?php echo esc_html($menu['label']); ?></a>
283 </li>
284 <?php
285 ++$i;
286 }
287 ?>
288 </ul>
289
290 <form class="search-form wp-adminify-search-plugins mr-0" method="get">
291 <input type="hidden" name="tab" value="search">
292 <label class="screen-reader-text" for="search-plugins">
293 <?php echo esc_html__('Search Plugins', 'adminify'); ?>
294 </label>
295 <input type="search" name="s" id="search-plugins" value="" class="wp-filter-search" placeholder="<?php echo esc_html__('Search plugins...', 'adminify'); ?>">
296 <input type="submit" id="search-submit" class="button hide-if-js" value="<?php echo esc_html__('Search Plugins', 'adminify'); ?>">
297 </form>
298 </div>
299 </div>
300 </div>
301 <?php
302 }
303
304 /**
305 * Body
306 */
307 public function body()
308 {
309 ?>
310 <div class="wp-list-table widefat plugin-install">
311 <div id="the-list">
312 <?php
313 $this->plugins();
314 ?>
315 </div>
316 </div>
317 <?php
318 }
319
320 /**
321 * Body
322 */
323 public function plugins()
324 {
325
326 foreach ($this->plugins_list as $key => $plugin) {
327 $install_status = \install_plugin_install_status($plugin);
328 $classes = implode(' ', $plugin['type']);
329
330 $more_details = self_admin_url(
331 'plugin-install.php?tab=plugin-information&amp;plugin=' . esc_attr($plugin['slug']) .
332 '&amp;TB_iframe=true&amp;width=600&amp;height=550'
333 );
334
335 ?>
336 <div class="plugin-card plugin-card-<?php echo esc_attr($key); ?> <?php echo esc_attr($classes); ?>">
337 <div class="plugin-card-top">
338 <div class="name column-name">
339 <h3>
340 <a href="<?php echo esc_url($more_details); ?>" class="thickbox open-plugin-details-modal">
341 <?php echo esc_html($plugin['name']); ?>
342 <img src="<?php echo esc_url($plugin['icon']); ?>" class="plugin-icon" alt="">
343 </a>
344 </h3>
345 </div>
346 <div class="desc column-description">
347 <p><?php echo wp_kses_post($plugin['short_description']); ?></p>
348 </div>
349 <!-- Hover Popup -->
350 <?php if( !empty($plugin['pricing_url']) || !empty($plugin['view_details']) ) { ?>
351 <div class="adminify-plugin-details">
352 <?php if( !empty($plugin['view_details']) ) { ?>
353 <a href="<?php echo esc_url($plugin['view_details']); ?>" target="_blank" class="adminify-view-details"><?php echo esc_html__('View Details', 'adminify'); ?></a>
354 <?php } ?>
355
356 <?php if( !empty($plugin['pricing_url']) ) { ?>
357 <a href="<?php echo esc_url($plugin['pricing_url']); ?>" target="_blank"><?php echo esc_html__('Buy Now', 'adminify'); ?></a>
358 <?php } ?>
359 </div>
360 <?php } ?>
361 </div>
362 <div class="plugin-card-bottom">
363 <div class="column-downloaded">
364 <span class="plugin-status">
365 <?php
366 echo esc_html__('Status:', 'adminify');
367
368 if ('install' === $install_status['status']) {
369 ?>
370 <span class="plugin-status-not-install" data-plugin-url="<?php echo esc_attr($plugin['download_link']); ?>"><?php echo esc_html__('No Installed', 'adminify'); ?></span>
371 <?php
372 } elseif ('update_available' === $install_status['status']) {
373 if (is_plugin_active($install_status['file'])) {
374 ?>
375 <span class="plugin-status-active">
376 <?php echo esc_html__('Active', 'adminify'); ?>
377 </span>
378 <?php
379 } else {
380 ?>
381 <span class="plugin-status-inactive" data-plugin-file="<?php echo esc_attr(esc_attr($install_status['file'])); ?>">
382 <?php echo esc_html__('Inactive', 'adminify'); ?>
383 </span>
384 <?php
385 }
386 } elseif (('latest_installed' === $install_status['status']) || ('newer_installed' === $install_status['status'])) {
387 if (is_plugin_active($install_status['file'])) {
388 ?>
389 <span class="plugin-status-active">
390 <?php echo esc_html__('Active', 'adminify'); ?>
391 </span>
392 <?php
393 } elseif (current_user_can('activate_plugin', $install_status['file'])) {
394 ?>
395 <span class="plugin-status-inactive" data-plugin-file="<?php echo esc_attr($install_status['file']); ?>">
396 <?php echo esc_html__('Inactive', 'adminify'); ?>
397 </span>
398 <?php
399 } else {
400 ?>
401 <span class="plugin-status-inactive" data-plugin-file="<?php echo esc_attr($install_status['file']); ?>">
402 <?php echo esc_html__('Inactive', 'adminify'); ?>
403 </span>
404 <?php
405 }
406 }
407 ?>
408 </span>
409 </div>
410 <div class="column-compatibility">
411 <ul class="plugin-action-buttons">
412 <?php
413 if ('install' === $install_status['status']) {
414 ?>
415 <li>
416 <button class="install-now adminify-btn adminify-btn-outline-primary" data-install-url="<?php echo esc_attr($plugin['download_link']); ?>">
417 <?php echo esc_html__('Install Now', 'adminify'); ?>
418 </button>
419 </li>
420 <?php
421 } elseif ('update_available' === $install_status['status']) {
422 ?>
423 <li class="mr-0">
424 <button class="update-now button" 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']); ?>">
425 <?php echo esc_html__('Update Now', 'adminify'); ?>
426 </button>
427 </li>
428 <?php
429 } elseif (('latest_installed' === $install_status['status']) || ('newer_installed' === $install_status['status'])) {
430 if (is_plugin_active($install_status['file'])) {
431 ?>
432 <li class="mr-0">
433 <button type="button" class="adminify-btn adminify-btn-success" disabled="disabled">
434 <?php echo esc_html__('Activated', 'adminify'); ?>
435 </button>
436 </li>
437 <?php
438 } elseif (current_user_can('activate_plugin', $install_status['file'])) {
439 ?>
440 <button class="button activate-now" data-plugin-file="<?php echo esc_attr($install_status['file']); ?>">
441 <?php echo esc_html__('Activate Now', 'adminify'); ?>
442 </button>
443 <?php
444 } else {
445 ?>
446 <li class="mr-0">
447 <button type="button" class="button button-disabled" disabled="disabled">
448 <?php echo esc_html__('Installed', 'adminify'); ?>
449 </button>
450 </li>
451 <?php
452 }
453 }
454 ?>
455 </ul>
456 </div>
457 </div>
458 </div>
459 <?php
460 }
461 }
462
463 /**
464 * Activate Plugins
465 *
466 * @author Jewel Theme <support@jeweltheme.com>
467 */
468 public function jltwp_adminify_addons_activate_plugin()
469 {
470 if (empty($_POST['plugin'])) {
471 return;
472 }
473 try {
474 $nonce = isset($_POST['nonce']) ? sanitize_text_field(wp_unslash($_POST['nonce'])) : '';
475
476 if (!wp_verify_nonce($nonce, 'jltwp_adminify_addons_nonce')) {
477 wp_send_json_error(array('mess' => __('Nonce is invalid', 'adminify')));
478 }
479
480 // if ((is_multisite() && !is_network_admin()) || !current_user_can('install_plugins')) {
481 // wp_send_json_error(array('mess' => __('Invalid access', 'adminify')));
482 // }
483
484 $plugin = sanitize_text_field(wp_unslash($_POST['plugin']));
485 $plugin_links = array_values(wp_list_pluck($this->plugins_list, 'slug'));
486
487 if (!in_array(dirname($plugin), $plugin_links)) {
488 wp_send_json_error(array('mess' => __('Invalid plugin', 'adminify')));
489 }
490
491 $result = activate_plugin($plugin);
492
493 if (is_wp_error($result)) {
494 wp_send_json_error(
495 array(
496 'mess' => $result->get_error_message(),
497 )
498 );
499 }
500 wp_send_json_success(
501 array(
502 'mess' => __('Activate success', 'adminify'),
503 )
504 );
505 } catch (\Exception $ex) {
506 wp_send_json_error(
507 array(
508 'mess' => __('Error exception.', 'adminify'),
509 array(
510 'error' => $ex,
511 ),
512 )
513 );
514 } catch (\Error $ex) {
515 wp_send_json_error(
516 array(
517 'mess' => __('Error.', 'adminify'),
518 array(
519 'error' => $ex,
520 ),
521 )
522 );
523 }
524 }
525
526 public function get_the_plugin_slug( $plugin ) {
527
528 // If the plugin is like myplugin/myplugin.php
529 if ( ! filter_var($plugin, FILTER_VALIDATE_URL) ) {
530 return dirname($plugin);
531 }
532
533 // If the plugin is from wordpress.org
534 if ( false !== strpos( $plugin, 'https://downloads.wordpress.org/plugin/' ) ) {
535 $plugin = str_replace( 'https://downloads.wordpress.org/plugin/', '', $plugin );
536 return str_replace( '.zip', '', $plugin );
537 }
538
539 // If the plugin is from local store
540 $plugin = explode( 'plugin_slug=', $plugin );
541 $plugin = explode( '&', $plugin[1] );
542 return $plugin[0];
543 }
544
545 /**
546 * Upgrade Plugins required Libraries
547 *
548 * @author Jewel Theme <support@jeweltheme.com>
549 */
550 public function jltwp_adminify_addons_upgrade_plugin()
551 {
552 if (empty($_POST['plugin'])) {
553 return;
554 }
555
556 try {
557 require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
558 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
559 require_once ABSPATH . 'wp-admin/includes/class-wp-ajax-upgrader-skin.php';
560 require_once ABSPATH . 'wp-admin/includes/class-plugin-upgrader.php';
561
562 $nonce = isset($_POST['nonce']) ? sanitize_text_field(wp_unslash($_POST['nonce'])) : '';
563
564 if (!wp_verify_nonce($nonce, 'jltwp_adminify_addons_nonce')) {
565 wp_send_json_error(array('mess' => __('Nonce is invalid', 'adminify')));
566 }
567
568 // if ((is_multisite() && !is_network_admin()) || !current_user_can('install_plugins')) {
569 // wp_send_json_error(array('mess' => __('Invalid access', 'adminify')));
570 // }
571
572 $plugin = sanitize_text_field(wp_unslash($_POST['plugin']));
573
574 $plugin_slug = $this->get_the_plugin_slug( $plugin );
575
576 if ( ! array_key_exists( $plugin_slug, $this->plugins_list) ) {
577 wp_send_json_error(array('mess' => __('Invalid plugin', 'adminify')));
578 }
579
580 $type = isset($_POST['type']) ? sanitize_text_field(wp_unslash($_POST['type'])) : 'install';
581 $skin = new \WP_Ajax_Upgrader_Skin();
582 $upgrader = new \Plugin_Upgrader($skin);
583
584 if ('install' === $type) {
585
586 $result = $upgrader->install($plugin);
587
588 if (empty($result) || empty($upgrader->result)) {
589 wp_send_json_error(
590 array(
591 'mess' => 'Something is wrong',
592 )
593 );
594 }
595
596 if (is_wp_error($result)) {
597 wp_send_json_error(
598 array(
599 'mess' => $result->get_error_message(),
600 )
601 );
602 }
603
604 $plugins = get_plugins('/' . $upgrader->result['destination_name']);
605 $plugin_data = end($plugins);
606 $plugin_data['slug'] = $upgrader->result['destination_name'];
607 $plugin_data['version'] = $plugin_data['Version'];
608
609 if (!empty($plugin_data) && !is_wp_error($plugin_data)) {
610
611 $install_status = \install_plugin_install_status($plugin_data);
612
613 $active_plugin = activate_plugin($install_status['file']);
614
615 if (is_wp_error($active_plugin)) {
616 wp_send_json_error(
617 array(
618 'mess' => $active_plugin->get_error_message(),
619 )
620 );
621 } else {
622 wp_send_json_success(
623 array(
624 'mess' => __('Install success', 'adminify'),
625 )
626 );
627 }
628 } else {
629
630 wp_send_json_error(
631 array(
632 'mess' => 'Error',
633 )
634 );
635 }
636 } else {
637
638 $is_active = is_plugin_active($plugin);
639 $result = $upgrader->upgrade($plugin);
640
641 if ( empty($result) || is_wp_error($result) ) {
642 wp_send_json_error(
643 array(
644 'mess' => is_wp_error($result) ? $result->get_error_message() : __('Couldn\'t upgrade', 'adminify')
645 )
646 );
647 }
648
649 $active_status = activate_plugin($plugin);
650
651 if ( empty($active_status) || is_wp_error($active_status) ) {
652 wp_send_json_error(
653 array(
654 'mess' => is_wp_error($result) ? $result->get_error_message() : __('Activation Failed', 'adminify')
655 )
656 );
657 }
658
659 wp_send_json_success(
660 array(
661 'mess' => __('Update success', 'adminify'),
662 'active' => true,
663 )
664 );
665 }
666 } catch (\Exception $ex) {
667 wp_send_json_error(
668 array(
669 'mess' => __('Error exception.', 'adminify'),
670 array(
671 'error' => $ex,
672 ),
673 )
674 );
675 }
676 }
677 }
678 }
679