PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 13.7.2
Jetpack – WP Security, Backup, Speed, & Growth v13.7.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-get-user-backup-endpoint.php

class.jetpack-json-api-get-user-backup-endpoint.php in Jetpack – WP Security, Backup, Speed, & Growth 13.7.2, at json-endpoints/jetpack/class.jetpack-json-api-get-user-backup-endpoint.php

61 lines 1.3 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 /**
4 * Get user Backup endpoint class.
5 *
6 * /sites/%s/users/%d/backup -> $blog_id, $user_id
7 */
8 class Jetpack_JSON_API_Get_User_Backup_Endpoint extends Jetpack_JSON_API_Endpoint {
9
10 /**
11 * Needed capabilities.
12 *
13 * @var array
14 */
15 protected $needed_capabilities = array(); // This endpoint is only accessible using a site token
16
17 /**
18 * The user ID.
19 *
20 * @var int
21 */
22 protected $user_id;
23
24 /**
25 * Validate input.
26 *
27 * @param int $user_id - the user ID.
28 *
29 * @return bool|WP_Error
30 */
31 public function validate_input( $user_id ) {
32 if ( empty( $user_id ) || ! is_numeric( $user_id ) ) {
33 return new WP_Error( 'user_id_not_specified', __( 'You must specify a User ID', 'jetpack' ), 400 );
34 }
35
36 $this->user_id = (int) $user_id;
37
38 return true;
39 }
40
41 /**
42 * The result.
43 *
44 * @return array|WP_Error
45 */
46 protected function result() {
47 // Disable Sync as this is a read-only operation and triggered by sync activity.
48 \Automattic\Jetpack\Sync\Actions::mark_sync_read_only();
49
50 $user = get_user_by( 'id', $this->user_id );
51 if ( empty( $user ) ) {
52 return new WP_Error( 'user_not_found', __( 'User not found', 'jetpack' ), 404 );
53 }
54
55 return array(
56 'user' => $user->to_array(),
57 'meta' => get_user_meta( $user->ID ),
58 );
59 }
60 }
61