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

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