| 1 |
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 |
|
| 3 |
/** |
| 4 |
* Get Term backup endpoint class. |
| 5 |
* |
| 6 |
* /sites/%s/terms/%d/backup -> $blog_id, $term_id |
| 7 |
*/ |
| 8 |
class Jetpack_JSON_API_Get_Term_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 term ID. |
| 19 |
* |
| 20 |
* @var int |
| 21 |
*/ |
| 22 |
protected $term_id; |
| 23 |
|
| 24 |
/** |
| 25 |
* Validate input. |
| 26 |
* |
| 27 |
* @param int $term_id - the term ID. |
| 28 |
* |
| 29 |
* @return bool|WP_Error |
| 30 |
*/ |
| 31 |
public function validate_input( $term_id ) { |
| 32 |
if ( empty( $term_id ) || ! is_numeric( $term_id ) ) { |
| 33 |
return new WP_Error( 'term_id_not_specified', __( 'You must specify a Term ID', 'jetpack' ), 400 ); |
| 34 |
} |
| 35 |
|
| 36 |
$this->term_id = (int) $term_id; |
| 37 |
|
| 38 |
return true; |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Return 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 |
$term = get_term( $this->term_id ); |
| 51 |
if ( empty( $term ) ) { |
| 52 |
return new WP_Error( 'term_not_found', __( 'Term not found', 'jetpack' ), 404 ); |
| 53 |
} |
| 54 |
|
| 55 |
return array( |
| 56 |
'term' => (array) $term, |
| 57 |
'meta' => get_term_meta( $this->term_id ), |
| 58 |
); |
| 59 |
} |
| 60 |
|
| 61 |
} |
| 62 |
|
| 63 |
|