PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 13.6.2
Jetpack – WP Security, Backup, Speed, & Growth v13.6.2
16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 All 506 releases
jetpack / json-endpoints / jetpack / class.jetpack-json-api-plugins-delete-endpoint.php

class.jetpack-json-api-plugins-delete-endpoint.php in Jetpack – WP Security, Backup, Speed, & Growth 13.6.2, at json-endpoints/jetpack/class.jetpack-json-api-plugins-delete-endpoint.php

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