Completed
Push — fix/normalize-www-in-site-url-... ( e67e76 )
by
unknown
13:13 queued 02:59
created

WPCOM_JSON_API_Get_Taxonomy_Endpoint   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 27
rs 10
wmc 5
lcom 1
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
B callback() 0 23 5
1
<?php
2
class WPCOM_JSON_API_Get_Taxonomy_Endpoint extends WPCOM_JSON_API_Taxonomy_Endpoint {
3
	// /sites/%s/tags/slug:%s       -> $blog_id, $tag_id
4
	// /sites/%s/categories/slug:%s -> $blog_id, $tag_id
5
	function callback( $path = '', $blog_id = 0, $taxonomy_id = 0 ) {
6
		$blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) );
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $blog_id. This often makes code more readable.
Loading history...
7
		if ( is_wp_error( $blog_id ) ) {
8
			return $blog_id;
9
		}
10
11
		$args = $this->query_args();
12
		if ( preg_match( '#/tags/#i', $path ) ) {
13
			$taxonomy_type = "post_tag";
14
		} else {
15
			$taxonomy_type = "category";
16
		}
17
18
		$return = $this->get_taxonomy( $taxonomy_id, $taxonomy_type, $args['context'] );
19
		if ( !$return || is_wp_error( $return ) ) {
20
			return $return;
21
		}
22
23
		/** This action is documented in json-endpoints/class.wpcom-json-api-site-settings-endpoint.php */
24
		do_action( 'wpcom_json_api_objects', 'taxonomies' );
25
26
		return $return;
27
	}
28
}
29