PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3
Jetpack – WP Security, Backup, Speed, & Growth v16.3
16.3 16.3-beta 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 All 508 releases
jetpack / json-endpoints / jetpack / class-jetpack-json-api-delete-backup-helper-script-endpoint.php

class-jetpack-json-api-delete-backup-helper-script-endpoint.php in Jetpack – WP Security, Backup, Speed, & Growth 16.3, at json-endpoints/jetpack/class-jetpack-json-api-delete-backup-helper-script-endpoint.php

92 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * API endpoint /sites/%s/delete-backup-helper-script
4 * This API endpoint deletes a Jetpack Backup Helper Script
5 *
6 * @package automattic/jetpack
7 */
8
9 use Automattic\Jetpack\Backup\V0005\Helper_Script_Manager;
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit( 0 );
13 }
14
15 /**
16 * API endpoint /sites/%s/delete-backup-helper-script
17 * This API endpoint deletes a Jetpack Backup Helper Script
18 *
19 * @phan-constructor-used-for-side-effects
20 */
21 class Jetpack_JSON_API_Delete_Backup_Helper_Script_Endpoint extends Jetpack_JSON_API_Endpoint {
22 /**
23 * An empty capability set means this endpoint is only accessible using a site token: it is
24 * reachable with a Jetpack site (blog) token and denied for every user token, however
25 * privileged. See Jetpack_JSON_API_Endpoint::check_capability().
26 *
27 * @var array
28 */
29 protected $needed_capabilities = array();
30
31 /**
32 * Method to call when running this endpoint (delete)
33 *
34 * @var string
35 */
36 protected $action = 'delete';
37
38 /**
39 * Local path to the Helper Script to delete.
40 *
41 * @var string|null
42 */
43 protected $script_path = null;
44
45 /**
46 * An array with 'success' => true if the specified file has been successfully deleted, or an instance of WP_Error.
47 *
48 * @var array|WP_Error
49 */
50 protected $result;
51
52 /**
53 * Checks that the input args look like a valid Helper Script path.
54 *
55 * @param null $object Unused.
56 * @return bool|WP_Error a WP_Error object or true if the input seems ok.
57 */
58 protected function validate_input( $object ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
59 $args = $this->input();
60
61 if ( ! isset( $args['path'] ) ) {
62 return new WP_Error( 'invalid_args', __( 'You must specify a helper script path', 'jetpack' ), 400 );
63 }
64
65 $this->script_path = $args['path'];
66 return true;
67 }
68
69 /**
70 * Deletes the specified Helper Script.
71 */
72 protected function delete() {
73 $delete_result = Helper_Script_Manager::delete_helper_script( $this->script_path );
74 Helper_Script_Manager::cleanup_expired_helper_scripts();
75
76 if ( is_wp_error( $delete_result ) ) {
77 $this->result = $delete_result;
78 } else {
79 $this->result = array( 'success' => true );
80 }
81 }
82
83 /**
84 * Returns the success or failure of the deletion operation
85 *
86 * @return array An array containing one key; 'success', which specifies whether the operation was successful.
87 */
88 protected function result() {
89 return $this->result;
90 }
91 }
92