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-get-term-backup-endpoint.php

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

67 lines 1.4 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 if ( ! defined( 'ABSPATH' ) ) {
4 exit( 0 );
5 }
6
7 /**
8 * Get Term backup endpoint class.
9 *
10 * /sites/%s/terms/%d/backup -> $blog_id, $term_id
11 *
12 * @phan-constructor-used-for-side-effects
13 */
14 class Jetpack_JSON_API_Get_Term_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 term ID.
25 *
26 * @var int
27 */
28 protected $term_id;
29
30 /**
31 * Validate input.
32 *
33 * @param int $term_id - the term ID.
34 *
35 * @return bool|WP_Error
36 */
37 public function validate_input( $term_id ) {
38 if ( empty( $term_id ) || ! is_numeric( $term_id ) ) {
39 return new WP_Error( 'term_id_not_specified', __( 'You must specify a Term ID', 'jetpack' ), 400 );
40 }
41
42 $this->term_id = (int) $term_id;
43
44 return true;
45 }
46
47 /**
48 * Return 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 $term = get_term( $this->term_id );
57 if ( empty( $term ) ) {
58 return new WP_Error( 'term_not_found', __( 'Term not found', 'jetpack' ), 404 );
59 }
60
61 return array(
62 'term' => (array) $term,
63 'meta' => get_term_meta( $this->term_id ),
64 );
65 }
66 }
67