Automattic /
jetpack
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
||
| 4 | include_once ABSPATH . 'wp-admin/includes/file.php'; |
||
| 5 | // POST /sites/%s/plugins/%s/install |
||
| 6 | new Jetpack_JSON_API_Plugins_Install_Endpoint( |
||
| 7 | array( |
||
| 8 | 'description' => 'Install a plugin to your jetpack blog', |
||
| 9 | 'group' => '__do_not_document', |
||
| 10 | 'stat' => 'plugins:1:install', |
||
| 11 | 'min_version' => '1', |
||
| 12 | 'max_version' => '1.1', |
||
| 13 | 'method' => 'POST', |
||
| 14 | 'path' => '/sites/%s/plugins/%s/install', |
||
| 15 | 'path_labels' => array( |
||
| 16 | '$site' => '(int|string) The site ID, The site domain', |
||
| 17 | '$plugin' => '(int|string) The plugin slug to install', |
||
| 18 | ), |
||
| 19 | 'response_format' => Jetpack_JSON_API_Plugins_Endpoint::$_response_format, |
||
| 20 | 'example_request_data' => array( |
||
| 21 | 'headers' => array( |
||
| 22 | 'authorization' => 'Bearer YOUR_API_TOKEN' |
||
| 23 | ), |
||
| 24 | ), |
||
| 25 | 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/plugins/akismet/install' |
||
| 26 | ) |
||
| 27 | ); |
||
| 28 | |||
| 29 | new Jetpack_JSON_API_Plugins_Install_Endpoint( |
||
| 30 | array( |
||
| 31 | 'description' => 'Install a plugin to your jetpack blog', |
||
| 32 | 'group' => '__do_not_document', |
||
| 33 | 'stat' => 'plugins:1:install', |
||
| 34 | 'min_version' => '1.2', |
||
| 35 | 'method' => 'POST', |
||
| 36 | 'path' => '/sites/%s/plugins/%s/install', |
||
| 37 | 'path_labels' => array( |
||
| 38 | '$site' => '(int|string) The site ID, The site domain', |
||
| 39 | '$plugin' => '(int|string) The plugin slug to install', |
||
| 40 | ), |
||
| 41 | 'response_format' => Jetpack_JSON_API_Plugins_Endpoint::$_response_format_v1_2, |
||
| 42 | 'example_request_data' => array( |
||
| 43 | 'headers' => array( |
||
| 44 | 'authorization' => 'Bearer YOUR_API_TOKEN' |
||
| 45 | ), |
||
| 46 | ), |
||
| 47 | 'example_request' => 'https://public-api.wordpress.com/rest/v1.2/sites/example.wordpress.org/plugins/akismet/install' |
||
| 48 | ) |
||
| 49 | ); |
||
| 50 | |||
| 51 | class Jetpack_JSON_API_Plugins_Install_Endpoint extends Jetpack_JSON_API_Plugins_Endpoint { |
||
| 52 | |||
| 53 | // POST /sites/%s/plugins/%s/install |
||
| 54 | protected $needed_capabilities = 'install_plugins'; |
||
| 55 | protected $action = 'install'; |
||
| 56 | |||
| 57 | protected function install() { |
||
| 58 | jetpack_require_lib( 'plugins' ); |
||
|
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||
| 59 | $result = ''; |
||
| 60 | foreach ( $this->plugins as $index => $slug ) { |
||
| 61 | $result = Jetpack_Plugins::install_plugin( $slug ); |
||
| 62 | if ( is_wp_error( $result ) ) { |
||
| 63 | $this->log[ $slug ][] = $result->get_error_message(); |
||
| 64 | if ( ! $this->bulk ) { |
||
| 65 | return $result; |
||
| 66 | } |
||
| 67 | } |
||
| 68 | } |
||
| 69 | |||
| 70 | if ( is_wp_error( $result ) ) { |
||
| 71 | return $result; |
||
| 72 | } |
||
| 73 | |||
| 74 | // No errors, install worked. Now replace the slug with the actual plugin id |
||
| 75 | $this->plugins[$index] = Jetpack_Plugins::get_plugin_id_by_slug( $slug ); |
||
| 76 | |||
| 77 | return true; |
||
| 78 | } |
||
| 79 | |||
| 80 | protected function validate_plugins() { |
||
| 81 | View Code Duplication | if ( empty( $this->plugins ) || ! is_array( $this->plugins ) ) { |
|
| 82 | return new WP_Error( 'missing_plugins', __( 'No plugins found.', 'jetpack' ) ); |
||
| 83 | } |
||
| 84 | |||
| 85 | jetpack_require_lib( 'plugins' ); |
||
|
0 ignored issues
–
show
|
|||
| 86 | foreach ( $this->plugins as $index => $slug ) { |
||
| 87 | // make sure it is not already installed |
||
| 88 | if ( Jetpack_Plugins::get_plugin_id_by_slug( $slug ) ) { |
||
| 89 | return new WP_Error( 'plugin_already_installed', __( 'The plugin is already installed', 'jetpack' ) ); |
||
| 90 | } |
||
| 91 | |||
| 92 | } |
||
| 93 | |||
| 94 | return true; |
||
| 95 | } |
||
| 96 | } |
||
| 97 |