Docs: Document that get_tags() returns a WP_Error object if any of the specified taxonomies do not exist.

Props coffee2code.
Fixes #50344.

git-svn-id: https://develop.svn.wordpress.org/trunk@47930 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2020-06-09 11:12:57 +00:00
parent ba994f6c09
commit eb1c55a7ac
2 changed files with 24 additions and 20 deletions

View File

@ -280,10 +280,14 @@ function sanitize_category_field( $field, $value, $cat_id, $context ) {
* Retrieves all post tags. * Retrieves all post tags.
* *
* @since 2.3.0 * @since 2.3.0
* @see get_terms() For list of arguments to pass.
* *
* @param string|array $args Tag arguments to use when retrieving tags. * @param string|array $args {
* @return WP_Term[]|int $tags Array of 'post_tag' term objects, or a count thereof. * Optional. Arguments to retrieve tags. See get_terms() for additional options.
*
* @type string $taxonomy Taxonomy to retrieve terms for. Default 'post_tag'.
* }
* @return WP_Term[]|int|WP_Error $tags Array of 'post_tag' term objects, a count thereof,
* or WP_Error if any of the taxonomies do not exist.
*/ */
function get_tags( $args = '' ) { function get_tags( $args = '' ) {
$defaults = array( 'taxonomy' => 'post_tag' ); $defaults = array( 'taxonomy' => 'post_tag' );
@ -292,19 +296,19 @@ function get_tags( $args = '' ) {
$tags = get_terms( $args ); $tags = get_terms( $args );
if ( empty( $tags ) ) { if ( empty( $tags ) ) {
$return = array(); $tags = array();
return $return; } else {
}
/** /**
* Filters the array of term objects returned for the 'post_tag' taxonomy. * Filters the array of term objects returned for the 'post_tag' taxonomy.
* *
* @since 2.3.0 * @since 2.3.0
* *
* @param WP_Term[]|int $tags Array of 'post_tag' term objects, or a count thereof. * @param WP_Term[]|int|WP_Error $tags Array of 'post_tag' term objects, a count thereof,
* or WP_Error if any of the taxonomies do not exist.
* @param array $args An array of arguments. @see get_terms() * @param array $args An array of arguments. @see get_terms()
*/ */
$tags = apply_filters( 'get_tags', $tags, $args ); $tags = apply_filters( 'get_tags', $tags, $args );
}
return $tags; return $tags;
} }

View File

@ -1133,11 +1133,11 @@ function get_term_to_edit( $id, $taxonomy ) {
* *
* @param array|string $args Optional. Array or string of arguments. See WP_Term_Query::__construct() * @param array|string $args Optional. Array or string of arguments. See WP_Term_Query::__construct()
* for information on accepted arguments. Default empty. * for information on accepted arguments. Default empty.
* @param array|string $deprecated Argument array, when using the legacy function parameter format. If present, this * @param array|string $deprecated Argument array, when using the legacy function parameter format. If present,
* parameter will be interpreted as `$args`, and the first function parameter will * this parameter will be interpreted as `$args`, and the first function parameter
* be parsed as a taxonomy or array of taxonomies. * will be parsed as a taxonomy or array of taxonomies.
* @return WP_Term[]|int|WP_Error List of WP_Term instances and their children. Will return WP_Error, if any of taxonomies * @return WP_Term[]|int|WP_Error Array of WP_Term instances, a count thereof,
* do not exist. * or WP_Error if any of the taxonomies do not exist.
*/ */
function get_terms( $args = array(), $deprecated = '' ) { function get_terms( $args = array(), $deprecated = '' ) {
$term_query = new WP_Term_Query(); $term_query = new WP_Term_Query();