summaryrefslogtreecommitdiff
blob: 40d0ab977e66a4a7fdddb9f7ecf0db6c062534f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php

class Jetpack_JSON_API_Get_Term_Backup_Endpoint extends Jetpack_JSON_API_Endpoint {
	// /sites/%s/terms/%d/backup      -> $blog_id, $term_id

	protected $needed_capabilities = array(); // This endpoint is only accessible using a site token
	protected $term_id;

	function validate_input( $term_id ) {
		if ( empty( $term_id ) || ! is_numeric( $term_id ) ) {
			return new WP_Error( 'term_id_not_specified', __( 'You must specify a Term ID', 'jetpack' ), 400 );
		}

		$this->term_id = intval( $term_id );

		return true;
	}

	protected function result() {
		$term = get_term( $this->term_id );
		if ( empty( $term ) ) {
			return new WP_Error( 'term_not_found', __( 'Term not found', 'jetpack' ), 404 );
		}

		return array(
			'term' => (array) $term,
			'meta' => get_term_meta( $this->term_id ),
		);
	}

}