| @@ -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 ]; | |
| 38 | + $response = [ 'success' => false, 'message' => '' ]; | |
| 39 | 39 | |
| 40 | 40 | $_plugins = Helper::get_plugins(); |
| 41 | 41 | $is_installed = isset( $_plugins[ $plugin['plugin_file'] ] ); |
| 42 | 42 | |
| @@ -54,8 +54,14 @@ | ||
| 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 | + | |
| 58 | 64 | /** |
| 59 | 65 | * @var array|object $api |
| 60 | 66 | */ |
| 61 | 67 | $api = plugins_api( 'plugin_information', [ |
| @@ -115,8 +121,14 @@ | ||
| 115 | 121 | $install_status = install_plugin_install_status( $api ); |
| 116 | 122 | $plugin['plugin_file'] = $install_status['file']; |
| 117 | 123 | } |
| 118 | 124 | |
| 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 | + | |
| 119 | 131 | $activate_status = $this->activate_plugin( $plugin['plugin_file'] ); |
| 120 | 132 | |
| 121 | 133 | if ( is_wp_error( $activate_status ) ) { |
| 122 | 134 | $response['message'] = $activate_status->get_error_message(); |
| @@ -222,9 +234,9 @@ | ||
| 222 | 234 | if ( is_plugin_active( $file ) ) { |
| 223 | 235 | return true; |
| 224 | 236 | } |
| 225 | 237 | |
| 226 | - if ( current_user_can( 'activate_plugin', $file ) && is_plugin_inactive( $file ) ) { | |
| 238 | + if ( Helper::current_user_can( 'activate_plugins' ) && is_plugin_inactive( $file ) ) { | |
| 227 | 239 | $result = activate_plugin( $file ); |
| 228 | 240 | if ( is_wp_error( $result ) ) { |
| 229 | 241 | return $result; |
| 230 | 242 | } else { |
| @@ -240,9 +252,9 @@ | ||
| 240 | 252 | // The theme is already active |
| 241 | 253 | return true; |
| 242 | 254 | } |
| 243 | 255 | |
| 244 | - if (current_user_can('switch_themes')) { | |
| 256 | + if (Helper::current_user_can('switch_themes')) { | |
| 245 | 257 | // Activate the theme |
| 246 | 258 | switch_theme($theme_slug); |
| 247 | 259 | |
| 248 | 260 | // Check if the theme was successfully activated |