<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[39033] trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php: Docs: Add much more complete and syntactically correct documentation throughout the `WP_REST_Terms_Controller` class.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/39033">39033</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/39033","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>DrewAPicture</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2016-10-30 18:20:58 +0000 (Sun, 30 Oct 2016)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Docs: Add much more complete and syntactically correct documentation throughout the `WP_REST_Terms_Controller` class.
Props Soean, mrahmadawais, flixos90.
See <a href="https://core.trac.wordpress.org/ticket/38398">#38398</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswpresttermscontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesrestapiendpointsclasswpresttermscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php 2016-10-30 18:08:36 UTC (rev 39032)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php 2016-10-30 18:20:58 UTC (rev 39033)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,13 +1,25 @@
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/**
+ * REST API: WP_REST_Terms_Controller class
+ *
+ * @package WordPress
+ * @subpackage REST_API
+ * @since 4.7.0
+ */
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Access terms associated with a taxonomy.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Core class used to managed terms associated with a taxonomy via the REST API.
+ *
+ * @since 4.7.0
+ *
+ * @see WP_REST_Controller
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> class WP_REST_Terms_Controller extends WP_REST_Controller {
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Taxonomy key.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.7.0
</ins><span class="cx" style="display: block; padding: 0 10px"> * @access protected
</span><span class="cx" style="display: block; padding: 0 10px"> * @var string
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -16,6 +28,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Instance of a term meta fields object.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.7.0
</ins><span class="cx" style="display: block; padding: 0 10px"> * @access protected
</span><span class="cx" style="display: block; padding: 0 10px"> * @var WP_REST_Term_Meta_Fields
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -24,6 +37,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Column to have the terms be sorted by.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.7.0
</ins><span class="cx" style="display: block; padding: 0 10px"> * @access protected
</span><span class="cx" style="display: block; padding: 0 10px"> * @var string
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -32,6 +46,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Number of terms that were found.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.7.0
</ins><span class="cx" style="display: block; padding: 0 10px"> * @access protected
</span><span class="cx" style="display: block; padding: 0 10px"> * @var int
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -40,6 +55,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Constructor.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.7.0
+ * @access public
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * @param string $taxonomy Taxonomy key.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function __construct( $taxonomy ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -53,6 +71,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Registers the routes for the objects of the controller.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ *
+ * @since 4.7.0
+ * @access public
+ *
+ * @see register_rest_route()
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function register_routes() {
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -71,6 +94,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'schema' => array( $this, 'get_public_item_schema' ),
</span><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
</span><span class="cx" style="display: block; padding: 0 10px"> array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'methods' => WP_REST_Server::READABLE,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -104,8 +128,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Checks if a request has access to read terms in the specified taxonomy.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param WP_REST_Request $request Full details about the request.
- * @return WP_Error|boolean
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.7.0
+ * @access public
+ *
+ * @param WP_REST_Request $request Full details about the request.
+ * @return bool|WP_Error True if the request has read access, otherwise false or WP_Error object.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function get_items_permissions_check( $request ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $tax_obj = get_taxonomy( $this->taxonomy );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -119,20 +146,25 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Gets terms associated with a taxonomy.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Retrieves terms associated with a taxonomy.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.7.0
+ * @access public
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * @param WP_REST_Request $request Full details about the request.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return WP_REST_Response|WP_Error
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function get_items( $request ) {
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Retrieve the list of registered collection query parameters.
</span><span class="cx" style="display: block; padding: 0 10px"> $registered = $this->get_collection_params();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // This array defines mappings between public API query parameters whose
- // values are accepted as-passed, and their internal WP_Query parameter
- // name equivalents (some are the same). Only values which are also
- // present in $registered will be set.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /*
+ * This array defines mappings between public API query parameters whose
+ * values are accepted as-passed, and their internal WP_Query parameter
+ * name equivalents (some are the same). Only values which are also
+ * present in $registered will be set.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> $parameter_mappings = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'exclude' => 'exclude',
</span><span class="cx" style="display: block; padding: 0 10px"> 'include' => 'include',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -147,8 +179,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $prepared_args = array();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // For each known parameter which is both registered and present in the request,
- // set the parameter's value on the query $prepared_args.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /*
+ * For each known parameter which is both registered and present in the request,
+ * set the parameter's value on the query $prepared_args.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> foreach ( $parameter_mappings as $api_param => $wp_param ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( isset( $registered[ $api_param ], $request[ $api_param ] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $prepared_args[ $wp_param ] = $request[ $api_param ];
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -177,11 +211,15 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Filters the query arguments before passing them to get_terms().
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * The dynamic portion of the hook name, `$this->taxonomy`, refers to the taxonomy slug.
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * Enables adding extra arguments or setting defaults for a terms
</span><span class="cx" style="display: block; padding: 0 10px"> * collection request.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @see https://developer.wordpress.org/reference/functions/get_terms/
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.7.0
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @link https://developer.wordpress.org/reference/functions/get_terms/
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * @param array $prepared_args Array of arguments to be
</span><span class="cx" style="display: block; padding: 0 10px"> * passed to get_terms().
</span><span class="cx" style="display: block; padding: 0 10px"> * @param WP_REST_Request $request The current request.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -198,15 +236,18 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $count_args = $prepared_args;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> unset( $count_args['number'], $count_args['offset'] );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $total_terms = wp_count_terms( $this->taxonomy, $count_args );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // wp_count_terms can return a falsy value when the term has no children
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // wp_count_terms can return a falsy value when the term has no children.
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! $total_terms ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $total_terms = 0;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $response = array();
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> foreach ( $query_result as $term ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $data = $this->prepare_item_for_response( $term, $request );
</span><span class="cx" style="display: block; padding: 0 10px"> $response[] = $this->prepare_response_for_collection( $data );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -216,24 +257,29 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Store pagination values for headers.
</span><span class="cx" style="display: block; padding: 0 10px"> $per_page = (int) $prepared_args['number'];
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $page = ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $page = ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $response->header( 'X-WP-Total', (int) $total_terms );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $max_pages = ceil( $total_terms / $per_page );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $response->header( 'X-WP-TotalPages', (int) $max_pages );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $base = add_query_arg( $request->get_query_params(), rest_url( $this->namespace . '/' . $this->rest_base ) );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $page > 1 ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $prev_page = $page - 1;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( $prev_page > $max_pages ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $prev_page = $max_pages;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $prev_link = add_query_arg( 'page', $prev_page, $base );
</span><span class="cx" style="display: block; padding: 0 10px"> $response->link_header( 'prev', $prev_link );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $max_pages > $page ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $next_page = $page + 1;
</span><span class="cx" style="display: block; padding: 0 10px"> $next_link = add_query_arg( 'page', $next_page, $base );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $response->link_header( 'next', $next_link );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -243,8 +289,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Checks if a request has access to read the specified term.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param WP_REST_Request $request Full details about the request.
- * @return WP_Error|boolean
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.7.0
+ * @access public
+ *
+ * @param WP_REST_Request $request Full details about the request.
+ * @return bool|WP_Error True if the request has read access for the item, otherwise false or WP_Error object.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function get_item_permissions_check( $request ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $tax_obj = get_taxonomy( $this->taxonomy );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -260,15 +309,20 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Gets a single term from a taxonomy.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param WP_REST_Request $request Full details about the request
- * @return WP_REST_Request|WP_Error
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.7.0
+ * @access public
+ *
+ * @param WP_REST_Request $request Full details about the request.
+ * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function get_item( $request ) {
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $term = get_term( (int) $request['id'], $this->taxonomy );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! $term || $term->taxonomy !== $this->taxonomy ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return new WP_Error( 'rest_term_invalid', __( "Resource doesn't exist." ), array( 'status' => 404 ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( is_wp_error( $term ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return $term;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -281,8 +335,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Checks if a request has access to create a term.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param WP_REST_Request $request Full details about the request.
- * @return WP_Error|boolean
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.7.0
+ * @access public
+ *
+ * @param WP_REST_Request $request Full details about the request.
+ * @return bool|WP_Error True if the request has access to create items, false or WP_Error object otherwise.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function create_item_permissions_check( $request ) {
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -301,8 +358,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Creates a single term in a taxonomy.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param WP_REST_Request $request Full details about the request
- * @return WP_REST_Request|WP_Error
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.7.0
+ * @access public
+ *
+ * @param WP_REST_Request $request Full details about the request.
+ * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function create_item( $request ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( isset( $request['parent'] ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -321,7 +381,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $term = wp_insert_term( $prepared_term->name, $this->taxonomy, $prepared_term );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( is_wp_error( $term ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px"> /*
</span><span class="cx" style="display: block; padding: 0 10px"> * If we're going to inform the client that the term already exists,
</span><span class="cx" style="display: block; padding: 0 10px"> * give them the identifier for future use.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -339,38 +398,50 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Fires after a single term is created or updated via the REST API.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * The dynamic portion of the hook name, `$this->taxonomy`, refers to the taxonomy slug.
+ *
+ * @since 4.7.0
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * @param WP_Term $term Inserted Term object.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param WP_REST_Request $request Request object.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param boolean $creating True when creating term, false when updating.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param bool $creating True when creating term, false when updating.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> do_action( "rest_insert_{$this->taxonomy}", $term, $request, true );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $schema = $this->get_item_schema();
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $schema['properties']['meta'] ) && isset( $request['meta'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $meta_update = $this->meta->update_value( $request['meta'], (int) $request['id'] );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( is_wp_error( $meta_update ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return $meta_update;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $fields_update = $this->update_additional_fields_for_object( $term, $request );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( is_wp_error( $fields_update ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return $fields_update;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $request->set_param( 'context', 'view' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $response = $this->prepare_item_for_response( $term, $request );
</span><span class="cx" style="display: block; padding: 0 10px"> $response = rest_ensure_response( $response );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $response->set_status( 201 );
</span><span class="cx" style="display: block; padding: 0 10px"> $response->header( 'Location', rest_url( $this->namespace . '/' . $this->rest_base . '/' . $term->term_id ) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> return $response;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Checks if a request has access to update the specified term.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param WP_REST_Request $request Full details about the request.
- * @return WP_Error|boolean
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.7.0
+ * @access public
+ *
+ * @param WP_REST_Request $request Full details about the request.
+ * @return bool|WP_Error True if the request has access to update the item, false or WP_Error object otherwise.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function update_item_permissions_check( $request ) {
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -379,6 +450,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $term = get_term( (int) $request['id'], $this->taxonomy );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! $term ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return new WP_Error( 'rest_term_invalid', __( "Resource doesn't exist." ), array( 'status' => 404 ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -393,8 +465,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Updates a single term from a taxonomy.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param WP_REST_Request $request Full details about the request
- * @return WP_REST_Request|WP_Error
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.7.0
+ * @access public
+ *
+ * @param WP_REST_Request $request Full details about the request.
+ * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function update_item( $request ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( isset( $request['parent'] ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -416,6 +491,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // Only update the term if we haz something to update.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $prepared_term ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $update = wp_update_term( $term->term_id, $term->taxonomy, (array) $prepared_term );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( is_wp_error( $update ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return $update;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -429,32 +505,41 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $schema = $this->get_item_schema();
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $schema['properties']['meta'] ) && isset( $request['meta'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $meta_update = $this->meta->update_value( $request['meta'], (int) $request['id'] );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( is_wp_error( $meta_update ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return $meta_update;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $fields_update = $this->update_additional_fields_for_object( $term, $request );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( is_wp_error( $fields_update ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return $fields_update;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $request->set_param( 'context', 'view' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $response = $this->prepare_item_for_response( $term, $request );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> return rest_ensure_response( $response );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Checks if a request has access to delete the specified term.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param WP_REST_Request $request Full details about the request.
- * @return WP_Error|boolean
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.7.0
+ * @access public
+ *
+ * @param WP_REST_Request $request Full details about the request.
+ * @return bool|WP_Error True if the request has access to delete the item, otherwise false or WP_Error object.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function delete_item_permissions_check( $request ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! $this->check_is_taxonomy_allowed( $this->taxonomy ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $term = get_term( (int) $request['id'], $this->taxonomy );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! $term ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return new WP_Error( 'rest_term_invalid', __( "Resource doesn't exist." ), array( 'status' => 404 ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -462,14 +547,18 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! current_user_can( 'delete_term', $term->term_id ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return new WP_Error( 'rest_cannot_delete', __( 'Sorry, you cannot delete resource.' ), array( 'status' => rest_authorization_required_code() ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> return true;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Deletes a single term from a taxonomy.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param WP_REST_Request $request Full details about the request
- * @return WP_REST_Response|WP_Error
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.7.0
+ * @access public
+ *
+ * @param WP_REST_Request $request Full details about the request.
+ * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function delete_item( $request ) {
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -481,10 +570,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $term = get_term( (int) $request['id'], $this->taxonomy );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $request->set_param( 'context', 'view' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $response = $this->prepare_item_for_response( $term, $request );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $retval = wp_delete_term( $term->term_id, $term->taxonomy );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! $retval ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return new WP_Error( 'rest_cannot_delete', __( 'The resource cannot be deleted.' ), array( 'status' => 500 ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -492,6 +584,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Fires after a single term is deleted via the REST API.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * The dynamic portion of the hook name, `$this->taxonomy`, refers to the taxonomy slug.
+ *
+ * @since 4.7.0
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * @param WP_Term $term The deleted term.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param WP_REST_Response $response The response data.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param WP_REST_Request $request The request sent to the API.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -504,6 +600,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Prepares a single term for create or update.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.7.0
+ * @access public
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * @param WP_REST_Request $request Request object.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return object $prepared_term Term object.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -529,7 +628,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( isset( $request['parent'] ) && ! empty( $schema['properties']['parent'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $parent_term_id = 0;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $parent_term = get_term( (int) $request['parent'], $this->taxonomy );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $parent_term = get_term( (int) $request['parent'], $this->taxonomy );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $parent_term ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $parent_term_id = $parent_term->term_id;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -541,6 +640,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Filters term data before inserting term via the REST API.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * The dynamic portion of the hook name, `$this->taxonomy`, refers to the taxonomy slug.
+ *
+ * @since 4.7.0
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * @param object $prepared_term Term object.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param WP_REST_Request $request Request object.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -550,45 +653,57 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Prepares a single term output for response.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.7.0
+ * @access public
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * @param obj $item Term object.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param WP_REST_Request $request Request object.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return WP_REST_Response $response
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return WP_REST_Response $response Response object.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function prepare_item_for_response( $item, $request ) {
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $schema = $this->get_item_schema();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $data = array();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $data = array();
+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $schema['properties']['id'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $data['id'] = (int) $item->term_id;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $schema['properties']['count'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $data['count'] = (int) $item->count;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $schema['properties']['description'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $data['description'] = $item->description;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $schema['properties']['link'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $data['link'] = get_term_link( $item );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $schema['properties']['name'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $data['name'] = $item->name;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $schema['properties']['slug'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $data['slug'] = $item->slug;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $schema['properties']['taxonomy'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $data['taxonomy'] = $item->taxonomy;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $schema['properties']['parent'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $data['parent'] = (int) $item->parent;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $schema['properties']['meta'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $data['meta'] = $this->meta->get_value( $item->term_id, $request );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $context = ! empty( $request['context'] ) ? $request['context'] : 'view';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $data = $this->add_additional_fields_to_object( $data, $request );
- $data = $this->filter_response_by_context( $data, $context );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $data = $this->add_additional_fields_to_object( $data, $request );
+ $data = $this->filter_response_by_context( $data, $context );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $response = rest_ensure_response( $data );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -597,8 +712,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Filters a term item returned from the API.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * The dynamic portion of the hook name, `$this->taxonomy`, refers to the taxonomy slug.
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * Allows modification of the term data right before it is returned.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.7.0
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * @param WP_REST_Response $response The response object.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param object $item The original term object.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param WP_REST_Request $request Request used to generate the response.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -609,6 +728,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Prepares links for the request.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.7.0
+ * @access protected
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * @param object $term Term object.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return array Links for the given term.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -628,6 +750,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $term->parent ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $parent_term = get_term( (int) $term->parent, $term->taxonomy );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( $parent_term ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $links['up'] = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'href' => rest_url( trailingslashit( $base ) . $parent_term->term_id ),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -637,21 +760,26 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $taxonomy_obj = get_taxonomy( $term->taxonomy );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( empty( $taxonomy_obj->object_type ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return $links;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $post_type_links = array();
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> foreach ( $taxonomy_obj->object_type as $type ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $post_type_object = get_post_type_object( $type );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( empty( $post_type_object->show_in_rest ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> continue;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $rest_base = ! empty( $post_type_object->rest_base ) ? $post_type_object->rest_base : $post_type_object->name;
</span><span class="cx" style="display: block; padding: 0 10px"> $post_type_links[] = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'href' => add_query_arg( $this->rest_base, $term->term_id, rest_url( sprintf( 'wp/v2/%s', $rest_base ) ) ),
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $post_type_links ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $links['https://api.w.org/post_type'] = $post_type_links;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -660,9 +788,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Gets the term's schema, conforming to JSON Schema.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Retrieves the term's schema, conforming to JSON Schema.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return array
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.7.0
+ * @access public
+ *
+ * @return array Item schema data.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function get_item_schema() {
</span><span class="cx" style="display: block; padding: 0 10px"> $schema = array(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -723,7 +854,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $taxonomy = get_taxonomy( $this->taxonomy );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( $taxonomy->hierarchical ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $schema['properties']['parent'] = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'description' => __( 'The id for the parent of the resource.' ),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -733,13 +866,17 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $schema['properties']['meta'] = $this->meta->get_field_schema();
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> return $this->add_additional_fields_schema( $schema );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Gets the query params for collections.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Retrieves the query params for collections.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return array
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.7.0
+ * @access public
+ *
+ * @return array Collection parameters.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function get_collection_params() {
</span><span class="cx" style="display: block; padding: 0 10px"> $query_params = parent::get_collection_params();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -753,12 +890,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'default' => array(),
</span><span class="cx" style="display: block; padding: 0 10px"> 'sanitize_callback' => 'wp_parse_id_list',
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $query_params['include'] = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'description' => __( 'Limit result set to specific ids.' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'type' => 'array',
</span><span class="cx" style="display: block; padding: 0 10px"> 'default' => array(),
</span><span class="cx" style="display: block; padding: 0 10px"> 'sanitize_callback' => 'wp_parse_id_list',
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! $taxonomy->hierarchical ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $query_params['offset'] = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'description' => __( 'Offset the result set by a specific number of items.' ),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -767,6 +906,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'validate_callback' => 'rest_validate_request_arg',
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $query_params['order'] = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'description' => __( 'Order sort attribute ascending or descending.' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'type' => 'string',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -778,6 +918,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'validate_callback' => 'rest_validate_request_arg',
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $query_params['orderby'] = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'description' => __( 'Sort collection by resource attribute.' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'type' => 'string',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -794,6 +935,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'validate_callback' => 'rest_validate_request_arg',
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $query_params['hide_empty'] = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'description' => __( 'Whether to hide resources not assigned to any posts.' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'type' => 'boolean',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -801,6 +943,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'sanitize_callback' => 'rest_sanitize_request_arg',
</span><span class="cx" style="display: block; padding: 0 10px"> 'validate_callback' => 'rest_validate_request_arg',
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( $taxonomy->hierarchical ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $query_params['parent'] = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'description' => __( 'Limit result set to resources assigned to a specific parent.' ),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -809,25 +952,31 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'validate_callback' => 'rest_validate_request_arg',
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $query_params['post'] = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'description' => __( 'Limit result set to resources assigned to a specific post.' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'type' => 'integer',
</span><span class="cx" style="display: block; padding: 0 10px"> 'default' => null,
</span><span class="cx" style="display: block; padding: 0 10px"> 'validate_callback' => 'rest_validate_request_arg',
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $query_params['slug'] = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'description' => __( 'Limit result set to resources with a specific slug.' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'type' => 'string',
</span><span class="cx" style="display: block; padding: 0 10px"> 'validate_callback' => 'rest_validate_request_arg',
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> return $query_params;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Checks that the taxonomy is valid.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.7.0
+ * @access protected
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * @param string $taxonomy Taxonomy to check.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return WP_Error|boolean
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return bool Whether the taxonomy is allowed for REST management.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> protected function check_is_taxonomy_allowed( $taxonomy ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $taxonomy_obj = get_taxonomy( $taxonomy );
</span></span></pre>
</div>
</div>
</body>
</html>