| @@ -34,9 +34,9 @@ | ||
| 34 | 34 | require_once ABSPATH . 'wp-admin/includes/file.php'; |
| 35 | 35 | require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
| 36 | 36 | include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; |
| 37 | 37 | |
| 38 | - $response = [ 'success' => false, 'message' => '' ]; | |
| 38 | + $response = [ 'success' => false ]; | |
| 39 | 39 | |
| 40 | 40 | $_plugins = Helper::get_plugins(); |
| 41 | 41 | $is_installed = isset( $_plugins[ $plugin['plugin_file'] ] ); |
| 42 | 42 | |
| @@ -53,36 +53,30 @@ | ||
| 53 | 53 | $response['message'] = 'Pro Plugin'; |
| 54 | 54 | } |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - if ( ! $is_installed ) { | |
| 58 | - if(!Helper::current_user_can( 'install_plugins' )){ | |
| 59 | - $response['code'] = 'invalid_requirements'; | |
| 60 | - $response['message'] = __( 'Sorry, you do not have permission to install a plugin.', 'templately' ); | |
| 61 | - return $response; | |
| 62 | - } | |
| 57 | + /** | |
| 58 | + * @var array|object $api | |
| 59 | + */ | |
| 60 | + $api = plugins_api( 'plugin_information', [ | |
| 61 | + 'slug' => sanitize_key( wp_unslash( $plugin['slug'] ) ), | |
| 62 | + 'fields' => [ | |
| 63 | + 'sections' => false, | |
| 64 | + ], | |
| 65 | + ] ); | |
| 63 | 66 | |
| 64 | - /** | |
| 65 | - * @var array|object $api | |
| 66 | - */ | |
| 67 | - $api = plugins_api( 'plugin_information', [ | |
| 68 | - 'slug' => sanitize_key( wp_unslash( $plugin['slug'] ) ), | |
| 69 | - 'fields' => [ | |
| 70 | - 'sections' => false, | |
| 71 | - ], | |
| 72 | - ] ); | |
| 67 | + if ( is_wp_error( $api ) ) { | |
| 68 | + $response['message'] = $api->get_error_message(); | |
| 73 | 69 | |
| 74 | - if ( is_wp_error( $api ) ) { | |
| 75 | - $response['message'] = $api->get_error_message(); | |
| 70 | + return $response; | |
| 71 | + } | |
| 76 | 72 | |
| 77 | - return $response; | |
| 78 | - } | |
| 73 | + $compatibility = $this->check_compatibility($api); | |
| 74 | + if (!$compatibility['success']) { | |
| 75 | + return $compatibility; | |
| 76 | + } | |
| 79 | 77 | |
| 80 | - $compatibility = $this->check_compatibility($api); | |
| 81 | - if (!$compatibility['success']) { | |
| 82 | - return $compatibility; | |
| 83 | - } | |
| 84 | - | |
| 78 | + if ( ! $is_installed ) { | |
| 85 | 79 | $response['name'] = $api->name; |
| 86 | 80 | |
| 87 | 81 | $skin = new WP_Ajax_Upgrader_Skin(); |
| 88 | 82 | $upgrader = new Plugin_Upgrader( $skin ); |
| @@ -121,14 +115,8 @@ | ||
| 121 | 115 | $install_status = install_plugin_install_status( $api ); |
| 122 | 116 | $plugin['plugin_file'] = $install_status['file']; |
| 123 | 117 | } |
| 124 | 118 | |
| 125 | - if ( !Helper::current_user_can( 'activate_plugins' ) && is_plugin_inactive( $file ) ) { | |
| 126 | - $response['code'] = 'invalid_requirements'; | |
| 127 | - $response['message'] = __( 'Sorry, you do not have permission to activate a plugin.', 'templately' ); | |
| 128 | - return $response; | |
| 129 | - } | |
| 130 | - | |
| 131 | 119 | $activate_status = $this->activate_plugin( $plugin['plugin_file'] ); |
| 132 | 120 | |
| 133 | 121 | if ( is_wp_error( $activate_status ) ) { |
| 134 | 122 | $response['message'] = $activate_status->get_error_message(); |
| @@ -234,9 +222,9 @@ | ||
| 234 | 222 | if ( is_plugin_active( $file ) ) { |
| 235 | 223 | return true; |
| 236 | 224 | } |
| 237 | 225 | |
| 238 | - if ( Helper::current_user_can( 'activate_plugins' ) && is_plugin_inactive( $file ) ) { | |
| 226 | + if ( current_user_can( 'activate_plugin', $file ) && is_plugin_inactive( $file ) ) { | |
| 239 | 227 | $result = activate_plugin( $file ); |
| 240 | 228 | if ( is_wp_error( $result ) ) { |
| 241 | 229 | return $result; |
| 242 | 230 | } else { |
| @@ -252,9 +240,9 @@ | ||
| 252 | 240 | // The theme is already active |
| 253 | 241 | return true; |
| 254 | 242 | } |
| 255 | 243 | |
| 256 | - if (Helper::current_user_can('switch_themes')) { | |
| 244 | + if (current_user_can('switch_themes')) { | |
| 257 | 245 | // Activate the theme |
| 258 | 246 | switch_theme($theme_slug); |
| 259 | 247 | |
| 260 | 248 | // Check if the theme was successfully activated |