Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 14 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| Jetpack_JSON_API_Get_User_Backup_Endpoint | |
0.00% |
0 / 12 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
| validate_input | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
| result | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit( 0 ); |
| 5 | } |
| 6 | |
| 7 | /** |
| 8 | * Get user Backup endpoint class. |
| 9 | * |
| 10 | * /sites/%s/users/%d/backup -> $blog_id, $user_id |
| 11 | * |
| 12 | * @phan-constructor-used-for-side-effects |
| 13 | */ |
| 14 | class Jetpack_JSON_API_Get_User_Backup_Endpoint extends Jetpack_JSON_API_Endpoint { |
| 15 | |
| 16 | /** |
| 17 | * Needed capabilities. |
| 18 | * |
| 19 | * @var array |
| 20 | */ |
| 21 | protected $needed_capabilities = array(); // This endpoint is only accessible using a site token |
| 22 | |
| 23 | /** |
| 24 | * The user ID. |
| 25 | * |
| 26 | * @var int |
| 27 | */ |
| 28 | protected $user_id; |
| 29 | |
| 30 | /** |
| 31 | * Validate input. |
| 32 | * |
| 33 | * @param int $user_id - the user ID. |
| 34 | * |
| 35 | * @return bool|WP_Error |
| 36 | */ |
| 37 | public function validate_input( $user_id ) { |
| 38 | if ( empty( $user_id ) || ! is_numeric( $user_id ) ) { |
| 39 | return new WP_Error( 'user_id_not_specified', __( 'You must specify a User ID', 'jetpack' ), 400 ); |
| 40 | } |
| 41 | |
| 42 | $this->user_id = (int) $user_id; |
| 43 | |
| 44 | return true; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * The result. |
| 49 | * |
| 50 | * @return array|WP_Error |
| 51 | */ |
| 52 | protected function result() { |
| 53 | // Disable Sync as this is a read-only operation and triggered by sync activity. |
| 54 | \Automattic\Jetpack\Sync\Actions::mark_sync_read_only(); |
| 55 | |
| 56 | $user = get_user_by( 'id', $this->user_id ); |
| 57 | if ( empty( $user ) ) { |
| 58 | return new WP_Error( 'user_not_found', __( 'User not found', 'jetpack' ), 404 ); |
| 59 | } |
| 60 | |
| 61 | return array( |
| 62 | 'user' => $user->to_array(), |
| 63 | 'meta' => get_user_meta( $user->ID ), |
| 64 | ); |
| 65 | } |
| 66 | } |