Changeset 51964 for trunk/src/wp-includes/rest-api.php
- Timestamp:
- 11/01/2021 03:26:06 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api.php
r51962 r51964 3116 3116 } 3117 3117 3118 $taxonomy = get_taxonomy( $term->taxonomy );3119 if ( ! $taxonomy ) {3118 $taxonomy_route = rest_get_route_for_taxonomy_items( $term->taxonomy ); 3119 if ( ! $taxonomy_route ) { 3120 3120 return ''; 3121 3121 } 3122 3122 3123 $controller = $taxonomy->get_rest_controller(); 3124 if ( ! $controller ) { 3125 return ''; 3126 } 3127 3128 $route = ''; 3129 3130 // The only controller that works is the Terms controller. 3131 if ( $controller instanceof WP_REST_Terms_Controller ) { 3132 $namespace = 'wp/v2'; 3133 $rest_base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name; 3134 $route = sprintf( '/%s/%s/%d', $namespace, $rest_base, $term->term_id ); 3135 } 3123 $route = sprintf( '%s/%d', $taxonomy_route, $term->term_id ); 3136 3124 3137 3125 /** … … 3144 3132 */ 3145 3133 return apply_filters( 'rest_route_for_term', $route, $term ); 3134 } 3135 3136 /** 3137 * Gets the REST API route for a taxonomy. 3138 * 3139 * @since 5.9.0 3140 * 3141 * @param string $taxonomy Name of taxonomy. 3142 * @return string The route path with a leading slash for the given taxonomy. 3143 */ 3144 function rest_get_route_for_taxonomy_items( $taxonomy ) { 3145 $taxonomy = get_taxonomy( $taxonomy ); 3146 if ( ! $taxonomy ) { 3147 return ''; 3148 } 3149 3150 if ( ! $taxonomy->show_in_rest ) { 3151 return ''; 3152 } 3153 3154 $namespace = ! empty( $taxonomy->rest_namespace ) ? $taxonomy->rest_namespace : 'wp/v2'; 3155 $rest_base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name; 3156 $route = sprintf( '/%s/%s', $namespace, $rest_base ); 3157 3158 /** 3159 * Filters the REST API route for a taxonomy. 3160 * 3161 * @since 5.9.0 3162 * 3163 * @param string $route The route path. 3164 * @param WP_Taxonomy $taxonomy The taxonomy object. 3165 */ 3166 return apply_filters( 'rest_route_for_taxonomy_items', $route, $taxonomy ); 3146 3167 } 3147 3168
Note: See TracChangeset
for help on using the changeset viewer.