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