PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 3.1.8
Adminify – White Label, Admin Menu Editor, Login Customizer v3.1.8
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 / Recommended.php

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

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