Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 60 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| Jetpack_JSON_API_Plugins_Delete_Endpoint | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
42 | |
0.00% |
0 / 1 |
| delete | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
42 | |||
| 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit( 0 ); |
| 5 | } |
| 6 | |
| 7 | // POST /sites/%s/plugins/%s/delete |
| 8 | new Jetpack_JSON_API_Plugins_Delete_Endpoint( |
| 9 | array( |
| 10 | 'description' => 'Delete/Uninstall a plugin from your jetpack blog', |
| 11 | 'group' => '__do_not_document', |
| 12 | 'stat' => 'plugins:1:delete', |
| 13 | 'min_version' => '1', |
| 14 | 'max_version' => '1.1', |
| 15 | 'method' => 'POST', |
| 16 | 'path' => '/sites/%s/plugins/%s/delete', |
| 17 | 'path_labels' => array( |
| 18 | '$site' => '(int|string) The site ID, The site domain', |
| 19 | '$plugin' => '(int|string) The plugin slug to delete', |
| 20 | ), |
| 21 | 'response_format' => Jetpack_JSON_API_Plugins_Endpoint::$_response_format, |
| 22 | 'allow_jetpack_site_auth' => true, |
| 23 | 'example_request_data' => array( |
| 24 | 'headers' => array( |
| 25 | 'authorization' => 'Bearer YOUR_API_TOKEN', |
| 26 | ), |
| 27 | ), |
| 28 | 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/plugins/akismet%2Fakismet/delete', |
| 29 | ) |
| 30 | ); |
| 31 | // v1.2 |
| 32 | new Jetpack_JSON_API_Plugins_Delete_Endpoint( |
| 33 | array( |
| 34 | 'description' => 'Delete/Uninstall a plugin from your jetpack blog', |
| 35 | 'group' => '__do_not_document', |
| 36 | 'stat' => 'plugins:1:delete', |
| 37 | 'min_version' => '1.2', |
| 38 | 'method' => 'POST', |
| 39 | 'path' => '/sites/%s/plugins/%s/delete', |
| 40 | 'path_labels' => array( |
| 41 | '$site' => '(int|string) The site ID, The site domain', |
| 42 | '$plugin' => '(int|string) The plugin slug to delete', |
| 43 | ), |
| 44 | 'response_format' => Jetpack_JSON_API_Plugins_Endpoint::$_response_format_v1_2, |
| 45 | 'allow_jetpack_site_auth' => true, |
| 46 | 'example_request_data' => array( |
| 47 | 'headers' => array( |
| 48 | 'authorization' => 'Bearer YOUR_API_TOKEN', |
| 49 | ), |
| 50 | ), |
| 51 | 'example_request' => 'https://public-api.wordpress.com/rest/v1.2/sites/example.wordpress.org/plugins/akismet%2Fakismet/delete', |
| 52 | ) |
| 53 | ); |
| 54 | |
| 55 | /** |
| 56 | * Plugins delete endpoint class. |
| 57 | * |
| 58 | * POST /sites/%s/plugins/%s/delete |
| 59 | * |
| 60 | * @phan-constructor-used-for-side-effects |
| 61 | */ |
| 62 | class Jetpack_JSON_API_Plugins_Delete_Endpoint extends Jetpack_JSON_API_Plugins_Endpoint { |
| 63 | |
| 64 | /** |
| 65 | * Needed capabilities. |
| 66 | * |
| 67 | * @var string |
| 68 | */ |
| 69 | protected $needed_capabilities = 'delete_plugins'; |
| 70 | |
| 71 | /** |
| 72 | * The action. |
| 73 | * |
| 74 | * @var string |
| 75 | */ |
| 76 | protected $action = 'delete'; |
| 77 | |
| 78 | /** |
| 79 | * The delete function. |
| 80 | * |
| 81 | * @return bool|WP_Error |
| 82 | */ |
| 83 | protected function delete() { |
| 84 | |
| 85 | foreach ( $this->plugins as $plugin ) { |
| 86 | |
| 87 | if ( Jetpack::is_plugin_active( $plugin ) ) { |
| 88 | $error = __( 'You cannot delete a plugin while it is active on the main site.', 'jetpack' ); |
| 89 | $this->log[ $plugin ][] = $error; |
| 90 | continue; |
| 91 | } |
| 92 | |
| 93 | $result = delete_plugins( array( $plugin ) ); |
| 94 | if ( is_wp_error( $result ) ) { |
| 95 | $error = $result->get_error_message(); |
| 96 | $this->log[ $plugin ][] = $error; |
| 97 | } else { |
| 98 | $this->log[ $plugin ][] = 'Plugin deleted'; |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | if ( ! $this->bulk && isset( $error ) ) { |
| 103 | return new WP_Error( 'delete_plugin_error', $error, 400 ); |
| 104 | } |
| 105 | |
| 106 | return true; |
| 107 | } |
| 108 | } |