| @@ -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 | |
| @@ -54,29 +54,18 @@ | ||
| 54 | 54 | } |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 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 | - } | |
| 63 | - | |
| 64 | - $plugins_api_args = [ | |
| 58 | + /** | |
| 59 | + * @var array|object $api | |
| 60 | + */ | |
| 61 | + $api = plugins_api( 'plugin_information', [ | |
| 65 | 62 | 'slug' => sanitize_key( wp_unslash( $plugin['slug'] ) ), |
| 66 | 63 | 'fields' => [ |
| 67 | 64 | 'sections' => false, |
| 68 | 65 | ], |
| 69 | - ]; | |
| 70 | - if(isset($plugin['has_license']) && $plugin['has_license']){ | |
| 71 | - $plugins_api_args['has_license'] = $plugin['has_license']; | |
| 72 | - } | |
| 73 | - /** | |
| 74 | - * @var array|object $api | |
| 75 | - */ | |
| 76 | - $api = plugins_api( 'plugin_information', $plugins_api_args); | |
| 66 | + ] ); | |
| 77 | 67 | |
| 78 | - | |
| 79 | 68 | if ( is_wp_error( $api ) ) { |
| 80 | 69 | $response['message'] = $api->get_error_message(); |
| 81 | 70 | |
| 82 | 71 | return $response; |
| @@ -126,14 +115,8 @@ | ||
| 126 | 115 | $install_status = install_plugin_install_status( $api ); |
| 127 | 116 | $plugin['plugin_file'] = $install_status['file']; |
| 128 | 117 | } |
| 129 | 118 | |
| 130 | - if ( !Helper::current_user_can( 'activate_plugins' ) && is_plugin_inactive( $file ) ) { | |
| 131 | - $response['code'] = 'invalid_requirements'; | |
| 132 | - $response['message'] = __( 'Sorry, you do not have permission to activate a plugin.', 'templately' ); | |
| 133 | - return $response; | |
| 134 | - } | |
| 135 | - | |
| 136 | 119 | $activate_status = $this->activate_plugin( $plugin['plugin_file'] ); |
| 137 | 120 | |
| 138 | 121 | if ( is_wp_error( $activate_status ) ) { |
| 139 | 122 | $response['message'] = $activate_status->get_error_message(); |
| @@ -239,9 +222,9 @@ | ||
| 239 | 222 | if ( is_plugin_active( $file ) ) { |
| 240 | 223 | return true; |
| 241 | 224 | } |
| 242 | 225 | |
| 243 | - if ( Helper::current_user_can( 'activate_plugins' ) && is_plugin_inactive( $file ) ) { | |
| 226 | + if ( current_user_can( 'activate_plugin', $file ) && is_plugin_inactive( $file ) ) { | |
| 244 | 227 | $result = activate_plugin( $file ); |
| 245 | 228 | if ( is_wp_error( $result ) ) { |
| 246 | 229 | return $result; |
| 247 | 230 | } else { |
| @@ -257,9 +240,9 @@ | ||
| 257 | 240 | // The theme is already active |
| 258 | 241 | return true; |
| 259 | 242 | } |
| 260 | 243 | |
| 261 | - if (Helper::current_user_can('switch_themes')) { | |
| 244 | + if (current_user_can('switch_themes')) { | |
| 262 | 245 | // Activate the theme |
| 263 | 246 | switch_theme($theme_slug); |
| 264 | 247 | |
| 265 | 248 | // Check if the theme was successfully activated |