<?php
/**
- * WordPress Category API
+ * Taxonomy API: Core category-specific functionality
*
* @package WordPress
+ * @subpackage Taxonomy
*/
/**
*
* @since 2.1.0
* @see get_terms() Type of arguments that can be changed.
- * @link https://codex.wordpress.org/Function_Reference/get_categories
*
- * @param string|array $args Optional. Change the defaults retrieving categories.
+ * @param string|array $args {
+ * Optional. Arguments to retrieve categories. See {@see get_terms()} for additional options.
+ *
+ * @type string $taxonomy Taxonomy to retrieve terms for. In this case, default 'category'.
+ * }
* @return array List of categories.
*/
function get_categories( $args = '' ) {
// Back compat
if ( isset($args['type']) && 'link' == $args['type'] ) {
- _deprecated_argument( __FUNCTION__, '3.0', '' );
+ /* translators: 1: "type => link", 2: "taxonomy => link_category" alternative */
+ _deprecated_argument( __FUNCTION__, '3.0',
+ sprintf( __( '%1$s is deprecated. Use %2$s instead.' ),
+ '<code>type => link</code>',
+ '<code>taxonomy => link_category</code>'
+ )
+ );
$taxonomy = $args['taxonomy'] = 'link_category';
}
- $categories = (array) get_terms( $taxonomy, $args );
+ $categories = get_terms( $taxonomy, $args );
- foreach ( array_keys( $categories ) as $k )
- _make_cat_compat( $categories[$k] );
+ if ( is_wp_error( $categories ) ) {
+ $categories = array();
+ } else {
+ $categories = (array) $categories;
+ foreach ( array_keys( $categories ) as $k ) {
+ _make_cat_compat( $categories[ $k ] );
+ }
+ }
return $categories;
}
* pass to it. This is one of the features with using pass by reference in PHP.
*
* @since 2.3.0
+ * @since 4.4.0 The `$category` parameter now also accepts a WP_Term object.
* @access private
*
- * @param array|object $category Category Row object or array
+ * @param array|object|WP_Term $category Category Row object or array
*/
function _make_cat_compat( &$category ) {
if ( is_object( $category ) && ! is_wp_error( $category ) ) {
- $category->cat_ID = &$category->term_id;
- $category->category_count = &$category->count;
- $category->category_description = &$category->description;
- $category->cat_name = &$category->name;
- $category->category_nicename = &$category->slug;
- $category->category_parent = &$category->parent;
+ $category->cat_ID = $category->term_id;
+ $category->category_count = $category->count;
+ $category->category_description = $category->description;
+ $category->cat_name = $category->name;
+ $category->category_nicename = $category->slug;
+ $category->category_parent = $category->parent;
} elseif ( is_array( $category ) && isset( $category['term_id'] ) ) {
$category['cat_ID'] = &$category['term_id'];
$category['category_count'] = &$category['count'];