~canonical-sysadmins/wordpress/4.8.3

« back to all changes in this revision

Viewing changes to wp-includes/category.php

  • Committer: Ryan Finnie
  • Date: 2015-08-31 16:09:47 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: ryan.finnie@canonical.com-20150831160947-1h6rfxby9z1ec62u
Merge WP4.3 from upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
68
68
 * @param int|object $category Category ID or Category row object
69
69
 * @param string $output Optional. Constant OBJECT, ARRAY_A, or ARRAY_N
70
70
 * @param string $filter Optional. Default is raw or no WordPress defined filter will applied.
71
 
 * @return object|array|WP_Error|null Category data in type defined by $output parameter. WP_Error if $category is empty, null if it does not exist.
 
71
 * @return object|array|WP_Error|null Category data in type defined by $output parameter.
 
72
 *                                    WP_Error if $category is empty, null if it does not exist.
72
73
 */
73
74
function get_category( $category, $output = OBJECT, $filter = 'raw' ) {
74
75
        $category = get_term( $category, 'category', $output, $filter );
98
99
 * @param string $category_path URL containing category slugs.
99
100
 * @param bool $full_match Optional. Whether full path should be matched.
100
101
 * @param string $output Optional. Constant OBJECT, ARRAY_A, or ARRAY_N
101
 
 * @return null|object|array Null on failure. Type is based on $output value.
 
102
 * @return object|array|WP_Error|void Type is based on $output value.
102
103
 */
103
104
function get_category_by_path( $category_path, $full_match = true, $output = OBJECT ) {
104
105
        $category_path = rawurlencode( urldecode( $category_path ) );
108
109
        $leaf_path  = sanitize_title( basename( $category_paths ) );
109
110
        $category_paths = explode( '/', $category_paths );
110
111
        $full_path = '';
111
 
        foreach ( (array) $category_paths as $pathdir )
 
112
        foreach ( (array) $category_paths as $pathdir ) {
112
113
                $full_path .= ( $pathdir != '' ? '/' : '' ) . sanitize_title( $pathdir );
113
 
 
 
114
        }
114
115
        $categories = get_terms( 'category', array('get' => 'all', 'slug' => $leaf_path) );
115
116
 
116
 
        if ( empty( $categories ) )
117
 
                return null;
 
117
        if ( empty( $categories ) ) {
 
118
                return;
 
119
        }
118
120
 
119
121
        foreach ( $categories as $category ) {
120
122
                $path = '/' . $leaf_path;
121
123
                $curcategory = $category;
122
124
                while ( ( $curcategory->parent != 0 ) && ( $curcategory->parent != $curcategory->term_id ) ) {
123
125
                        $curcategory = get_term( $curcategory->parent, 'category' );
124
 
                        if ( is_wp_error( $curcategory ) )
 
126
                        if ( is_wp_error( $curcategory ) ) {
125
127
                                return $curcategory;
 
128
                        }
126
129
                        $path = '/' . $curcategory->slug . $path;
127
130
                }
128
131
 
139
142
                _make_cat_compat( $category );
140
143
                return $category;
141
144
        }
142
 
 
143
 
        return null;
144
145
}
145
146
 
146
147
/**
321
322
 * @param array|object $category Category Row object or array
322
323
 */
323
324
function _make_cat_compat( &$category ) {
324
 
        if ( is_object( $category ) ) {
 
325
        if ( is_object( $category ) && ! is_wp_error( $category ) ) {
325
326
                $category->cat_ID = &$category->term_id;
326
327
                $category->category_count = &$category->count;
327
328
                $category->category_description = &$category->description;