PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 4.0.1.2
Adminify – White Label, Admin Menu Editor, Login Customizer v4.0.1.2
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.1.2, at Libs/Addons.php

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