Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 14 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| Jetpack_JSON_API_Get_Option_Backup_Endpoint | |
0.00% |
0 / 12 |
|
0.00% |
0 / 3 |
30 | |
0.00% |
0 / 1 |
| validate_input | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 | |||
| result | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| get_option_row | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit( 0 ); |
| 5 | } |
| 6 | |
| 7 | /** |
| 8 | * Get option backup endpoint. |
| 9 | * |
| 10 | * /sites/%s/options/backup -> $blog_id |
| 11 | * |
| 12 | * @phan-constructor-used-for-side-effects |
| 13 | */ |
| 14 | class Jetpack_JSON_API_Get_Option_Backup_Endpoint extends Jetpack_JSON_API_Endpoint { |
| 15 | /** |
| 16 | * Needed capabilities. |
| 17 | * |
| 18 | * @var array |
| 19 | */ |
| 20 | protected $needed_capabilities = array(); // This endpoint is only accessible using a site token |
| 21 | |
| 22 | /** |
| 23 | * Option names. |
| 24 | * |
| 25 | * @var array |
| 26 | */ |
| 27 | protected $option_names; |
| 28 | |
| 29 | /** |
| 30 | * Validate input. |
| 31 | * |
| 32 | * @param object $object - unused. |
| 33 | * |
| 34 | * @return bool|WP_Error |
| 35 | */ |
| 36 | public function validate_input( $object ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
| 37 | $query_args = $this->query_args(); |
| 38 | |
| 39 | if ( empty( $query_args['name'] ) ) { |
| 40 | return new WP_Error( 'option_name_not_specified', __( 'You must specify an option name', 'jetpack' ), 400 ); |
| 41 | } |
| 42 | |
| 43 | if ( is_array( $query_args['name'] ) ) { |
| 44 | $this->option_names = $query_args['name']; |
| 45 | } else { |
| 46 | $this->option_names = array( $query_args['name'] ); |
| 47 | } |
| 48 | |
| 49 | return true; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * The result. |
| 54 | */ |
| 55 | protected function result() { |
| 56 | // Disable Sync as this is a read-only operation and triggered by sync activity. |
| 57 | \Automattic\Jetpack\Sync\Actions::mark_sync_read_only(); |
| 58 | |
| 59 | $options = array_map( array( $this, 'get_option_row' ), $this->option_names ); |
| 60 | return array( 'options' => $options ); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Get options row. |
| 65 | * |
| 66 | * @param string $name - name of the row. |
| 67 | * |
| 68 | * @return object|null Database query result or null on failure. |
| 69 | */ |
| 70 | private function get_option_row( $name ) { |
| 71 | global $wpdb; |
| 72 | return $wpdb->get_row( $wpdb->prepare( "select * from `{$wpdb->options}` where option_name = %s", $name ) ); |
| 73 | } |
| 74 | } |