Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
Jetpack_JSON_API_Get_Term_Backup_Endpoint
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 2
30
0.00% covered (danger)
0.00%
0 / 1
 validate_input
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
12
 result
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
6
1<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2
3if ( ! 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 */
14class 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}