PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 4.0.7
Adminify – White Label, Admin Menu Editor, Login Customizer v4.0.7
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
← All changes | Libs/Addons.php +191 -201 4.2.54.0.7 View file →
@@ -1,7 +1,7 @@
1 1 <?php
2 2
3 -namespace PXLBSAdminify\Libs;
3 +namespace WPAdminify\Libs;
4 4
5 5 // No, Direct access Sir !!!
6 6 if (!defined('ABSPATH')) {
7 7 exit;
@@ -24,9 +24,11 @@
24 24 public $plugins_list = [];
25 25 public $sub_menu;
26 26 public $menu_order;
27 27
28 + public $server_url = 'https://coupon.wpadminify.com/';
28 29
30 +
29 31 /**
30 32 * Constructor method
31 33 *
32 34 * @param integer $menu_order .
@@ -39,82 +41,56 @@
39 41 $this->plugins_list = $this->plugins_list();
40 42
41 43 $this->includes();
42 44
43 - // Show Addons menu only on network admin for multisite, or on regular admin for single site
44 - if ( is_multisite() ) {
45 - add_action('network_admin_menu', array($this, 'admin_menu'), 1000);
46 - } else {
47 - add_action('admin_menu', array($this, 'admin_menu'), 1000);
48 - }
49 - add_action('wp_ajax_pxlbsadminify_addons_upgrade_plugin', array($this, 'pxlbsadminify_addons_upgrade_plugin'));
50 - add_action('wp_ajax_pxlbsadminify_addons_activate_plugin', array($this, 'pxlbsadminify_addons_activate_plugin'));
51 - // Notify the site admin when a renamed legacy addon is detected
52 - // alongside its replacement. Per WordPress.org plugin guidelines,
53 - // we must not deactivate or activate plugins automatically; the
54 - // user has to perform the swap themselves from the Plugins screen.
55 - add_action('admin_notices', array($this, 'maybe_renamed_addon_notice'));
56 - add_action( 'rest_api_init', array( $this , 'addons_rest_routes') );
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 + add_action( 'rest_api_init', array( $this , 'jltwp_adminify_addons_rest_routes') );
57 51 }
58 52
59 - public function addons_rest_routes() {
53 + public function jltwp_adminify_addons_rest_routes() {
60 54 register_rest_route('adminify/v1', '/get-addons-list', array(
61 55 'methods' => 'GET',
62 - 'callback' => [$this, 'get_addons_plugins_list'],
63 - 'permission_callback' => [$this, 'check_is_admin_user'],
56 + 'callback' => [$this, 'jltwp_adminify_get_addons_plugins_list'],
57 + // 'permission_callback' => [$this, 'adminify_is_admin_user'],
58 + 'permission_callback' => '__return_true',
64 59 ));
65 60
66 61 register_rest_route('adminify/v1', '/install-addons', array(
67 62 'methods' => 'POST',
68 - 'callback' => [$this, 'install_addons'],
69 - 'permission_callback' => [$this, 'check_verify_nonce_and_permissions'],
63 + 'callback' => [$this, 'jltwp_adminify_install_addons'],
64 + 'permission_callback' => [$this, 'adminify_verify_nonce_and_permissions'],
70 65 ));
71 66 }
72 67
73 - public function check_is_admin_user() {
74 - if ( is_multisite() && ! is_super_admin() ) {
75 - return new \WP_Error('rest_forbidden', __('You are not allowed to access this resource.', 'adminify'), array('status' => 403));
76 - }
68 + public function adminify_is_admin_user() {
69 + return current_user_can('manage_options');
70 + }
71 +
72 + public function adminify_verify_nonce_and_permissions() {
73 + // Check user
77 74 if ( ! current_user_can('manage_options') ) {
78 - return new \WP_Error('rest_forbidden', __('You are not allowed to access this resource.', 'adminify'), array('status' => 403));
75 + return new WP_Error('forbidden', 'You are not allowed to do this.', array('status' => 403));
79 76 }
80 - return true;
81 - }
82 77
83 - public function check_verify_nonce_and_permissions() {
84 - // The install-addons endpoint may both install AND activate
85 - // addons depending on each addon's current status, so the
86 - // caller must hold BOTH capabilities. On multisite this also
87 - // requires super admin.
78 + // Check nonce from header
79 + $nonce = $_SERVER['HTTP_X_WP_NONCE'] ?? '';
80 + if ( ! wp_verify_nonce($nonce, 'wp_rest') ) {
81 + return new WP_Error('rest_cookie_invalid_nonce', __('Invalid nonce.'), array('status' => 403));
82 + }
88 83 if ( is_multisite() && ! is_super_admin() ) {
89 - return new \WP_Error('rest_forbidden', __('Super admin required.', 'adminify'), array('status' => 403));
84 + return new WP_Error('not_allowed', 'Super admin only on multisite.', array('status' => 403));
90 85 }
91 - if ( ! current_user_can('install_plugins') ) {
92 - return new \WP_Error('rest_forbidden', __('You are not allowed to install plugins.', 'adminify'), array('status' => 403));
93 - }
94 - if ( ! current_user_can('activate_plugins') ) {
95 - return new \WP_Error('rest_forbidden', __('You are not allowed to activate plugins.', 'adminify'), array('status' => 403));
96 - }
97 86
98 - // Nonce check from header. Sanitize and unslash before verifying.
99 - $nonce = isset($_SERVER['HTTP_X_WP_NONCE'])
100 - ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_WP_NONCE'] ) )
101 - : '';
102 - if ( ! wp_verify_nonce( $nonce, 'wp_rest' ) ) {
103 - return new \WP_Error('rest_cookie_invalid_nonce', __('Invalid nonce.', 'adminify'), array('status' => 403));
104 - }
105 -
106 87 return true;
107 88 }
108 89
109 90
110 - public function get_addons_plugins_list() {
111 - // Fetch the catalogue on demand. This callback only runs on the
112 - // Add-ons page (a user action), so the remote request is not made on
113 - // routine admin page loads.
114 - $plugins = ( method_exists( $this, 'get_adminify_plugins_lists' ) )
115 - ? (array) $this->get_adminify_plugins_lists()
116 - : (array) $this->plugins_list;
91 + public function jltwp_adminify_get_addons_plugins_list() {
92 + $plugins = $this->plugins_list;
117 93 unset($plugins['master-addons']);
118 94 $all_plugins = get_plugins();
119 95 $active_plugins = get_option('active_plugins');
120 96 foreach( $plugins as $slug => $plugin){
@@ -136,123 +112,101 @@
136 112
137 113 }
138 114
139 115
140 - public function install_addons( $request ) {
141 - $addons = $request->get_param('addons');
142 - if ( empty($addons) || ! is_array($addons) ) {
143 - return new \WP_Error('no_addons', __('No addons were selected.', 'adminify'), array('status' => 400));
116 + public function jltwp_adminify_install_addons( $request ) {
117 + $addons = $request->get_param('addons');
118 + if ( empty($addons) || !is_array($addons) ) {
119 + return new WP_Error('no_addons', 'No addons were selected.', array('status' => 400));
144 120 }
145 121
146 - $plugins_list = $this->get_addons_plugins_list()->data;
147 - foreach( $addons as $key => $plugin ) {
148 - $plugin = sanitize_key( $plugin );
149 - if ( ! isset( $plugins_list[ $plugin ] ) ) {
122 + $plugins_list = $this->jltwp_adminify_get_addons_plugins_list()->data;
123 + foreach( $addons as $key => $plugin ){
124 + if($plugins_list[$plugin]['status'] == "activated") continue;
125 + if($plugins_list[$plugin]['status'] == "installed") {
126 + $this->jltwp_adminify_activate_plugin_by_slug($plugin);
150 127 continue;
151 128 }
152 - if ( $plugins_list[ $plugin ]['status'] === 'activated' ) {
153 - continue;
154 - }
155 - if ( $plugins_list[ $plugin ]['status'] === 'installed' ) {
156 - $this->activate_plugin_by_slug( $plugin );
157 - continue;
158 - }
159 129 $params = [
160 130 'request_type' => 'rest',
161 - 'plugin' => $plugins_list[ $plugin ]['download_link'],
131 + 'plugin' => $plugins_list[$plugin]['download_link'],
162 132 ];
163 133
164 - $this->pxlbsadminify_addons_upgrade_plugin( $params );
134 + $this->jltwp_adminify_addons_upgrade_plugin($params);
165 135 }
166 -
167 - return rest_ensure_response(['message' => __('Addons processed.', 'adminify'), 'addons' => $addons]);
136 +
137 + return rest_ensure_response(['message' => 'Addons installed', 'addons' => $addons]);
168 138 }
169 139
170 - function activate_plugin_by_slug($slug) {
171 - // Activation requires the activate_plugins capability in
172 - // addition to whatever capability gated the calling endpoint.
173 - // On multisite, activation must be performed by a super admin.
174 - if ( is_multisite() && ! is_super_admin() ) {
175 - return new \WP_Error( 'rest_forbidden', __( 'Super admin required to activate plugins.', 'adminify' ), array( 'status' => 403 ) );
176 - }
177 - if ( ! current_user_can( 'activate_plugins' ) ) {
178 - return new \WP_Error( 'rest_forbidden', __( 'You are not allowed to activate plugins.', 'adminify' ), array( 'status' => 403 ) );
179 - }
180 -
181 - // Reject any slug containing path separators / traversal so
182 - // $slug cannot escape WP_PLUGIN_DIR.
183 - if ( ! is_string( $slug ) || $slug === '' || strpbrk( $slug, "/\\" ) !== false || strpos( $slug, '..' ) !== false ) {
184 - return new \WP_Error( 'invalid_slug', __( 'Invalid plugin slug.', 'adminify' ), array( 'status' => 400 ) );
185 - }
186 -
187 - // Slug must be present in the trusted addons list.
188 - if ( ! array_key_exists( $slug, (array) $this->plugins_list ) ) {
189 - return new \WP_Error( 'invalid_slug', __( 'Invalid plugin slug.', 'adminify' ), array( 'status' => 400 ) );
190 - }
191 -
140 + function jltwp_adminify_activate_plugin_by_slug($slug) {
192 141 $plugin_path = WP_PLUGIN_DIR . '/' . $slug;
193 142
194 - if ( ! is_dir( $plugin_path ) ) {
143 + if (!is_dir($plugin_path)) {
195 144 return;
196 145 }
197 146
198 - $installed_plugins = get_plugins( '/' . $slug );
199 - if ( empty( $installed_plugins ) ) {
147 + $plugin_files = glob("$plugin_path/*.php");
148 + if (!$plugin_files || empty($plugin_files)) {
200 149 return;
201 150 }
202 151
203 - $plugin_relative_path = $slug . '/' . key( $installed_plugins );
152 + $main_plugin_file = basename($plugin_files[0]);
153 + $plugin_relative_path = $slug . '/' . $main_plugin_file;
204 154
205 - if ( is_plugin_active( $plugin_relative_path ) ) {
155 + if (is_plugin_active($plugin_relative_path)) {
206 156 return;
207 157 }
208 158
209 - activate_plugin( $plugin_relative_path );
159 + activate_plugin($plugin_relative_path);
210 160 }
211 161
212 - /**
213 - * Map of legacy addon slugs that have been renamed to a new slug.
214 - *
215 - * @return array<string,string>
216 - */
217 - protected function renamed_addons_map() {
218 - return [
219 - 'sidebar-generator/adminify-sidebar-generator.php' => 'adminify-sidebar-generator/adminify-sidebar-generator.php',
162 + public function maybe_replace_addons_path() {
163 +
164 + $addons = [
165 + 'sidebar-generator/adminify-sidebar-generator.php' => 'adminify-sidebar-generator/adminify-sidebar-generator.php'
220 166 ];
221 - }
222 167
223 - /**
224 - * Show a non-blocking admin notice if a legacy (renamed) addon is
225 - * still installed. We never deactivate or activate plugins on the
226 - * user's behalf; the notice points them to the Plugins screen so
227 - * they can perform the swap themselves.
228 - */
229 - public function maybe_renamed_addon_notice() {
230 - if ( ! current_user_can('activate_plugins') ) {
231 - return;
232 - }
168 + foreach ($addons as $old_plugin => $new_plugin) {
233 169
234 - $messages = [];
170 + $old_plugin_path = WP_PLUGIN_DIR . '/' . $old_plugin;
171 + $new_plugin_path = WP_PLUGIN_DIR . '/' . $new_plugin;
235 172
236 - foreach ($this->renamed_addons_map() as $old_plugin => $new_plugin) {
237 - $old_exists = file_exists(WP_PLUGIN_DIR . '/' . $old_plugin);
238 - if ( ! $old_exists ) {
173 + // Both files exist, delete the old one
174 + if ( file_exists($old_plugin_path) && file_exists($new_plugin_path) ) {
175 + unlink(dirname($old_plugin_path));
239 176 continue;
240 177 }
241 178
242 - $messages[] = sprintf(
243 - /* translators: 1: old plugin slug, 2: new plugin slug */
244 - esc_html__('"%1$s" has been renamed to "%2$s". Please deactivate and remove the old version, then install the new one from the Adminify Addons screen.', 'adminify'),
245 - esc_html(dirname($old_plugin)),
246 - esc_html(dirname($new_plugin))
247 - );
248 - }
179 + // If the old file exists and the new file doesn't exist, rename the old file to the new file
180 + if ( file_exists($old_plugin_path) && !file_exists($new_plugin_path) ) {
249 181
250 - if ( empty($messages) ) {
251 - return;
182 + // check if the old plugin is active
183 + include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
184 +
185 + $is_active = is_plugin_active( $old_plugin );
186 +
187 + if ( $is_active ) {
188 + // Deactivate the old plugin
189 + deactivate_plugins( $old_plugin );
190 + // Rename the old plugin to the new plugin
191 + rename( dirname($old_plugin_path), dirname($new_plugin_path) );
192 +
193 + if ( file_exists($new_plugin_path) ) {
194 + // Clear the plugin cache
195 + wp_cache_delete( 'plugins', 'plugins' );
196 +
197 + // Activate the new plugin
198 + activate_plugin( $new_plugin );
199 + }
200 +
201 + } else {
202 + // Rename the old plugin to the new plugin
203 + rename( dirname($old_plugin_path), dirname($new_plugin_path) );
204 + }
205 + }
206 +
252 207 }
253 208
254 - echo '<div class="notice notice-warning"><p><strong>' . esc_html__('Adminify', 'adminify') . ':</strong> ' . esc_html(implode('<br>', $messages)) . '</p></div>';
255 209 }
256 210
257 211 /**
258 212 * Includes
@@ -260,18 +214,17 @@
260 214 * @author Jewel Theme <support@jeweltheme.com>
261 215 */
262 216 public function includes()
263 217 {
264 - // wp-load.php must never be required from within a plugin: the
265 - // plugin already runs inside WordPress. The wp-admin includes
266 - // below are required for plugin install/upgrade APIs used by
267 - // this class and are loaded with require_once immediately
268 - // before the functions from each file are called.
269 - require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
270 - require_once ABSPATH . 'wp-admin/includes/file.php';
271 - require_once ABSPATH . 'wp-admin/includes/misc.php';
272 - require_once ABSPATH . 'wp-admin/includes/plugin.php';
273 - require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
218 + // if (!function_exists('install_plugin_install_status')) {
219 + // require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
220 + require_once(ABSPATH . '/wp-load.php');
221 + require_once(ABSPATH . 'wp-admin/includes/plugin-install.php');
222 + require_once(ABSPATH . 'wp-admin/includes/file.php');
223 + require_once(ABSPATH . 'wp-admin/includes/misc.php');
224 + require_once(ABSPATH . 'wp-admin/includes/plugin.php');
225 + require_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
226 + // }
274 227 }
275 228
276 229 /**
277 230 * Menu Items
@@ -319,10 +272,26 @@
319 272 *
320 273 * @return void
321 274 */
322 275
323 - public function addons_check()
276 + public function jltwp_adminify_addons_check()
324 277 {
278 +
279 + $license = jltwp_adminify()->_get_license();
280 +
281 + if (!is_object($license) || !$license->is_valid() || !$license->is_active()) return;
282 +
283 + if ( $this->is_eligible_for_coupon() ) {
284 + // Get the coupon
285 + $coupon = $this->maybe_create_and_get_coupon();
286 + if (!empty($coupon) && !empty($coupon['code'])) {
287 + echo sprintf(
288 + __('<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'),
289 + esc_attr($coupon['code'])
290 + );
291 + }
292 + }
293 +
325 294 echo '<style>
326 295 #fs_addons .fs-cards-list{ display: flex; }
327 296 #fs_addons .fs-cards-list .fs-card .fs-inner .fs-cta .button{
328 297 top: 112px;
@@ -331,10 +300,73 @@
331 300 border-radius: 3px !important;
332 301 }</style>';
333 302 }
334 303
304 + public function is_eligible_for_coupon() {
335 305
306 + $is_eligible = get_option('wp_adminify_addon__is_eligible_for_coupon', null);
336 307
308 + if ( $is_eligible !== null ) return wp_validate_boolean($is_eligible);
309 + $args = [
310 + 'license' => base64_encode(json_encode(jltwp_adminify()->_get_license())),
311 + 'action' => 'check_eligibility'
312 + ];
313 +
314 + $request_uri = add_query_arg($args, $this->server_url);
315 +
316 + $response = wp_remote_get($request_uri);
317 +
318 + if (!is_wp_error($response) && $response['response']['code'] === 200) {
319 + $file_contents = wp_remote_retrieve_body($response);
320 + $is_eligible = json_decode($file_contents, true);
321 + update_option('wp_adminify_addon__is_eligible_for_coupon', wp_validate_boolean($is_eligible));
322 + return $is_eligible;
323 + }
324 +
325 + return false;
326 + }
327 +
328 + public function maybe_delete_corrupted_coupon(){
329 + $coupon_delete_check = get_option('wp_adminify_addon__coupon_is_deleted', false);
330 + if($coupon_delete_check != true){
331 + delete_option('wp_adminify_addon__coupon');
332 + update_option('wp_adminify_addon__coupon_is_deleted', true);
333 + }
334 + }
335 +
336 + public function maybe_create_and_get_coupon()
337 + {
338 + $this->maybe_delete_corrupted_coupon();
339 + $coupon = get_option('wp_adminify_addon__coupon');
340 +
341 + if (!empty($coupon)) return $coupon;
342 +
343 + // communicate hit hserver get coupon
344 + $args = [
345 + 'license' => base64_encode(json_encode(jltwp_adminify()->_get_license())),
346 + 'action' => 'get_coupon'
347 + ];
348 +
349 + $response = wp_remote_get(add_query_arg($args, $this->server_url));
350 +
351 + if (!is_wp_error($response) && $response['response']['code'] === 200) {
352 +
353 + $file_contents = wp_remote_retrieve_body($response);
354 + $response_data = json_decode($file_contents, true);
355 +
356 + if (!empty($response_data) && is_array($response_data) && !empty($response_data['id']) && !empty($response_data['code']) ) {
357 + $coupon = [
358 + 'id' => $response_data['id'],
359 + 'code' => $response_data['code']
360 + ];
361 + update_option('wp_adminify_addon__coupon', $coupon);
362 + }
363 + }
364 +
365 + return $coupon;
366 + }
367 +
368 +
337 369 /**
338 370 * Header
339 371 */
340 372 public function header()
@@ -342,11 +374,11 @@
342 374 ?>
343 375 <div class='wp-adminify-addons-header'>
344 376 <div class='wp-adminify-addons-title'>
345 377 <h2>
346 - <?php echo esc_html__('Add Ons for Adminify', 'adminify'); ?>
378 + <?php echo esc_html__('Add Ons for WP Adminify', 'adminify'); ?>
347 379 </h2>
348 - <?php $this->addons_check(); ?>
380 + <?php $this->jltwp_adminify_addons_check(); ?>
349 381 </div>
350 382 <div class='wp-adminify-addons-menu'>
351 383 <div class="wp-filter">
352 384 <ul class="filter-links">
@@ -399,19 +431,10 @@
399 431 * Body
400 432 */
401 433 public function plugins()
402 434 {
403 - // $this->plugins_list is populated at construction only from the
404 - // cached catalogue, which is empty until a live fetch runs. The
405 - // Add-ons page render is itself an explicit user action, so fall
406 - // back to the bundled catalogue here so the cards always show.
407 - $plugins_list = $this->plugins_list;
408 435
409 - if ( empty( $plugins_list ) && method_exists( $this, 'get_adminify_plugins_lists' ) ) {
410 - $plugins_list = (array) $this->get_adminify_plugins_lists();
411 - }
412 -
413 - foreach ($plugins_list as $key => $plugin) {
436 + foreach ($this->plugins_list as $key => $plugin) {
414 437 $install_status = \install_plugin_install_status($plugin);
415 438 $classes = implode(' ', $plugin['type']);
416 439
417 440 $more_details = self_admin_url(
@@ -551,9 +574,9 @@
551 574 * Activate Plugins
552 575 *
553 576 * @author Jewel Theme <support@jeweltheme.com>
554 577 */
555 - public function pxlbsadminify_addons_activate_plugin()
578 + public function jltwp_adminify_addons_activate_plugin()
556 579 {
557 580 if (empty($_POST['plugin'])) {
558 581 return;
559 582 }
@@ -559,9 +582,9 @@
559 582 }
560 583 try {
561 584 $nonce = isset($_POST['nonce']) ? sanitize_text_field(wp_unslash($_POST['nonce'])) : '';
562 585
563 - if (!wp_verify_nonce($nonce, 'pxlbsadminify_addons_nonce')) {
586 + if (!wp_verify_nonce($nonce, 'jltwp_adminify_addons_nonce')) {
564 587 wp_send_json_error(array('mess' => __('Nonce is invalid', 'adminify')));
565 588 }
566 589
567 590 // Security check - only administrators can activate plugins
@@ -571,23 +594,12 @@
571 594
572 595 $plugin = sanitize_text_field(wp_unslash($_POST['plugin']));
573 596 $plugin_links = array_values(wp_list_pluck($this->plugins_list, 'slug'));
574 597
575 - if (!in_array(dirname($plugin), $plugin_links, true)) {
598 + if (!in_array(dirname($plugin), $plugin_links)) {
576 599 wp_send_json_error(array('mess' => __('Invalid plugin', 'adminify')));
577 600 }
578 601
579 - // Resolve against the list of actually installed plugins so that
580 - // only a known plugin file is ever passed to activate_plugin().
581 - if (!function_exists('get_plugins')) {
582 - require_once ABSPATH . 'wp-admin/includes/plugin.php';
583 - }
584 - $installed_plugins = array_keys(get_plugins());
585 -
586 - if (!in_array($plugin, $installed_plugins, true)) {
587 - wp_send_json_error(array('mess' => __('Invalid plugin', 'adminify')));
588 - }
589 -
590 602 $result = activate_plugin($plugin);
591 603
592 604 if (is_wp_error($result)) {
593 605 wp_send_json_error(
@@ -645,9 +657,9 @@
645 657 * Upgrade Plugins required Libraries
646 658 *
647 659 * @author Jewel Theme <support@jeweltheme.com>
648 660 */
649 - public function pxlbsadminify_addons_upgrade_plugin( $params = null )
661 + public function jltwp_adminify_addons_upgrade_plugin( $params = null )
650 662 {
651 663 if ($params == null && empty($_POST['plugin'])) {
652 664 return;
653 665 }
@@ -660,9 +672,9 @@
660 672
661 673 if($params == null){
662 674 $nonce = isset($_POST['nonce']) ? sanitize_text_field(wp_unslash($_POST['nonce'])) : '';
663 675
664 - if (!wp_verify_nonce($nonce, 'pxlbsadminify_addons_nonce')) {
676 + if (!wp_verify_nonce($nonce, 'jltwp_adminify_addons_nonce')) {
665 677 wp_send_json_error(array('mess' => __('Nonce is invalid', 'adminify')));
666 678 }
667 679 $plugin = sanitize_text_field(wp_unslash($_POST['plugin']));
668 680 }else{
@@ -675,20 +687,12 @@
675 687 }
676 688
677 689 $plugin_slug = $this->get_the_plugin_slug( $plugin );
678 690
679 - if ( ! array_key_exists( $plugin_slug, $this->plugins_list ) ) {
691 + if ( ! array_key_exists( $plugin_slug, $this->plugins_list) ) {
680 692 wp_send_json_error(array('mess' => __('Invalid plugin', 'adminify')));
681 693 }
682 -
683 - // Replace the user-supplied $plugin value with values derived
684 - // from our trusted internal addons list, so that arbitrary
685 - // input never reaches Plugin_Upgrader::install()/upgrade() or
686 - // activate_plugin().
687 - $trusted_install_source = isset($this->plugins_list[$plugin_slug]['download_link'])
688 - ? $this->plugins_list[$plugin_slug]['download_link']
689 - : '';
690 -
694 +
691 695 if($params == null){
692 696 $type = isset($_POST['type']) ? sanitize_text_field(wp_unslash($_POST['type'])) : 'install';
693 697 }else{
694 698 $type = 'install';
@@ -697,13 +701,9 @@
697 701 $upgrader = new \Plugin_Upgrader($skin);
698 702
699 703 if ('install' === $type) {
700 704
701 - if ( empty( $trusted_install_source ) ) {
702 - wp_send_json_error(array('mess' => __('Invalid plugin', 'adminify')));
703 - }
704 -
705 - $result = $upgrader->install( $trusted_install_source );
705 + $result = $upgrader->install($plugin);
706 706 if ($params == null){
707 707 if (empty($result) || empty($upgrader->result)) {
708 708 wp_send_json_error(
709 709 array(
@@ -762,21 +762,11 @@
762 762 }
763 763 }
764 764 } else {
765 765
766 - // Resolve the trusted plugin file path from the validated
767 - // slug instead of trusting the raw $_POST value, so that
768 - // is_plugin_active(), Plugin_Upgrader::upgrade() and
769 - // activate_plugin() never receive attacker-supplied paths.
770 - $installed_plugins = get_plugins( '/' . $plugin_slug );
771 - if ( empty( $installed_plugins ) ) {
772 - wp_send_json_error(array('mess' => __('Plugin not installed.', 'adminify')));
773 - }
774 - $trusted_plugin_file = $plugin_slug . '/' . key( $installed_plugins );
766 + $is_active = is_plugin_active($plugin);
767 + $result = $upgrader->upgrade($plugin);
775 768
776 - $is_active = is_plugin_active( $trusted_plugin_file );
777 - $result = $upgrader->upgrade( $trusted_plugin_file );
778 -
779 769 if ($params == null){
780 770 if ( empty($result) || is_wp_error($result) ) {
781 771 wp_send_json_error(
782 772 array(
@@ -785,9 +775,9 @@
785 775 );
786 776 }
787 777 }
788 778
789 - $active_status = activate_plugin( $trusted_plugin_file );
779 + $active_status = activate_plugin($plugin);
790 780
791 781 if ($params == null){
792 782 if ( empty($active_status) || is_wp_error($active_status) ) {
793 783 wp_send_json_error(