Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-inclu.../rest-api/endpoint...
File: class-wp-rest-terms-controller.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* REST API: WP_REST_Terms_Controller class
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage REST_API
[5] Fix | Delete
* @since 4.7.0
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Core class used to managed terms associated with a taxonomy via the REST API.
[10] Fix | Delete
*
[11] Fix | Delete
* @since 4.7.0
[12] Fix | Delete
*
[13] Fix | Delete
* @see WP_REST_Controller
[14] Fix | Delete
*/
[15] Fix | Delete
class WP_REST_Terms_Controller extends WP_REST_Controller {
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* Taxonomy key.
[19] Fix | Delete
*
[20] Fix | Delete
* @since 4.7.0
[21] Fix | Delete
* @var string
[22] Fix | Delete
*/
[23] Fix | Delete
protected $taxonomy;
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* Instance of a term meta fields object.
[27] Fix | Delete
*
[28] Fix | Delete
* @since 4.7.0
[29] Fix | Delete
* @var WP_REST_Term_Meta_Fields
[30] Fix | Delete
*/
[31] Fix | Delete
protected $meta;
[32] Fix | Delete
[33] Fix | Delete
/**
[34] Fix | Delete
* Column to have the terms be sorted by.
[35] Fix | Delete
*
[36] Fix | Delete
* @since 4.7.0
[37] Fix | Delete
* @var string
[38] Fix | Delete
*/
[39] Fix | Delete
protected $sort_column;
[40] Fix | Delete
[41] Fix | Delete
/**
[42] Fix | Delete
* Number of terms that were found.
[43] Fix | Delete
*
[44] Fix | Delete
* @since 4.7.0
[45] Fix | Delete
* @var int
[46] Fix | Delete
*/
[47] Fix | Delete
protected $total_terms;
[48] Fix | Delete
[49] Fix | Delete
/**
[50] Fix | Delete
* Whether the controller supports batching.
[51] Fix | Delete
*
[52] Fix | Delete
* @since 5.9.0
[53] Fix | Delete
* @var array
[54] Fix | Delete
*/
[55] Fix | Delete
protected $allow_batch = array( 'v1' => true );
[56] Fix | Delete
[57] Fix | Delete
/**
[58] Fix | Delete
* Constructor.
[59] Fix | Delete
*
[60] Fix | Delete
* @since 4.7.0
[61] Fix | Delete
*
[62] Fix | Delete
* @param string $taxonomy Taxonomy key.
[63] Fix | Delete
*/
[64] Fix | Delete
public function __construct( $taxonomy ) {
[65] Fix | Delete
$this->taxonomy = $taxonomy;
[66] Fix | Delete
$tax_obj = get_taxonomy( $taxonomy );
[67] Fix | Delete
$this->rest_base = ! empty( $tax_obj->rest_base ) ? $tax_obj->rest_base : $tax_obj->name;
[68] Fix | Delete
$this->namespace = ! empty( $tax_obj->rest_namespace ) ? $tax_obj->rest_namespace : 'wp/v2';
[69] Fix | Delete
[70] Fix | Delete
$this->meta = new WP_REST_Term_Meta_Fields( $taxonomy );
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
/**
[74] Fix | Delete
* Registers the routes for terms.
[75] Fix | Delete
*
[76] Fix | Delete
* @since 4.7.0
[77] Fix | Delete
*
[78] Fix | Delete
* @see register_rest_route()
[79] Fix | Delete
*/
[80] Fix | Delete
public function register_routes() {
[81] Fix | Delete
[82] Fix | Delete
register_rest_route(
[83] Fix | Delete
$this->namespace,
[84] Fix | Delete
'/' . $this->rest_base,
[85] Fix | Delete
array(
[86] Fix | Delete
array(
[87] Fix | Delete
'methods' => WP_REST_Server::READABLE,
[88] Fix | Delete
'callback' => array( $this, 'get_items' ),
[89] Fix | Delete
'permission_callback' => array( $this, 'get_items_permissions_check' ),
[90] Fix | Delete
'args' => $this->get_collection_params(),
[91] Fix | Delete
),
[92] Fix | Delete
array(
[93] Fix | Delete
'methods' => WP_REST_Server::CREATABLE,
[94] Fix | Delete
'callback' => array( $this, 'create_item' ),
[95] Fix | Delete
'permission_callback' => array( $this, 'create_item_permissions_check' ),
[96] Fix | Delete
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ),
[97] Fix | Delete
),
[98] Fix | Delete
'allow_batch' => $this->allow_batch,
[99] Fix | Delete
'schema' => array( $this, 'get_public_item_schema' ),
[100] Fix | Delete
)
[101] Fix | Delete
);
[102] Fix | Delete
[103] Fix | Delete
register_rest_route(
[104] Fix | Delete
$this->namespace,
[105] Fix | Delete
'/' . $this->rest_base . '/(?P<id>[\d]+)',
[106] Fix | Delete
array(
[107] Fix | Delete
'args' => array(
[108] Fix | Delete
'id' => array(
[109] Fix | Delete
'description' => __( 'Unique identifier for the term.' ),
[110] Fix | Delete
'type' => 'integer',
[111] Fix | Delete
),
[112] Fix | Delete
),
[113] Fix | Delete
array(
[114] Fix | Delete
'methods' => WP_REST_Server::READABLE,
[115] Fix | Delete
'callback' => array( $this, 'get_item' ),
[116] Fix | Delete
'permission_callback' => array( $this, 'get_item_permissions_check' ),
[117] Fix | Delete
'args' => array(
[118] Fix | Delete
'context' => $this->get_context_param( array( 'default' => 'view' ) ),
[119] Fix | Delete
),
[120] Fix | Delete
),
[121] Fix | Delete
array(
[122] Fix | Delete
'methods' => WP_REST_Server::EDITABLE,
[123] Fix | Delete
'callback' => array( $this, 'update_item' ),
[124] Fix | Delete
'permission_callback' => array( $this, 'update_item_permissions_check' ),
[125] Fix | Delete
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
[126] Fix | Delete
),
[127] Fix | Delete
array(
[128] Fix | Delete
'methods' => WP_REST_Server::DELETABLE,
[129] Fix | Delete
'callback' => array( $this, 'delete_item' ),
[130] Fix | Delete
'permission_callback' => array( $this, 'delete_item_permissions_check' ),
[131] Fix | Delete
'args' => array(
[132] Fix | Delete
'force' => array(
[133] Fix | Delete
'type' => 'boolean',
[134] Fix | Delete
'default' => false,
[135] Fix | Delete
'description' => __( 'Required to be true, as terms do not support trashing.' ),
[136] Fix | Delete
),
[137] Fix | Delete
),
[138] Fix | Delete
),
[139] Fix | Delete
'allow_batch' => $this->allow_batch,
[140] Fix | Delete
'schema' => array( $this, 'get_public_item_schema' ),
[141] Fix | Delete
)
[142] Fix | Delete
);
[143] Fix | Delete
}
[144] Fix | Delete
[145] Fix | Delete
/**
[146] Fix | Delete
* Checks if the terms for a post can be read.
[147] Fix | Delete
*
[148] Fix | Delete
* @since 6.0.3
[149] Fix | Delete
*
[150] Fix | Delete
* @param WP_Post $post Post object.
[151] Fix | Delete
* @param WP_REST_Request $request Full details about the request.
[152] Fix | Delete
* @return bool Whether the terms for the post can be read.
[153] Fix | Delete
*/
[154] Fix | Delete
public function check_read_terms_permission_for_post( $post, $request ) {
[155] Fix | Delete
// If the requested post isn't associated with this taxonomy, deny access.
[156] Fix | Delete
if ( ! is_object_in_taxonomy( $post->post_type, $this->taxonomy ) ) {
[157] Fix | Delete
return false;
[158] Fix | Delete
}
[159] Fix | Delete
[160] Fix | Delete
// Grant access if the post is publicly viewable.
[161] Fix | Delete
if ( is_post_publicly_viewable( $post ) ) {
[162] Fix | Delete
return true;
[163] Fix | Delete
}
[164] Fix | Delete
[165] Fix | Delete
// Otherwise grant access if the post is readable by the logged in user.
[166] Fix | Delete
if ( current_user_can( 'read_post', $post->ID ) ) {
[167] Fix | Delete
return true;
[168] Fix | Delete
}
[169] Fix | Delete
[170] Fix | Delete
// Otherwise, deny access.
[171] Fix | Delete
return false;
[172] Fix | Delete
}
[173] Fix | Delete
[174] Fix | Delete
/**
[175] Fix | Delete
* Checks if a request has access to read terms in the specified taxonomy.
[176] Fix | Delete
*
[177] Fix | Delete
* @since 4.7.0
[178] Fix | Delete
*
[179] Fix | Delete
* @param WP_REST_Request $request Full details about the request.
[180] Fix | Delete
* @return bool|WP_Error True if the request has read access, otherwise false or WP_Error object.
[181] Fix | Delete
*/
[182] Fix | Delete
public function get_items_permissions_check( $request ) {
[183] Fix | Delete
$tax_obj = get_taxonomy( $this->taxonomy );
[184] Fix | Delete
[185] Fix | Delete
if ( ! $tax_obj || ! $this->check_is_taxonomy_allowed( $this->taxonomy ) ) {
[186] Fix | Delete
return false;
[187] Fix | Delete
}
[188] Fix | Delete
[189] Fix | Delete
if ( 'edit' === $request['context'] && ! current_user_can( $tax_obj->cap->edit_terms ) ) {
[190] Fix | Delete
return new WP_Error(
[191] Fix | Delete
'rest_forbidden_context',
[192] Fix | Delete
__( 'Sorry, you are not allowed to edit terms in this taxonomy.' ),
[193] Fix | Delete
array( 'status' => rest_authorization_required_code() )
[194] Fix | Delete
);
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
if ( ! empty( $request['post'] ) ) {
[198] Fix | Delete
$post = get_post( $request['post'] );
[199] Fix | Delete
[200] Fix | Delete
if ( ! $post ) {
[201] Fix | Delete
return new WP_Error(
[202] Fix | Delete
'rest_post_invalid_id',
[203] Fix | Delete
__( 'Invalid post ID.' ),
[204] Fix | Delete
array(
[205] Fix | Delete
'status' => 400,
[206] Fix | Delete
)
[207] Fix | Delete
);
[208] Fix | Delete
}
[209] Fix | Delete
[210] Fix | Delete
if ( ! $this->check_read_terms_permission_for_post( $post, $request ) ) {
[211] Fix | Delete
return new WP_Error(
[212] Fix | Delete
'rest_forbidden_context',
[213] Fix | Delete
__( 'Sorry, you are not allowed to view terms for this post.' ),
[214] Fix | Delete
array(
[215] Fix | Delete
'status' => rest_authorization_required_code(),
[216] Fix | Delete
)
[217] Fix | Delete
);
[218] Fix | Delete
}
[219] Fix | Delete
}
[220] Fix | Delete
[221] Fix | Delete
return true;
[222] Fix | Delete
}
[223] Fix | Delete
[224] Fix | Delete
/**
[225] Fix | Delete
* Retrieves terms associated with a taxonomy.
[226] Fix | Delete
*
[227] Fix | Delete
* @since 4.7.0
[228] Fix | Delete
*
[229] Fix | Delete
* @param WP_REST_Request $request Full details about the request.
[230] Fix | Delete
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
[231] Fix | Delete
*/
[232] Fix | Delete
public function get_items( $request ) {
[233] Fix | Delete
[234] Fix | Delete
// Retrieve the list of registered collection query parameters.
[235] Fix | Delete
$registered = $this->get_collection_params();
[236] Fix | Delete
[237] Fix | Delete
/*
[238] Fix | Delete
* This array defines mappings between public API query parameters whose
[239] Fix | Delete
* values are accepted as-passed, and their internal WP_Query parameter
[240] Fix | Delete
* name equivalents (some are the same). Only values which are also
[241] Fix | Delete
* present in $registered will be set.
[242] Fix | Delete
*/
[243] Fix | Delete
$parameter_mappings = array(
[244] Fix | Delete
'exclude' => 'exclude',
[245] Fix | Delete
'include' => 'include',
[246] Fix | Delete
'order' => 'order',
[247] Fix | Delete
'orderby' => 'orderby',
[248] Fix | Delete
'post' => 'post',
[249] Fix | Delete
'hide_empty' => 'hide_empty',
[250] Fix | Delete
'per_page' => 'number',
[251] Fix | Delete
'search' => 'search',
[252] Fix | Delete
'slug' => 'slug',
[253] Fix | Delete
);
[254] Fix | Delete
[255] Fix | Delete
$prepared_args = array( 'taxonomy' => $this->taxonomy );
[256] Fix | Delete
[257] Fix | Delete
/*
[258] Fix | Delete
* For each known parameter which is both registered and present in the request,
[259] Fix | Delete
* set the parameter's value on the query $prepared_args.
[260] Fix | Delete
*/
[261] Fix | Delete
foreach ( $parameter_mappings as $api_param => $wp_param ) {
[262] Fix | Delete
if ( isset( $registered[ $api_param ], $request[ $api_param ] ) ) {
[263] Fix | Delete
$prepared_args[ $wp_param ] = $request[ $api_param ];
[264] Fix | Delete
}
[265] Fix | Delete
}
[266] Fix | Delete
[267] Fix | Delete
if ( isset( $prepared_args['orderby'] ) && isset( $request['orderby'] ) ) {
[268] Fix | Delete
$orderby_mappings = array(
[269] Fix | Delete
'include_slugs' => 'slug__in',
[270] Fix | Delete
);
[271] Fix | Delete
[272] Fix | Delete
if ( isset( $orderby_mappings[ $request['orderby'] ] ) ) {
[273] Fix | Delete
$prepared_args['orderby'] = $orderby_mappings[ $request['orderby'] ];
[274] Fix | Delete
}
[275] Fix | Delete
}
[276] Fix | Delete
[277] Fix | Delete
if ( isset( $registered['offset'] ) && ! empty( $request['offset'] ) ) {
[278] Fix | Delete
$prepared_args['offset'] = $request['offset'];
[279] Fix | Delete
} else {
[280] Fix | Delete
$prepared_args['offset'] = ( $request['page'] - 1 ) * $prepared_args['number'];
[281] Fix | Delete
}
[282] Fix | Delete
[283] Fix | Delete
$taxonomy_obj = get_taxonomy( $this->taxonomy );
[284] Fix | Delete
[285] Fix | Delete
if ( $taxonomy_obj->hierarchical && isset( $registered['parent'], $request['parent'] ) ) {
[286] Fix | Delete
if ( 0 === $request['parent'] ) {
[287] Fix | Delete
// Only query top-level terms.
[288] Fix | Delete
$prepared_args['parent'] = 0;
[289] Fix | Delete
} else {
[290] Fix | Delete
if ( $request['parent'] ) {
[291] Fix | Delete
$prepared_args['parent'] = $request['parent'];
[292] Fix | Delete
}
[293] Fix | Delete
}
[294] Fix | Delete
}
[295] Fix | Delete
[296] Fix | Delete
/**
[297] Fix | Delete
* Filters get_terms() arguments when querying terms via the REST API.
[298] Fix | Delete
*
[299] Fix | Delete
* The dynamic portion of the hook name, `$this->taxonomy`, refers to the taxonomy slug.
[300] Fix | Delete
*
[301] Fix | Delete
* Possible hook names include:
[302] Fix | Delete
*
[303] Fix | Delete
* - `rest_category_query`
[304] Fix | Delete
* - `rest_post_tag_query`
[305] Fix | Delete
*
[306] Fix | Delete
* Enables adding extra arguments or setting defaults for a terms
[307] Fix | Delete
* collection request.
[308] Fix | Delete
*
[309] Fix | Delete
* @since 4.7.0
[310] Fix | Delete
*
[311] Fix | Delete
* @link https://developer.wordpress.org/reference/functions/get_terms/
[312] Fix | Delete
*
[313] Fix | Delete
* @param array $prepared_args Array of arguments for get_terms().
[314] Fix | Delete
* @param WP_REST_Request $request The REST API request.
[315] Fix | Delete
*/
[316] Fix | Delete
$prepared_args = apply_filters( "rest_{$this->taxonomy}_query", $prepared_args, $request );
[317] Fix | Delete
[318] Fix | Delete
if ( ! empty( $prepared_args['post'] ) ) {
[319] Fix | Delete
$query_result = wp_get_object_terms( $prepared_args['post'], $this->taxonomy, $prepared_args );
[320] Fix | Delete
[321] Fix | Delete
// Used when calling wp_count_terms() below.
[322] Fix | Delete
$prepared_args['object_ids'] = $prepared_args['post'];
[323] Fix | Delete
} else {
[324] Fix | Delete
$query_result = get_terms( $prepared_args );
[325] Fix | Delete
}
[326] Fix | Delete
[327] Fix | Delete
$count_args = $prepared_args;
[328] Fix | Delete
[329] Fix | Delete
unset( $count_args['number'], $count_args['offset'] );
[330] Fix | Delete
[331] Fix | Delete
$total_terms = wp_count_terms( $count_args );
[332] Fix | Delete
[333] Fix | Delete
// wp_count_terms() can return a falsey value when the term has no children.
[334] Fix | Delete
if ( ! $total_terms ) {
[335] Fix | Delete
$total_terms = 0;
[336] Fix | Delete
}
[337] Fix | Delete
[338] Fix | Delete
$response = array();
[339] Fix | Delete
[340] Fix | Delete
foreach ( $query_result as $term ) {
[341] Fix | Delete
if ( 'edit' === $request['context'] && ! current_user_can( 'edit_term', $term->term_id ) ) {
[342] Fix | Delete
continue;
[343] Fix | Delete
}
[344] Fix | Delete
[345] Fix | Delete
$data = $this->prepare_item_for_response( $term, $request );
[346] Fix | Delete
$response[] = $this->prepare_response_for_collection( $data );
[347] Fix | Delete
}
[348] Fix | Delete
[349] Fix | Delete
$response = rest_ensure_response( $response );
[350] Fix | Delete
[351] Fix | Delete
// Store pagination values for headers.
[352] Fix | Delete
$per_page = (int) $prepared_args['number'];
[353] Fix | Delete
$page = (int) ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 );
[354] Fix | Delete
[355] Fix | Delete
$response->header( 'X-WP-Total', (int) $total_terms );
[356] Fix | Delete
[357] Fix | Delete
$max_pages = (int) ceil( $total_terms / $per_page );
[358] Fix | Delete
[359] Fix | Delete
$response->header( 'X-WP-TotalPages', $max_pages );
[360] Fix | Delete
[361] Fix | Delete
$request_params = $request->get_query_params();
[362] Fix | Delete
$collection_url = rest_url( rest_get_route_for_taxonomy_items( $this->taxonomy ) );
[363] Fix | Delete
$base = add_query_arg( urlencode_deep( $request_params ), $collection_url );
[364] Fix | Delete
[365] Fix | Delete
if ( $page > 1 ) {
[366] Fix | Delete
$prev_page = $page - 1;
[367] Fix | Delete
[368] Fix | Delete
if ( $prev_page > $max_pages ) {
[369] Fix | Delete
$prev_page = $max_pages;
[370] Fix | Delete
}
[371] Fix | Delete
[372] Fix | Delete
$prev_link = add_query_arg( 'page', $prev_page, $base );
[373] Fix | Delete
$response->link_header( 'prev', $prev_link );
[374] Fix | Delete
}
[375] Fix | Delete
if ( $max_pages > $page ) {
[376] Fix | Delete
$next_page = $page + 1;
[377] Fix | Delete
$next_link = add_query_arg( 'page', $next_page, $base );
[378] Fix | Delete
[379] Fix | Delete
$response->link_header( 'next', $next_link );
[380] Fix | Delete
}
[381] Fix | Delete
[382] Fix | Delete
return $response;
[383] Fix | Delete
}
[384] Fix | Delete
[385] Fix | Delete
/**
[386] Fix | Delete
* Get the term, if the ID is valid.
[387] Fix | Delete
*
[388] Fix | Delete
* @since 4.7.2
[389] Fix | Delete
*
[390] Fix | Delete
* @param int $id Supplied ID.
[391] Fix | Delete
* @return WP_Term|WP_Error Term object if ID is valid, WP_Error otherwise.
[392] Fix | Delete
*/
[393] Fix | Delete
protected function get_term( $id ) {
[394] Fix | Delete
$error = new WP_Error(
[395] Fix | Delete
'rest_term_invalid',
[396] Fix | Delete
__( 'Term does not exist.' ),
[397] Fix | Delete
array( 'status' => 404 )
[398] Fix | Delete
);
[399] Fix | Delete
[400] Fix | Delete
if ( ! $this->check_is_taxonomy_allowed( $this->taxonomy ) ) {
[401] Fix | Delete
return $error;
[402] Fix | Delete
}
[403] Fix | Delete
[404] Fix | Delete
if ( (int) $id <= 0 ) {
[405] Fix | Delete
return $error;
[406] Fix | Delete
}
[407] Fix | Delete
[408] Fix | Delete
$term = get_term( (int) $id, $this->taxonomy );
[409] Fix | Delete
if ( empty( $term ) || $term->taxonomy !== $this->taxonomy ) {
[410] Fix | Delete
return $error;
[411] Fix | Delete
}
[412] Fix | Delete
[413] Fix | Delete
return $term;
[414] Fix | Delete
}
[415] Fix | Delete
[416] Fix | Delete
/**
[417] Fix | Delete
* Checks if a request has access to read or edit the specified term.
[418] Fix | Delete
*
[419] Fix | Delete
* @since 4.7.0
[420] Fix | Delete
*
[421] Fix | Delete
* @param WP_REST_Request $request Full details about the request.
[422] Fix | Delete
* @return true|WP_Error True if the request has read access for the item, otherwise WP_Error object.
[423] Fix | Delete
*/
[424] Fix | Delete
public function get_item_permissions_check( $request ) {
[425] Fix | Delete
$term = $this->get_term( $request['id'] );
[426] Fix | Delete
[427] Fix | Delete
if ( is_wp_error( $term ) ) {
[428] Fix | Delete
return $term;
[429] Fix | Delete
}
[430] Fix | Delete
[431] Fix | Delete
if ( 'edit' === $request['context'] && ! current_user_can( 'edit_term', $term->term_id ) ) {
[432] Fix | Delete
return new WP_Error(
[433] Fix | Delete
'rest_forbidden_context',
[434] Fix | Delete
__( 'Sorry, you are not allowed to edit this term.' ),
[435] Fix | Delete
array( 'status' => rest_authorization_required_code() )
[436] Fix | Delete
);
[437] Fix | Delete
}
[438] Fix | Delete
[439] Fix | Delete
return true;
[440] Fix | Delete
}
[441] Fix | Delete
[442] Fix | Delete
/**
[443] Fix | Delete
* Gets a single term from a taxonomy.
[444] Fix | Delete
*
[445] Fix | Delete
* @since 4.7.0
[446] Fix | Delete
*
[447] Fix | Delete
* @param WP_REST_Request $request Full details about the request.
[448] Fix | Delete
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
[449] Fix | Delete
*/
[450] Fix | Delete
public function get_item( $request ) {
[451] Fix | Delete
$term = $this->get_term( $request['id'] );
[452] Fix | Delete
if ( is_wp_error( $term ) ) {
[453] Fix | Delete
return $term;
[454] Fix | Delete
}
[455] Fix | Delete
[456] Fix | Delete
$response = $this->prepare_item_for_response( $term, $request );
[457] Fix | Delete
[458] Fix | Delete
return rest_ensure_response( $response );
[459] Fix | Delete
}
[460] Fix | Delete
[461] Fix | Delete
/**
[462] Fix | Delete
* Checks if a request has access to create a term.
[463] Fix | Delete
*
[464] Fix | Delete
* @since 4.7.0
[465] Fix | Delete
*
[466] Fix | Delete
* @param WP_REST_Request $request Full details about the request.
[467] Fix | Delete
* @return true|WP_Error True if the request has access to create items, false or WP_Error object otherwise.
[468] Fix | Delete
*/
[469] Fix | Delete
public function create_item_permissions_check( $request ) {
[470] Fix | Delete
[471] Fix | Delete
if ( ! $this->check_is_taxonomy_allowed( $this->taxonomy ) ) {
[472] Fix | Delete
return false;
[473] Fix | Delete
}
[474] Fix | Delete
[475] Fix | Delete
$taxonomy_obj = get_taxonomy( $this->taxonomy );
[476] Fix | Delete
[477] Fix | Delete
if ( ( is_taxonomy_hierarchical( $this->taxonomy )
[478] Fix | Delete
&& ! current_user_can( $taxonomy_obj->cap->edit_terms ) )
[479] Fix | Delete
|| ( ! is_taxonomy_hierarchical( $this->taxonomy )
[480] Fix | Delete
&& ! current_user_can( $taxonomy_obj->cap->assign_terms ) ) ) {
[481] Fix | Delete
return new WP_Error(
[482] Fix | Delete
'rest_cannot_create',
[483] Fix | Delete
__( 'Sorry, you are not allowed to create terms in this taxonomy.' ),
[484] Fix | Delete
array( 'status' => rest_authorization_required_code() )
[485] Fix | Delete
);
[486] Fix | Delete
}
[487] Fix | Delete
[488] Fix | Delete
return true;
[489] Fix | Delete
}
[490] Fix | Delete
[491] Fix | Delete
/**
[492] Fix | Delete
* Creates a single term in a taxonomy.
[493] Fix | Delete
*
[494] Fix | Delete
* @since 4.7.0
[495] Fix | Delete
*
[496] Fix | Delete
* @param WP_REST_Request $request Full details about the request.
[497] Fix | Delete
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
[498] Fix | Delete
*/
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function