diff options
author | Yury German <blueknight@gentoo.org> | 2019-05-22 01:01:36 -0400 |
---|---|---|
committer | Yury German <blueknight@gentoo.org> | 2019-05-22 01:01:36 -0400 |
commit | 0914c92da22824025992c368c745546e41fbeb84 (patch) | |
tree | 965f6adf3b725e56d559fe4a93eff02281499dcc /plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-delete-endpoint.php | |
parent | Deleting plugins for update (diff) | |
download | blogs-gentoo-0914c92da22824025992c368c745546e41fbeb84.tar.gz blogs-gentoo-0914c92da22824025992c368c745546e41fbeb84.tar.bz2 blogs-gentoo-0914c92da22824025992c368c745546e41fbeb84.zip |
Adding Plugins
Updating the following
akismet.4.1.2, google-authenticator.0.52, jetpack.7.3.1
Signed-off-by: Yury German <blueknight@gentoo.org>
Diffstat (limited to 'plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-delete-endpoint.php')
-rw-r--r-- | plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-delete-endpoint.php | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-delete-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-delete-endpoint.php new file mode 100644 index 00000000..3748d621 --- /dev/null +++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-delete-endpoint.php @@ -0,0 +1,78 @@ +<?php +// POST /sites/%s/plugins/%s/delete +new Jetpack_JSON_API_Plugins_Delete_Endpoint( + array( + 'description' => 'Delete/Uninstall a plugin from your jetpack blog', + 'group' => '__do_not_document', + 'stat' => 'plugins:1:delete', + 'min_version' => '1', + 'max_version' => '1.1', + 'method' => 'POST', + 'path' => '/sites/%s/plugins/%s/delete', + 'path_labels' => array( + '$site' => '(int|string) The site ID, The site domain', + '$plugin' => '(int|string) The plugin slug to delete', + ), + 'response_format' => Jetpack_JSON_API_Plugins_Endpoint::$_response_format, + 'example_request_data' => array( + 'headers' => array( + 'authorization' => 'Bearer YOUR_API_TOKEN' + ), + ), + 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/plugins/akismet%2Fakismet/delete' + ) +); +// v1.2 +new Jetpack_JSON_API_Plugins_Delete_Endpoint( + array( + 'description' => 'Delete/Uninstall a plugin from your jetpack blog', + 'group' => '__do_not_document', + 'stat' => 'plugins:1:delete', + 'min_version' => '1.2', + 'method' => 'POST', + 'path' => '/sites/%s/plugins/%s/delete', + 'path_labels' => array( + '$site' => '(int|string) The site ID, The site domain', + '$plugin' => '(int|string) The plugin slug to delete', + ), + 'response_format' => Jetpack_JSON_API_Plugins_Endpoint::$_response_format_v1_2, + 'example_request_data' => array( + 'headers' => array( + 'authorization' => 'Bearer YOUR_API_TOKEN' + ), + ), + 'example_request' => 'https://public-api.wordpress.com/rest/v1.2/sites/example.wordpress.org/plugins/akismet%2Fakismet/delete' + ) +); + +class Jetpack_JSON_API_Plugins_Delete_Endpoint extends Jetpack_JSON_API_Plugins_Endpoint { + + // POST /sites/%s/plugins/%s/delete + protected $needed_capabilities = 'delete_plugins'; + protected $action = 'delete'; + + protected function delete() { + + foreach ( $this->plugins as $plugin ) { + + if ( Jetpack::is_plugin_active( $plugin ) ) { + $error = $this->log[ $plugin ][] = __( 'You cannot delete a plugin while it is active on the main site.', 'jetpack' ); + continue; + } + + $result = delete_plugins( array( $plugin ) ); + if ( is_wp_error( $result ) ) { + $error = $this->log[ $plugin ][] = $result->get_error_message(); + } else { + $this->log[ $plugin ][] = 'Plugin deleted'; + } + } + + if ( ! $this->bulk && isset( $error ) ) { + return new WP_Error( 'delete_plugin_error', $error, 400 ); + } + + return true; + } + +} |