author | ymh <ymh.work@gmail.com> |
Tue, 15 Dec 2020 13:49:49 +0100 | |
changeset 16 | a86126ab1dd4 |
parent 9 | 177826044cd9 |
child 18 | be944660c56a |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3 |
* Taxonomy API: Core category-specific template tags |
0 | 4 |
* |
5 |
* @package WordPress |
|
6 |
* @subpackage Template |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7 |
* @since 1.2.0 |
0 | 8 |
*/ |
9 |
||
10 |
/** |
|
16 | 11 |
* Retrieves category link URL. |
0 | 12 |
* |
13 |
* @since 1.0.0 |
|
16 | 14 |
* |
0 | 15 |
* @see get_term_link() |
16 |
* |
|
17 |
* @param int|object $category Category ID or object. |
|
18 |
* @return string Link on success, empty string if category does not exist. |
|
19 |
*/ |
|
20 |
function get_category_link( $category ) { |
|
9 | 21 |
if ( ! is_object( $category ) ) { |
0 | 22 |
$category = (int) $category; |
9 | 23 |
} |
0 | 24 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
25 |
$category = get_term_link( $category ); |
0 | 26 |
|
9 | 27 |
if ( is_wp_error( $category ) ) { |
0 | 28 |
return ''; |
9 | 29 |
} |
0 | 30 |
|
31 |
return $category; |
|
32 |
} |
|
33 |
||
34 |
/** |
|
16 | 35 |
* Retrieves category parents with separator. |
0 | 36 |
* |
37 |
* @since 1.2.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
38 |
* @since 4.8.0 The `$visited` parameter was deprecated and renamed to `$deprecated`. |
0 | 39 |
* |
16 | 40 |
* @param int $category_id Category ID. |
41 |
* @param bool $link Optional. Whether to format with link. Default false. |
|
42 |
* @param string $separator Optional. How to separate categories. Default '/'. |
|
43 |
* @param bool $nicename Optional. Whether to use nice name for display. Default false. |
|
44 |
* @param array $deprecated Not used. |
|
0 | 45 |
* @return string|WP_Error A list of category parents on success, WP_Error on failure. |
46 |
*/ |
|
16 | 47 |
function get_category_parents( $category_id, $link = false, $separator = '/', $nicename = false, $deprecated = array() ) { |
0 | 48 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
49 |
if ( ! empty( $deprecated ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
50 |
_deprecated_argument( __FUNCTION__, '4.8.0' ); |
0 | 51 |
} |
52 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
53 |
$format = $nicename ? 'slug' : 'name'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
54 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
55 |
$args = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
56 |
'separator' => $separator, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
57 |
'link' => $link, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
58 |
'format' => $format, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
59 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
60 |
|
16 | 61 |
return get_term_parents_list( $category_id, 'category', $args ); |
0 | 62 |
} |
63 |
||
64 |
/** |
|
16 | 65 |
* Retrieves post categories. |
0 | 66 |
* |
16 | 67 |
* This tag may be used outside The Loop by passing a post ID as the parameter. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
68 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
69 |
* Note: This function only returns results from the default "category" taxonomy. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
70 |
* For custom taxonomies use get_the_terms(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
71 |
* |
0 | 72 |
* @since 0.71 |
73 |
* |
|
16 | 74 |
* @param int $post_id Optional. The post ID. Defaults to current post ID. |
9 | 75 |
* @return WP_Term[] Array of WP_Term objects, one for each category assigned to the post. |
0 | 76 |
*/ |
16 | 77 |
function get_the_category( $post_id = false ) { |
78 |
$categories = get_the_terms( $post_id, 'category' ); |
|
9 | 79 |
if ( ! $categories || is_wp_error( $categories ) ) { |
0 | 80 |
$categories = array(); |
9 | 81 |
} |
0 | 82 |
|
83 |
$categories = array_values( $categories ); |
|
84 |
||
85 |
foreach ( array_keys( $categories ) as $key ) { |
|
9 | 86 |
_make_cat_compat( $categories[ $key ] ); |
0 | 87 |
} |
88 |
||
5 | 89 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
90 |
* Filters the array of categories to return for a post. |
5 | 91 |
* |
92 |
* @since 3.1.0 |
|
16 | 93 |
* @since 4.4.0 Added `$post_id` parameter. |
5 | 94 |
* |
9 | 95 |
* @param WP_Term[] $categories An array of categories to return for the post. |
16 | 96 |
* @param int|false $post_id ID of the post. |
5 | 97 |
*/ |
16 | 98 |
return apply_filters( 'get_the_categories', $categories, $post_id ); |
0 | 99 |
} |
100 |
||
101 |
/** |
|
16 | 102 |
* Retrieves category name based on category ID. |
0 | 103 |
* |
104 |
* @since 0.71 |
|
105 |
* |
|
106 |
* @param int $cat_ID Category ID. |
|
107 |
* @return string|WP_Error Category name on success, WP_Error on failure. |
|
108 |
*/ |
|
16 | 109 |
function get_the_category_by_ID( $cat_ID ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid |
9 | 110 |
$cat_ID = (int) $cat_ID; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
111 |
$category = get_term( $cat_ID ); |
5 | 112 |
|
9 | 113 |
if ( is_wp_error( $category ) ) { |
0 | 114 |
return $category; |
9 | 115 |
} |
5 | 116 |
|
117 |
return ( $category ) ? $category->name : ''; |
|
0 | 118 |
} |
119 |
||
120 |
/** |
|
16 | 121 |
* Retrieves category list for a post in either HTML list or custom format. |
122 |
* |
|
123 |
* Generally used for quick, delimited (e.g. comma-separated) lists of categories, |
|
124 |
* as part of a post entry meta. |
|
125 |
* |
|
126 |
* For a more powerful, list-based function, see wp_list_categories(). |
|
0 | 127 |
* |
128 |
* @since 1.5.1 |
|
129 |
* |
|
16 | 130 |
* @see wp_list_categories() |
131 |
* |
|
132 |
* @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
133 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
134 |
* @param string $separator Optional. Separator between the categories. By default, the links are placed |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
135 |
* in an unordered list. An empty string will result in the default behavior. |
16 | 136 |
* @param string $parents Optional. How to display the parents. |
137 |
* @param int $post_id Optional. Post ID to retrieve categories. |
|
138 |
* @return string Category list for a post. |
|
0 | 139 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
140 |
function get_the_category_list( $separator = '', $parents = '', $post_id = false ) { |
0 | 141 |
global $wp_rewrite; |
16 | 142 |
|
5 | 143 |
if ( ! is_object_in_taxonomy( get_post_type( $post_id ), 'category' ) ) { |
144 |
/** This filter is documented in wp-includes/category-template.php */ |
|
0 | 145 |
return apply_filters( 'the_category', '', $separator, $parents ); |
5 | 146 |
} |
0 | 147 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
148 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
149 |
* Filters the categories before building the category list. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
150 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
151 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
152 |
* |
9 | 153 |
* @param WP_Term[] $categories An array of the post's categories. |
16 | 154 |
* @param int|bool $post_id ID of the post we're retrieving categories for. |
155 |
* When `false`, we assume the current post in the loop. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
156 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
157 |
$categories = apply_filters( 'the_category_list', get_the_category( $post_id ), $post_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
158 |
|
5 | 159 |
if ( empty( $categories ) ) { |
160 |
/** This filter is documented in wp-includes/category-template.php */ |
|
0 | 161 |
return apply_filters( 'the_category', __( 'Uncategorized' ), $separator, $parents ); |
5 | 162 |
} |
0 | 163 |
|
164 |
$rel = ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) ? 'rel="category tag"' : 'rel="category"'; |
|
165 |
||
166 |
$thelist = ''; |
|
16 | 167 |
if ( '' === $separator ) { |
0 | 168 |
$thelist .= '<ul class="post-categories">'; |
169 |
foreach ( $categories as $category ) { |
|
170 |
$thelist .= "\n\t<li>"; |
|
171 |
switch ( strtolower( $parents ) ) { |
|
172 |
case 'multiple': |
|
9 | 173 |
if ( $category->parent ) { |
0 | 174 |
$thelist .= get_category_parents( $category->parent, true, $separator ); |
9 | 175 |
} |
176 |
$thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>' . $category->name . '</a></li>'; |
|
0 | 177 |
break; |
178 |
case 'single': |
|
5 | 179 |
$thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>'; |
9 | 180 |
if ( $category->parent ) { |
0 | 181 |
$thelist .= get_category_parents( $category->parent, false, $separator ); |
9 | 182 |
} |
183 |
$thelist .= $category->name . '</a></li>'; |
|
0 | 184 |
break; |
185 |
case '': |
|
186 |
default: |
|
9 | 187 |
$thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>' . $category->name . '</a></li>'; |
0 | 188 |
} |
189 |
} |
|
190 |
$thelist .= '</ul>'; |
|
191 |
} else { |
|
192 |
$i = 0; |
|
193 |
foreach ( $categories as $category ) { |
|
9 | 194 |
if ( 0 < $i ) { |
0 | 195 |
$thelist .= $separator; |
9 | 196 |
} |
0 | 197 |
switch ( strtolower( $parents ) ) { |
198 |
case 'multiple': |
|
9 | 199 |
if ( $category->parent ) { |
0 | 200 |
$thelist .= get_category_parents( $category->parent, true, $separator ); |
9 | 201 |
} |
202 |
$thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>' . $category->name . '</a>'; |
|
0 | 203 |
break; |
204 |
case 'single': |
|
5 | 205 |
$thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>'; |
9 | 206 |
if ( $category->parent ) { |
0 | 207 |
$thelist .= get_category_parents( $category->parent, false, $separator ); |
9 | 208 |
} |
0 | 209 |
$thelist .= "$category->name</a>"; |
210 |
break; |
|
211 |
case '': |
|
212 |
default: |
|
9 | 213 |
$thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>' . $category->name . '</a>'; |
0 | 214 |
} |
215 |
++$i; |
|
216 |
} |
|
217 |
} |
|
5 | 218 |
|
219 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
220 |
* Filters the category or list of categories. |
5 | 221 |
* |
222 |
* @since 1.2.0 |
|
223 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
224 |
* @param string $thelist List of categories for the current post. |
5 | 225 |
* @param string $separator Separator used between the categories. |
226 |
* @param string $parents How to display the category parents. Accepts 'multiple', |
|
227 |
* 'single', or empty. |
|
228 |
*/ |
|
0 | 229 |
return apply_filters( 'the_category', $thelist, $separator, $parents ); |
230 |
} |
|
231 |
||
232 |
/** |
|
9 | 233 |
* Checks if the current post is within any of the given categories. |
0 | 234 |
* |
235 |
* The given categories are checked against the post's categories' term_ids, names and slugs. |
|
236 |
* Categories given as integers will only be checked against the post's categories' term_ids. |
|
237 |
* |
|
238 |
* Prior to v2.5 of WordPress, category names were not supported. |
|
239 |
* Prior to v2.7, category slugs were not supported. |
|
240 |
* Prior to v2.7, only one category could be compared: in_category( $single_category ). |
|
241 |
* Prior to v2.7, this function could only be used in the WordPress Loop. |
|
242 |
* As of 2.7, the function can be used anywhere if it is provided a post ID or post object. |
|
243 |
* |
|
9 | 244 |
* For more information on this and similar theme functions, check out |
245 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
246 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
247 |
* |
|
0 | 248 |
* @since 1.2.0 |
16 | 249 |
* @since 2.7.0 The `$post` parameter was added. |
0 | 250 |
* |
251 |
* @param int|string|array $category Category ID, name or slug, or array of said. |
|
16 | 252 |
* @param int|object $post Optional. Post to check instead of the current post. |
0 | 253 |
* @return bool True if the current post is in any of the given categories. |
254 |
*/ |
|
255 |
function in_category( $category, $post = null ) { |
|
9 | 256 |
if ( empty( $category ) ) { |
0 | 257 |
return false; |
9 | 258 |
} |
0 | 259 |
|
260 |
return has_category( $category, $post ); |
|
261 |
} |
|
262 |
||
263 |
/** |
|
16 | 264 |
* Displays category list for a post in either HTML list or custom format. |
0 | 265 |
* |
266 |
* @since 0.71 |
|
267 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
268 |
* @param string $separator Optional. Separator between the categories. By default, the links are placed |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
269 |
* in an unordered list. An empty string will result in the default behavior. |
16 | 270 |
* @param string $parents Optional. How to display the parents. |
271 |
* @param int $post_id Optional. Post ID to retrieve categories. |
|
0 | 272 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
273 |
function the_category( $separator = '', $parents = '', $post_id = false ) { |
0 | 274 |
echo get_the_category_list( $separator, $parents, $post_id ); |
275 |
} |
|
276 |
||
277 |
/** |
|
16 | 278 |
* Retrieves category description. |
0 | 279 |
* |
280 |
* @since 1.0.0 |
|
281 |
* |
|
16 | 282 |
* @param int $category Optional. Category ID. Defaults to the current category ID. |
283 |
* @return string Category description, if available. |
|
0 | 284 |
*/ |
285 |
function category_description( $category = 0 ) { |
|
9 | 286 |
return term_description( $category ); |
0 | 287 |
} |
288 |
||
289 |
/** |
|
16 | 290 |
* Displays or retrieves the HTML dropdown list of categories. |
0 | 291 |
* |
292 |
* The 'hierarchical' argument, which is disabled by default, will override the |
|
293 |
* depth argument, unless it is true. When the argument is false, it will |
|
294 |
* display all of the categories. When it is enabled it will use the value in |
|
295 |
* the 'depth' argument. |
|
296 |
* |
|
297 |
* @since 2.1.0 |
|
5 | 298 |
* @since 4.2.0 Introduced the `value_field` argument. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
299 |
* @since 4.6.0 Introduced the `required` argument. |
0 | 300 |
* |
16 | 301 |
* @param array|string $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
302 |
* Optional. Array or string of arguments to generate a categories drop-down element. See WP_Term_Query::__construct() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
303 |
* for information on additional accepted arguments. |
5 | 304 |
* |
305 |
* @type string $show_option_all Text to display for showing all categories. Default empty. |
|
306 |
* @type string $show_option_none Text to display for showing no categories. Default empty. |
|
307 |
* @type string $option_none_value Value to use when no category is selected. Default empty. |
|
308 |
* @type string $orderby Which column to use for ordering categories. See get_terms() for a list |
|
309 |
* of accepted values. Default 'id' (term_id). |
|
310 |
* @type bool $pad_counts See get_terms() for an argument description. Default false. |
|
311 |
* @type bool|int $show_count Whether to include post counts. Accepts 0, 1, or their bool equivalents. |
|
312 |
* Default 0. |
|
313 |
* @type bool|int $echo Whether to echo or return the generated markup. Accepts 0, 1, or their |
|
314 |
* bool equivalents. Default 1. |
|
315 |
* @type bool|int $hierarchical Whether to traverse the taxonomy hierarchy. Accepts 0, 1, or their bool |
|
316 |
* equivalents. Default 0. |
|
317 |
* @type int $depth Maximum depth. Default 0. |
|
318 |
* @type int $tab_index Tab index for the select element. Default 0 (no tabindex). |
|
319 |
* @type string $name Value for the 'name' attribute of the select element. Default 'cat'. |
|
320 |
* @type string $id Value for the 'id' attribute of the select element. Defaults to the value |
|
321 |
* of `$name`. |
|
322 |
* @type string $class Value for the 'class' attribute of the select element. Default 'postform'. |
|
323 |
* @type int|string $selected Value of the option that should be selected. Default 0. |
|
324 |
* @type string $value_field Term field that should be used to populate the 'value' attribute |
|
325 |
* of the option elements. Accepts any valid term field: 'term_id', 'name', |
|
326 |
* 'slug', 'term_group', 'term_taxonomy_id', 'taxonomy', 'description', |
|
327 |
* 'parent', 'count'. Default 'term_id'. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
328 |
* @type string|array $taxonomy Name of the category or categories to retrieve. Default 'category'. |
5 | 329 |
* @type bool $hide_if_empty True to skip generating markup if no categories are found. |
330 |
* Default false (create select element even if no categories are found). |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
331 |
* @type bool $required Whether the `<select>` element should have the HTML5 'required' attribute. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
332 |
* Default false. |
5 | 333 |
* } |
16 | 334 |
* @return string HTML dropdown list of categories. |
0 | 335 |
*/ |
336 |
function wp_dropdown_categories( $args = '' ) { |
|
337 |
$defaults = array( |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
338 |
'show_option_all' => '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
339 |
'show_option_none' => '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
340 |
'orderby' => 'id', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
341 |
'order' => 'ASC', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
342 |
'show_count' => 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
343 |
'hide_empty' => 1, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
344 |
'child_of' => 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
345 |
'exclude' => '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
346 |
'echo' => 1, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
347 |
'selected' => 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
348 |
'hierarchical' => 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
349 |
'name' => 'cat', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
350 |
'id' => '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
351 |
'class' => 'postform', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
352 |
'depth' => 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
353 |
'tab_index' => 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
354 |
'taxonomy' => 'category', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
355 |
'hide_if_empty' => false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
356 |
'option_none_value' => -1, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
357 |
'value_field' => 'term_id', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
358 |
'required' => false, |
0 | 359 |
); |
360 |
||
361 |
$defaults['selected'] = ( is_category() ) ? get_query_var( 'cat' ) : 0; |
|
362 |
||
363 |
// Back compat. |
|
16 | 364 |
if ( isset( $args['type'] ) && 'link' === $args['type'] ) { |
9 | 365 |
_deprecated_argument( |
366 |
__FUNCTION__, |
|
367 |
'3.0.0', |
|
368 |
sprintf( |
|
16 | 369 |
/* translators: 1: "type => link", 2: "taxonomy => link_category" */ |
9 | 370 |
__( '%1$s is deprecated. Use %2$s instead.' ), |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
371 |
'<code>type => link</code>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
372 |
'<code>taxonomy => link_category</code>' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
373 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
374 |
); |
0 | 375 |
$args['taxonomy'] = 'link_category'; |
376 |
} |
|
377 |
||
16 | 378 |
// Parse incoming $args into an array and merge it with $defaults. |
379 |
$parsed_args = wp_parse_args( $args, $defaults ); |
|
0 | 380 |
|
16 | 381 |
$option_none_value = $parsed_args['option_none_value']; |
382 |
||
383 |
if ( ! isset( $parsed_args['pad_counts'] ) && $parsed_args['show_count'] && $parsed_args['hierarchical'] ) { |
|
384 |
$parsed_args['pad_counts'] = true; |
|
0 | 385 |
} |
386 |
||
16 | 387 |
$tab_index = $parsed_args['tab_index']; |
0 | 388 |
|
389 |
$tab_index_attribute = ''; |
|
5 | 390 |
if ( (int) $tab_index > 0 ) { |
0 | 391 |
$tab_index_attribute = " tabindex=\"$tab_index\""; |
5 | 392 |
} |
0 | 393 |
|
5 | 394 |
// Avoid clashes with the 'name' param of get_terms(). |
16 | 395 |
$get_terms_args = $parsed_args; |
5 | 396 |
unset( $get_terms_args['name'] ); |
16 | 397 |
$categories = get_terms( $get_terms_args ); |
5 | 398 |
|
16 | 399 |
$name = esc_attr( $parsed_args['name'] ); |
400 |
$class = esc_attr( $parsed_args['class'] ); |
|
401 |
$id = $parsed_args['id'] ? esc_attr( $parsed_args['id'] ) : $name; |
|
402 |
$required = $parsed_args['required'] ? 'required' : ''; |
|
0 | 403 |
|
16 | 404 |
if ( ! $parsed_args['hide_if_empty'] || ! empty( $categories ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
405 |
$output = "<select $required name='$name' id='$id' class='$class' $tab_index_attribute>\n"; |
5 | 406 |
} else { |
0 | 407 |
$output = ''; |
5 | 408 |
} |
16 | 409 |
if ( empty( $categories ) && ! $parsed_args['hide_if_empty'] && ! empty( $parsed_args['show_option_none'] ) ) { |
0 | 410 |
|
5 | 411 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
412 |
* Filters a taxonomy drop-down display element. |
5 | 413 |
* |
414 |
* A variety of taxonomy drop-down display elements can be modified |
|
415 |
* just prior to display via this filter. Filterable arguments include |
|
416 |
* 'show_option_none', 'show_option_all', and various forms of the |
|
417 |
* term name. |
|
418 |
* |
|
419 |
* @since 1.2.0 |
|
420 |
* |
|
421 |
* @see wp_dropdown_categories() |
|
422 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
423 |
* @param string $element Category name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
424 |
* @param WP_Term|null $category The category object, or null if there's no corresponding category. |
5 | 425 |
*/ |
16 | 426 |
$show_option_none = apply_filters( 'list_cats', $parsed_args['show_option_none'], null ); |
9 | 427 |
$output .= "\t<option value='" . esc_attr( $option_none_value ) . "' selected='selected'>$show_option_none</option>\n"; |
0 | 428 |
} |
429 |
||
430 |
if ( ! empty( $categories ) ) { |
|
431 |
||
16 | 432 |
if ( $parsed_args['show_option_all'] ) { |
5 | 433 |
|
434 |
/** This filter is documented in wp-includes/category-template.php */ |
|
16 | 435 |
$show_option_all = apply_filters( 'list_cats', $parsed_args['show_option_all'], null ); |
436 |
$selected = ( '0' === strval( $parsed_args['selected'] ) ) ? " selected='selected'" : ''; |
|
9 | 437 |
$output .= "\t<option value='0'$selected>$show_option_all</option>\n"; |
0 | 438 |
} |
439 |
||
16 | 440 |
if ( $parsed_args['show_option_none'] ) { |
5 | 441 |
|
442 |
/** This filter is documented in wp-includes/category-template.php */ |
|
16 | 443 |
$show_option_none = apply_filters( 'list_cats', $parsed_args['show_option_none'], null ); |
444 |
$selected = selected( $option_none_value, $parsed_args['selected'], false ); |
|
9 | 445 |
$output .= "\t<option value='" . esc_attr( $option_none_value ) . "'$selected>$show_option_none</option>\n"; |
0 | 446 |
} |
447 |
||
16 | 448 |
if ( $parsed_args['hierarchical'] ) { |
449 |
$depth = $parsed_args['depth']; // Walk the full depth. |
|
5 | 450 |
} else { |
0 | 451 |
$depth = -1; // Flat. |
5 | 452 |
} |
16 | 453 |
$output .= walk_category_dropdown_tree( $categories, $depth, $parsed_args ); |
0 | 454 |
} |
455 |
||
16 | 456 |
if ( ! $parsed_args['hide_if_empty'] || ! empty( $categories ) ) { |
0 | 457 |
$output .= "</select>\n"; |
5 | 458 |
} |
16 | 459 |
|
5 | 460 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
461 |
* Filters the taxonomy drop-down output. |
5 | 462 |
* |
463 |
* @since 2.1.0 |
|
464 |
* |
|
16 | 465 |
* @param string $output HTML output. |
466 |
* @param array $parsed_args Arguments used to build the drop-down. |
|
5 | 467 |
*/ |
16 | 468 |
$output = apply_filters( 'wp_dropdown_cats', $output, $parsed_args ); |
0 | 469 |
|
16 | 470 |
if ( $parsed_args['echo'] ) { |
0 | 471 |
echo $output; |
5 | 472 |
} |
16 | 473 |
|
0 | 474 |
return $output; |
475 |
} |
|
476 |
||
477 |
/** |
|
16 | 478 |
* Displays or retrieves the HTML list of categories. |
0 | 479 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
480 |
* @since 2.1.0 |
16 | 481 |
* @since 4.4.0 Introduced the `hide_title_if_empty` and `separator` arguments. |
482 |
* @since 4.4.0 The `current_category` argument was modified to optionally accept an array of values. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
483 |
* |
16 | 484 |
* @param array|string $args { |
485 |
* Array of optional arguments. See get_categories(), get_terms(), and WP_Term_Query::__construct() |
|
486 |
* for information on additional accepted arguments. |
|
0 | 487 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
488 |
* @type int|array $current_category ID of category, or array of IDs of categories, that should get the |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
489 |
* 'current-cat' class. Default 0. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
490 |
* @type int $depth Category depth. Used for tab indentation. Default 0. |
16 | 491 |
* @type bool|int $echo Whether to echo or return the generated markup. Accepts 0, 1, or their |
492 |
* bool equivalents. Default 1. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
493 |
* @type array|string $exclude Array or comma/space-separated string of term IDs to exclude. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
494 |
* If `$hierarchical` is true, descendants of `$exclude` terms will also |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
495 |
* be excluded; see `$exclude_tree`. See get_terms(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
496 |
* Default empty string. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
497 |
* @type array|string $exclude_tree Array or comma/space-separated string of term IDs to exclude, along |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
498 |
* with their descendants. See get_terms(). Default empty string. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
499 |
* @type string $feed Text to use for the feed link. Default 'Feed for all posts filed |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
500 |
* under [cat name]'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
501 |
* @type string $feed_image URL of an image to use for the feed link. Default empty string. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
502 |
* @type string $feed_type Feed type. Used to build feed link. See get_term_feed_link(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
503 |
* Default empty string (default feed). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
504 |
* @type bool $hide_title_if_empty Whether to hide the `$title_li` element if there are no terms in |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
505 |
* the list. Default false (title will always be shown). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
506 |
* @type string $separator Separator between links. Default '<br />'. |
16 | 507 |
* @type bool|int $show_count Whether to include post counts. Accepts 0, 1, or their bool equivalents. |
508 |
* Default 0. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
509 |
* @type string $show_option_all Text to display for showing all categories. Default empty string. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
510 |
* @type string $show_option_none Text to display for the 'no categories' option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
511 |
* Default 'No categories'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
512 |
* @type string $style The style used to display the categories list. If 'list', categories |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
513 |
* will be output as an unordered list. If left empty or another value, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
514 |
* categories will be output separated by `<br>` tags. Default 'list'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
515 |
* @type string $title_li Text to use for the list title `<li>` element. Pass an empty string |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
516 |
* to disable. Default 'Categories'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
517 |
* @type bool|int $use_desc_for_title Whether to use the category description as the title attribute. |
16 | 518 |
* Accepts 0, 1, or their bool equivalents. Default 1. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
519 |
* } |
16 | 520 |
* @return void|string|false Void if 'echo' argument is true, HTML list of categories if 'echo' is false. |
521 |
* False if the taxonomy does not exist. |
|
0 | 522 |
*/ |
523 |
function wp_list_categories( $args = '' ) { |
|
524 |
$defaults = array( |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
525 |
'child_of' => 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
526 |
'current_category' => 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
527 |
'depth' => 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
528 |
'echo' => 1, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
529 |
'exclude' => '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
530 |
'exclude_tree' => '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
531 |
'feed' => '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
532 |
'feed_image' => '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
533 |
'feed_type' => '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
534 |
'hide_empty' => 1, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
535 |
'hide_title_if_empty' => false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
536 |
'hierarchical' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
537 |
'order' => 'ASC', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
538 |
'orderby' => 'name', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
539 |
'separator' => '<br />', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
540 |
'show_count' => 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
541 |
'show_option_all' => '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
542 |
'show_option_none' => __( 'No categories' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
543 |
'style' => 'list', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
544 |
'taxonomy' => 'category', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
545 |
'title_li' => __( 'Categories' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
546 |
'use_desc_for_title' => 1, |
0 | 547 |
); |
548 |
||
16 | 549 |
$parsed_args = wp_parse_args( $args, $defaults ); |
0 | 550 |
|
16 | 551 |
if ( ! isset( $parsed_args['pad_counts'] ) && $parsed_args['show_count'] && $parsed_args['hierarchical'] ) { |
552 |
$parsed_args['pad_counts'] = true; |
|
9 | 553 |
} |
0 | 554 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
555 |
// Descendants of exclusions should be excluded too. |
16 | 556 |
if ( true == $parsed_args['hierarchical'] ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
557 |
$exclude_tree = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
558 |
|
16 | 559 |
if ( $parsed_args['exclude_tree'] ) { |
560 |
$exclude_tree = array_merge( $exclude_tree, wp_parse_id_list( $parsed_args['exclude_tree'] ) ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
561 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
562 |
|
16 | 563 |
if ( $parsed_args['exclude'] ) { |
564 |
$exclude_tree = array_merge( $exclude_tree, wp_parse_id_list( $parsed_args['exclude'] ) ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
565 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
566 |
|
16 | 567 |
$parsed_args['exclude_tree'] = $exclude_tree; |
568 |
$parsed_args['exclude'] = ''; |
|
0 | 569 |
} |
570 |
||
16 | 571 |
if ( ! isset( $parsed_args['class'] ) ) { |
572 |
$parsed_args['class'] = ( 'category' === $parsed_args['taxonomy'] ) ? 'categories' : $parsed_args['taxonomy']; |
|
9 | 573 |
} |
0 | 574 |
|
16 | 575 |
if ( ! taxonomy_exists( $parsed_args['taxonomy'] ) ) { |
5 | 576 |
return false; |
577 |
} |
|
0 | 578 |
|
16 | 579 |
$show_option_all = $parsed_args['show_option_all']; |
580 |
$show_option_none = $parsed_args['show_option_none']; |
|
0 | 581 |
|
16 | 582 |
$categories = get_categories( $parsed_args ); |
0 | 583 |
|
584 |
$output = ''; |
|
16 | 585 |
|
586 |
if ( $parsed_args['title_li'] && 'list' === $parsed_args['style'] |
|
587 |
&& ( ! empty( $categories ) || ! $parsed_args['hide_title_if_empty'] ) |
|
588 |
) { |
|
589 |
$output = '<li class="' . esc_attr( $parsed_args['class'] ) . '">' . $parsed_args['title_li'] . '<ul>'; |
|
5 | 590 |
} |
16 | 591 |
|
0 | 592 |
if ( empty( $categories ) ) { |
593 |
if ( ! empty( $show_option_none ) ) { |
|
16 | 594 |
if ( 'list' === $parsed_args['style'] ) { |
5 | 595 |
$output .= '<li class="cat-item-none">' . $show_option_none . '</li>'; |
596 |
} else { |
|
0 | 597 |
$output .= $show_option_none; |
5 | 598 |
} |
0 | 599 |
} |
600 |
} else { |
|
601 |
if ( ! empty( $show_option_all ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
602 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
603 |
$posts_page = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
604 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
605 |
// For taxonomies that belong only to custom post types, point to a valid archive. |
16 | 606 |
$taxonomy_object = get_taxonomy( $parsed_args['taxonomy'] ); |
607 |
if ( ! in_array( 'post', $taxonomy_object->object_type, true ) && ! in_array( 'page', $taxonomy_object->object_type, true ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
608 |
foreach ( $taxonomy_object->object_type as $object_type ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
609 |
$_object_type = get_post_type_object( $object_type ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
610 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
611 |
// Grab the first one. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
612 |
if ( ! empty( $_object_type->has_archive ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
613 |
$posts_page = get_post_type_archive_link( $object_type ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
614 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
615 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
616 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
617 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
618 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
619 |
// Fallback for the 'All' link is the posts page. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
620 |
if ( ! $posts_page ) { |
16 | 621 |
if ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
622 |
$posts_page = get_permalink( get_option( 'page_for_posts' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
623 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
624 |
$posts_page = home_url( '/' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
625 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
626 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
627 |
|
0 | 628 |
$posts_page = esc_url( $posts_page ); |
16 | 629 |
if ( 'list' === $parsed_args['style'] ) { |
5 | 630 |
$output .= "<li class='cat-item-all'><a href='$posts_page'>$show_option_all</a></li>"; |
631 |
} else { |
|
0 | 632 |
$output .= "<a href='$posts_page'>$show_option_all</a>"; |
5 | 633 |
} |
0 | 634 |
} |
635 |
||
16 | 636 |
if ( empty( $parsed_args['current_category'] ) && ( is_category() || is_tax() || is_tag() ) ) { |
0 | 637 |
$current_term_object = get_queried_object(); |
16 | 638 |
if ( $current_term_object && $parsed_args['taxonomy'] === $current_term_object->taxonomy ) { |
639 |
$parsed_args['current_category'] = get_queried_object_id(); |
|
5 | 640 |
} |
0 | 641 |
} |
642 |
||
16 | 643 |
if ( $parsed_args['hierarchical'] ) { |
644 |
$depth = $parsed_args['depth']; |
|
5 | 645 |
} else { |
0 | 646 |
$depth = -1; // Flat. |
5 | 647 |
} |
16 | 648 |
$output .= walk_category_tree( $categories, $depth, $parsed_args ); |
0 | 649 |
} |
650 |
||
16 | 651 |
if ( $parsed_args['title_li'] && 'list' === $parsed_args['style'] |
652 |
&& ( ! empty( $categories ) || ! $parsed_args['hide_title_if_empty'] ) |
|
653 |
) { |
|
0 | 654 |
$output .= '</ul></li>'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
655 |
} |
0 | 656 |
|
5 | 657 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
658 |
* Filters the HTML output of a taxonomy list. |
5 | 659 |
* |
660 |
* @since 2.1.0 |
|
661 |
* |
|
662 |
* @param string $output HTML output. |
|
663 |
* @param array $args An array of taxonomy-listing arguments. |
|
664 |
*/ |
|
665 |
$html = apply_filters( 'wp_list_categories', $output, $args ); |
|
0 | 666 |
|
16 | 667 |
if ( $parsed_args['echo'] ) { |
5 | 668 |
echo $html; |
669 |
} else { |
|
670 |
return $html; |
|
671 |
} |
|
0 | 672 |
} |
673 |
||
674 |
/** |
|
9 | 675 |
* Displays a tag cloud. |
0 | 676 |
* |
16 | 677 |
* Outputs a list of tags in what is called a 'tag cloud', where the size of each tag |
678 |
* is determined by how many times that particular tag has been assigned to posts. |
|
679 |
* |
|
0 | 680 |
* @since 2.3.0 |
16 | 681 |
* @since 2.8.0 Added the `taxonomy` argument. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
682 |
* @since 4.8.0 Added the `show_count` argument. |
0 | 683 |
* |
9 | 684 |
* @param array|string $args { |
685 |
* Optional. Array or string of arguments for displaying a tag cloud. See wp_generate_tag_cloud() |
|
686 |
* and get_terms() for the full lists of arguments that can be passed in `$args`. |
|
687 |
* |
|
688 |
* @type int $number The number of tags to display. Accepts any positive integer |
|
689 |
* or zero to return all. Default 0 (all tags). |
|
690 |
* @type string $link Whether to display term editing links or term permalinks. |
|
691 |
* Accepts 'edit' and 'view'. Default 'view'. |
|
692 |
* @type string $post_type The post type. Used to highlight the proper post type menu |
|
693 |
* on the linked edit page. Defaults to the first post type |
|
694 |
* associated with the taxonomy. |
|
695 |
* @type bool $echo Whether or not to echo the return value. Default true. |
|
696 |
* } |
|
16 | 697 |
* @return void|string|array Void if 'echo' argument is true, or on failure. Otherwise, tag cloud |
698 |
* as a string or an array, depending on 'format' argument. |
|
0 | 699 |
*/ |
700 |
function wp_tag_cloud( $args = '' ) { |
|
701 |
$defaults = array( |
|
9 | 702 |
'smallest' => 8, |
703 |
'largest' => 22, |
|
704 |
'unit' => 'pt', |
|
705 |
'number' => 45, |
|
706 |
'format' => 'flat', |
|
707 |
'separator' => "\n", |
|
708 |
'orderby' => 'name', |
|
709 |
'order' => 'ASC', |
|
710 |
'exclude' => '', |
|
711 |
'include' => '', |
|
712 |
'link' => 'view', |
|
713 |
'taxonomy' => 'post_tag', |
|
714 |
'post_type' => '', |
|
715 |
'echo' => true, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
716 |
'show_count' => 0, |
0 | 717 |
); |
16 | 718 |
|
719 |
$args = wp_parse_args( $args, $defaults ); |
|
0 | 720 |
|
9 | 721 |
$tags = get_terms( |
722 |
array_merge( |
|
723 |
$args, |
|
724 |
array( |
|
725 |
'orderby' => 'count', |
|
726 |
'order' => 'DESC', |
|
727 |
) |
|
728 |
) |
|
16 | 729 |
); // Always query top tags. |
0 | 730 |
|
9 | 731 |
if ( empty( $tags ) || is_wp_error( $tags ) ) { |
0 | 732 |
return; |
9 | 733 |
} |
0 | 734 |
|
735 |
foreach ( $tags as $key => $tag ) { |
|
16 | 736 |
if ( 'edit' === $args['link'] ) { |
5 | 737 |
$link = get_edit_term_link( $tag->term_id, $tag->taxonomy, $args['post_type'] ); |
9 | 738 |
} else { |
739 |
$link = get_term_link( intval( $tag->term_id ), $tag->taxonomy ); |
|
740 |
} |
|
16 | 741 |
|
9 | 742 |
if ( is_wp_error( $link ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
743 |
return; |
9 | 744 |
} |
0 | 745 |
|
746 |
$tags[ $key ]->link = $link; |
|
9 | 747 |
$tags[ $key ]->id = $tag->term_id; |
0 | 748 |
} |
749 |
||
16 | 750 |
// Here's where those top tags get sorted according to $args. |
751 |
$return = wp_generate_tag_cloud( $tags, $args ); |
|
0 | 752 |
|
5 | 753 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
754 |
* Filters the tag cloud output. |
5 | 755 |
* |
756 |
* @since 2.3.0 |
|
757 |
* |
|
16 | 758 |
* @param string|array $return Tag cloud as a string or an array, depending on 'format' argument. |
759 |
* @param array $args An array of tag cloud arguments. |
|
5 | 760 |
*/ |
0 | 761 |
$return = apply_filters( 'wp_tag_cloud', $return, $args ); |
762 |
||
16 | 763 |
if ( 'array' === $args['format'] || empty( $args['echo'] ) ) { |
0 | 764 |
return $return; |
9 | 765 |
} |
0 | 766 |
|
767 |
echo $return; |
|
768 |
} |
|
769 |
||
770 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
771 |
* Default topic count scaling for tag links. |
0 | 772 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
773 |
* @since 2.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
774 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
775 |
* @param int $count Number of posts with that tag. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
776 |
* @return int Scaled count. |
0 | 777 |
*/ |
778 |
function default_topic_count_scale( $count ) { |
|
9 | 779 |
return round( log10( $count + 1 ) * 100 ); |
0 | 780 |
} |
781 |
||
782 |
/** |
|
783 |
* Generates a tag cloud (heatmap) from provided data. |
|
784 |
* |
|
785 |
* @todo Complete functionality. |
|
786 |
* @since 2.3.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
787 |
* @since 4.8.0 Added the `show_count` argument. |
0 | 788 |
* |
9 | 789 |
* @param WP_Term[] $tags Array of WP_Term objects to generate the tag cloud for. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
790 |
* @param string|array $args { |
9 | 791 |
* Optional. Array or string of arguments for generating a tag cloud. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
792 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
793 |
* @type int $smallest Smallest font size used to display tags. Paired |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
794 |
* with the value of `$unit`, to determine CSS text |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
795 |
* size unit. Default 8 (pt). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
796 |
* @type int $largest Largest font size used to display tags. Paired |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
797 |
* with the value of `$unit`, to determine CSS text |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
798 |
* size unit. Default 22 (pt). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
799 |
* @type string $unit CSS text size unit to use with the `$smallest` |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
800 |
* and `$largest` values. Accepts any valid CSS text |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
801 |
* size unit. Default 'pt'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
802 |
* @type int $number The number of tags to return. Accepts any |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
803 |
* positive integer or zero to return all. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
804 |
* Default 0. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
805 |
* @type string $format Format to display the tag cloud in. Accepts 'flat' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
806 |
* (tags separated with spaces), 'list' (tags displayed |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
807 |
* in an unordered list), or 'array' (returns an array). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
808 |
* Default 'flat'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
809 |
* @type string $separator HTML or text to separate the tags. Default "\n" (newline). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
810 |
* @type string $orderby Value to order tags by. Accepts 'name' or 'count'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
811 |
* Default 'name'. The {@see 'tag_cloud_sort'} filter |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
812 |
* can also affect how tags are sorted. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
813 |
* @type string $order How to order the tags. Accepts 'ASC' (ascending), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
814 |
* 'DESC' (descending), or 'RAND' (random). Default 'ASC'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
815 |
* @type int|bool $filter Whether to enable filtering of the final output |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
816 |
* via {@see 'wp_generate_tag_cloud'}. Default 1|true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
817 |
* @type string $topic_count_text Nooped plural text from _n_noop() to supply to |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
818 |
* tag counts. Default null. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
819 |
* @type callable $topic_count_text_callback Callback used to generate nooped plural text for |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
820 |
* tag counts based on the count. Default null. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
821 |
* @type callable $topic_count_scale_callback Callback used to determine the tag count scaling |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
822 |
* value. Default default_topic_count_scale(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
823 |
* @type bool|int $show_count Whether to display the tag counts. Default 0. Accepts |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
824 |
* 0, 1, or their bool equivalents. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
825 |
* } |
5 | 826 |
* @return string|array Tag cloud as a string or an array, depending on 'format' argument. |
0 | 827 |
*/ |
828 |
function wp_generate_tag_cloud( $tags, $args = '' ) { |
|
829 |
$defaults = array( |
|
9 | 830 |
'smallest' => 8, |
831 |
'largest' => 22, |
|
832 |
'unit' => 'pt', |
|
833 |
'number' => 0, |
|
834 |
'format' => 'flat', |
|
835 |
'separator' => "\n", |
|
836 |
'orderby' => 'name', |
|
837 |
'order' => 'ASC', |
|
838 |
'topic_count_text' => null, |
|
839 |
'topic_count_text_callback' => null, |
|
840 |
'topic_count_scale_callback' => 'default_topic_count_scale', |
|
841 |
'filter' => 1, |
|
842 |
'show_count' => 0, |
|
0 | 843 |
); |
844 |
||
5 | 845 |
$args = wp_parse_args( $args, $defaults ); |
846 |
||
847 |
$return = ( 'array' === $args['format'] ) ? array() : ''; |
|
848 |
||
849 |
if ( empty( $tags ) ) { |
|
850 |
return $return; |
|
851 |
} |
|
852 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
853 |
// Juggle topic counts. |
5 | 854 |
if ( isset( $args['topic_count_text'] ) ) { |
855 |
// First look for nooped plural support via topic_count_text. |
|
856 |
$translate_nooped_plural = $args['topic_count_text']; |
|
857 |
} elseif ( ! empty( $args['topic_count_text_callback'] ) ) { |
|
858 |
// Look for the alternative callback style. Ignore the previous default. |
|
16 | 859 |
if ( 'default_topic_count_text' === $args['topic_count_text_callback'] ) { |
860 |
/* translators: %s: Number of items (tags). */ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
861 |
$translate_nooped_plural = _n_noop( '%s item', '%s items' ); |
5 | 862 |
} else { |
863 |
$translate_nooped_plural = false; |
|
864 |
} |
|
865 |
} elseif ( isset( $args['single_text'] ) && isset( $args['multiple_text'] ) ) { |
|
866 |
// If no callback exists, look for the old-style single_text and multiple_text arguments. |
|
9 | 867 |
// phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralSingle,WordPress.WP.I18n.NonSingularStringLiteralPlural |
5 | 868 |
$translate_nooped_plural = _n_noop( $args['single_text'], $args['multiple_text'] ); |
869 |
} else { |
|
870 |
// This is the default for when no callback, plural, or argument is passed in. |
|
16 | 871 |
/* translators: %s: Number of items (tags). */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
872 |
$translate_nooped_plural = _n_noop( '%s item', '%s items' ); |
0 | 873 |
} |
874 |
||
5 | 875 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
876 |
* Filters how the items in a tag cloud are sorted. |
5 | 877 |
* |
878 |
* @since 2.8.0 |
|
879 |
* |
|
9 | 880 |
* @param WP_Term[] $tags Ordered array of terms. |
881 |
* @param array $args An array of tag cloud arguments. |
|
5 | 882 |
*/ |
0 | 883 |
$tags_sorted = apply_filters( 'tag_cloud_sort', $tags, $args ); |
5 | 884 |
if ( empty( $tags_sorted ) ) { |
885 |
return $return; |
|
886 |
} |
|
887 |
||
888 |
if ( $tags_sorted !== $tags ) { |
|
0 | 889 |
$tags = $tags_sorted; |
5 | 890 |
unset( $tags_sorted ); |
0 | 891 |
} else { |
5 | 892 |
if ( 'RAND' === $args['order'] ) { |
893 |
shuffle( $tags ); |
|
0 | 894 |
} else { |
895 |
// SQL cannot save you; this is a second (potentially different) sort on a subset of data. |
|
5 | 896 |
if ( 'name' === $args['orderby'] ) { |
0 | 897 |
uasort( $tags, '_wp_object_name_sort_cb' ); |
5 | 898 |
} else { |
0 | 899 |
uasort( $tags, '_wp_object_count_sort_cb' ); |
5 | 900 |
} |
0 | 901 |
|
5 | 902 |
if ( 'DESC' === $args['order'] ) { |
0 | 903 |
$tags = array_reverse( $tags, true ); |
5 | 904 |
} |
0 | 905 |
} |
906 |
} |
|
907 |
||
9 | 908 |
if ( $args['number'] > 0 ) { |
5 | 909 |
$tags = array_slice( $tags, 0, $args['number'] ); |
9 | 910 |
} |
0 | 911 |
|
9 | 912 |
$counts = array(); |
16 | 913 |
$real_counts = array(); // For the alt tag. |
0 | 914 |
foreach ( (array) $tags as $key => $tag ) { |
915 |
$real_counts[ $key ] = $tag->count; |
|
9 | 916 |
$counts[ $key ] = call_user_func( $args['topic_count_scale_callback'], $tag->count ); |
0 | 917 |
} |
918 |
||
919 |
$min_count = min( $counts ); |
|
9 | 920 |
$spread = max( $counts ) - $min_count; |
921 |
if ( $spread <= 0 ) { |
|
0 | 922 |
$spread = 1; |
9 | 923 |
} |
5 | 924 |
$font_spread = $args['largest'] - $args['smallest']; |
9 | 925 |
if ( $font_spread < 0 ) { |
0 | 926 |
$font_spread = 1; |
9 | 927 |
} |
0 | 928 |
$font_step = $font_spread / $spread; |
929 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
930 |
$aria_label = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
931 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
932 |
* Determine whether to output an 'aria-label' attribute with the tag name and count. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
933 |
* When tags have a different font size, they visually convey an important information |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
934 |
* that should be available to assistive technologies too. On the other hand, sometimes |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
935 |
* themes set up the Tag Cloud to display all tags with the same font size (setting |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
936 |
* the 'smallest' and 'largest' arguments to the same value). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
937 |
* In order to always serve the same content to all users, the 'aria-label' gets printed out: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
938 |
* - when tags have a different size |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
939 |
* - when the tag count is displayed (for example when users check the checkbox in the |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
940 |
* Tag Cloud widget), regardless of the tags font size |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
941 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
942 |
if ( $args['show_count'] || 0 !== $font_spread ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
943 |
$aria_label = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
944 |
} |
0 | 945 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
946 |
// Assemble the data that will be used to generate the tag cloud markup. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
947 |
$tags_data = array(); |
0 | 948 |
foreach ( $tags as $key => $tag ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
949 |
$tag_id = isset( $tag->id ) ? $tag->id : $key; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
950 |
|
9 | 951 |
$count = $counts[ $key ]; |
0 | 952 |
$real_count = $real_counts[ $key ]; |
5 | 953 |
|
954 |
if ( $translate_nooped_plural ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
955 |
$formatted_count = sprintf( translate_nooped_plural( $translate_nooped_plural, $real_count ), number_format_i18n( $real_count ) ); |
5 | 956 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
957 |
$formatted_count = call_user_func( $args['topic_count_text_callback'], $real_count, $tag, $args ); |
5 | 958 |
} |
959 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
960 |
$tags_data[] = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
961 |
'id' => $tag_id, |
16 | 962 |
'url' => ( '#' !== $tag->link ) ? $tag->link : '#', |
963 |
'role' => ( '#' !== $tag->link ) ? '' : ' role="button"', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
964 |
'name' => $tag->name, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
965 |
'formatted_count' => $formatted_count, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
966 |
'slug' => $tag->slug, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
967 |
'real_count' => $real_count, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
968 |
'class' => 'tag-cloud-link tag-link-' . $tag_id, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
969 |
'font_size' => $args['smallest'] + ( $count - $min_count ) * $font_step, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
970 |
'aria_label' => $aria_label ? sprintf( ' aria-label="%1$s (%2$s)"', esc_attr( $tag->name ), esc_attr( $formatted_count ) ) : '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
971 |
'show_count' => $args['show_count'] ? '<span class="tag-link-count"> (' . $real_count . ')</span>' : '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
972 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
973 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
974 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
975 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
976 |
* Filters the data used to generate the tag cloud. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
977 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
978 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
979 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
980 |
* @param array $tags_data An array of term data for term used to generate the tag cloud. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
981 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
982 |
$tags_data = apply_filters( 'wp_generate_tag_cloud_data', $tags_data ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
983 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
984 |
$a = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
985 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
986 |
// Generate the output links array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
987 |
foreach ( $tags_data as $key => $tag_data ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
988 |
$class = $tag_data['class'] . ' tag-link-position-' . ( $key + 1 ); |
9 | 989 |
$a[] = sprintf( |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
990 |
'<a href="%1$s"%2$s class="%3$s" style="font-size: %4$s;"%5$s>%6$s%7$s</a>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
991 |
esc_url( $tag_data['url'] ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
992 |
$tag_data['role'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
993 |
esc_attr( $class ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
994 |
esc_attr( str_replace( ',', '.', $tag_data['font_size'] ) . $args['unit'] ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
995 |
$tag_data['aria_label'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
996 |
esc_html( $tag_data['name'] ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
997 |
$tag_data['show_count'] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
998 |
); |
0 | 999 |
} |
1000 |
||
5 | 1001 |
switch ( $args['format'] ) { |
9 | 1002 |
case 'array': |
5 | 1003 |
$return =& $a; |
1004 |
break; |
|
9 | 1005 |
case 'list': |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1006 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1007 |
* Force role="list", as some browsers (sic: Safari 10) don't expose to assistive |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1008 |
* technologies the default role when the list is styled with `list-style: none`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1009 |
* Note: this is redundant but doesn't harm. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1010 |
*/ |
9 | 1011 |
$return = "<ul class='wp-tag-cloud' role='list'>\n\t<li>"; |
5 | 1012 |
$return .= join( "</li>\n\t<li>", $a ); |
1013 |
$return .= "</li>\n</ul>\n"; |
|
1014 |
break; |
|
9 | 1015 |
default: |
5 | 1016 |
$return = join( $args['separator'], $a ); |
1017 |
break; |
|
1018 |
} |
|
0 | 1019 |
|
5 | 1020 |
if ( $args['filter'] ) { |
1021 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1022 |
* Filters the generated output of a tag cloud. |
5 | 1023 |
* |
1024 |
* The filter is only evaluated if a true value is passed |
|
1025 |
* to the $filter argument in wp_generate_tag_cloud(). |
|
1026 |
* |
|
1027 |
* @since 2.3.0 |
|
1028 |
* |
|
1029 |
* @see wp_generate_tag_cloud() |
|
1030 |
* |
|
1031 |
* @param array|string $return String containing the generated HTML tag cloud output |
|
1032 |
* or an array of tag links if the 'format' argument |
|
1033 |
* equals 'array'. |
|
9 | 1034 |
* @param WP_Term[] $tags An array of terms used in the tag cloud. |
5 | 1035 |
* @param array $args An array of wp_generate_tag_cloud() arguments. |
1036 |
*/ |
|
0 | 1037 |
return apply_filters( 'wp_generate_tag_cloud', $return, $tags, $args ); |
9 | 1038 |
} else { |
1039 |
return $return; |
|
5 | 1040 |
} |
0 | 1041 |
} |
1042 |
||
1043 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1044 |
* Serves as a callback for comparing objects based on name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1045 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1046 |
* Used with `uasort()`. |
0 | 1047 |
* |
1048 |
* @since 3.1.0 |
|
1049 |
* @access private |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1050 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1051 |
* @param object $a The first object to compare. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1052 |
* @param object $b The second object to compare. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1053 |
* @return int Negative number if `$a->name` is less than `$b->name`, zero if they are equal, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1054 |
* or greater than zero if `$a->name` is greater than `$b->name`. |
0 | 1055 |
*/ |
1056 |
function _wp_object_name_sort_cb( $a, $b ) { |
|
1057 |
return strnatcasecmp( $a->name, $b->name ); |
|
1058 |
} |
|
1059 |
||
1060 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1061 |
* Serves as a callback for comparing objects based on count. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1062 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1063 |
* Used with `uasort()`. |
0 | 1064 |
* |
1065 |
* @since 3.1.0 |
|
1066 |
* @access private |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1067 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1068 |
* @param object $a The first object to compare. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1069 |
* @param object $b The second object to compare. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1070 |
* @return bool Whether the count value for `$a` is greater than the count value for `$b`. |
0 | 1071 |
*/ |
1072 |
function _wp_object_count_sort_cb( $a, $b ) { |
|
1073 |
return ( $a->count > $b->count ); |
|
1074 |
} |
|
1075 |
||
1076 |
// |
|
16 | 1077 |
// Helper functions. |
0 | 1078 |
// |
1079 |
||
1080 |
/** |
|
16 | 1081 |
* Retrieves HTML list content for category list. |
1082 |
* |
|
1083 |
* @since 2.1.0 |
|
1084 |
* @since 5.3.0 Formalized the existing `...$args` parameter by adding it |
|
1085 |
* to the function signature. |
|
0 | 1086 |
* |
1087 |
* @uses Walker_Category to create HTML list content. |
|
16 | 1088 |
* @see Walker::walk() for parameters and return description. |
1089 |
* |
|
1090 |
* @param mixed ...$args Elements array, maximum hierarchical depth and optional additional arguments. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1091 |
* @return string |
0 | 1092 |
*/ |
16 | 1093 |
function walk_category_tree( ...$args ) { |
1094 |
// The user's options are the third parameter. |
|
5 | 1095 |
if ( empty( $args[2]['walker'] ) || ! ( $args[2]['walker'] instanceof Walker ) ) { |
0 | 1096 |
$walker = new Walker_Category; |
5 | 1097 |
} else { |
16 | 1098 |
/** |
1099 |
* @var Walker $walker |
|
1100 |
*/ |
|
0 | 1101 |
$walker = $args[2]['walker']; |
5 | 1102 |
} |
16 | 1103 |
return $walker->walk( ...$args ); |
0 | 1104 |
} |
1105 |
||
1106 |
/** |
|
16 | 1107 |
* Retrieves HTML dropdown (select) content for category list. |
1108 |
* |
|
1109 |
* @since 2.1.0 |
|
1110 |
* @since 5.3.0 Formalized the existing `...$args` parameter by adding it |
|
1111 |
* to the function signature. |
|
0 | 1112 |
* |
1113 |
* @uses Walker_CategoryDropdown to create HTML dropdown content. |
|
16 | 1114 |
* @see Walker::walk() for parameters and return description. |
1115 |
* |
|
1116 |
* @param mixed ...$args Elements array, maximum hierarchical depth and optional additional arguments. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1117 |
* @return string |
0 | 1118 |
*/ |
16 | 1119 |
function walk_category_dropdown_tree( ...$args ) { |
1120 |
// The user's options are the third parameter. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1121 |
if ( empty( $args[2]['walker'] ) || ! ( $args[2]['walker'] instanceof Walker ) ) { |
0 | 1122 |
$walker = new Walker_CategoryDropdown; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1123 |
} else { |
16 | 1124 |
/** |
1125 |
* @var Walker $walker |
|
1126 |
*/ |
|
0 | 1127 |
$walker = $args[2]['walker']; |
1128 |
} |
|
16 | 1129 |
return $walker->walk( ...$args ); |
0 | 1130 |
} |
1131 |
||
1132 |
// |
|
16 | 1133 |
// Tags. |
0 | 1134 |
// |
1135 |
||
1136 |
/** |
|
16 | 1137 |
* Retrieves the link to the tag. |
0 | 1138 |
* |
1139 |
* @since 2.3.0 |
|
16 | 1140 |
* |
0 | 1141 |
* @see get_term_link() |
1142 |
* |
|
1143 |
* @param int|object $tag Tag ID or object. |
|
1144 |
* @return string Link on success, empty string if tag does not exist. |
|
1145 |
*/ |
|
1146 |
function get_tag_link( $tag ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1147 |
return get_category_link( $tag ); |
0 | 1148 |
} |
1149 |
||
1150 |
/** |
|
16 | 1151 |
* Retrieves the tags for a post. |
0 | 1152 |
* |
1153 |
* @since 2.3.0 |
|
1154 |
* |
|
16 | 1155 |
* @param int $post_id Post ID. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1156 |
* @return array|false|WP_Error Array of tag objects on success, false on failure. |
0 | 1157 |
*/ |
16 | 1158 |
function get_the_tags( $post_id = 0 ) { |
1159 |
$terms = get_the_terms( $post_id, 'post_tag' ); |
|
5 | 1160 |
|
1161 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1162 |
* Filters the array of tags for the given post. |
5 | 1163 |
* |
1164 |
* @since 2.3.0 |
|
1165 |
* |
|
1166 |
* @see get_the_terms() |
|
1167 |
* |
|
9 | 1168 |
* @param WP_Term[] $terms An array of tags for the given post. |
5 | 1169 |
*/ |
16 | 1170 |
return apply_filters( 'get_the_tags', $terms ); |
0 | 1171 |
} |
1172 |
||
1173 |
/** |
|
16 | 1174 |
* Retrieves the tags for a post formatted as a string. |
0 | 1175 |
* |
1176 |
* @since 2.3.0 |
|
1177 |
* |
|
16 | 1178 |
* @param string $before Optional. String to use before the tags. Default empty. |
1179 |
* @param string $sep Optional. String to use between the tags. Default empty. |
|
1180 |
* @param string $after Optional. String to use after the tags. Default empty. |
|
1181 |
* @param int $post_id Optional. Post ID. Defaults to the current post ID. |
|
1182 |
* @return string|false|WP_Error A list of tags on success, false if there are no terms, |
|
1183 |
* WP_Error on failure. |
|
0 | 1184 |
*/ |
16 | 1185 |
function get_the_tag_list( $before = '', $sep = '', $after = '', $post_id = 0 ) { |
1186 |
$tag_list = get_the_term_list( $post_id, 'post_tag', $before, $sep, $after ); |
|
5 | 1187 |
|
1188 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1189 |
* Filters the tags list for a given post. |
5 | 1190 |
* |
1191 |
* @since 2.3.0 |
|
1192 |
* |
|
1193 |
* @param string $tag_list List of tags. |
|
16 | 1194 |
* @param string $before String to use before the tags. |
5 | 1195 |
* @param string $sep String to use between the tags. |
16 | 1196 |
* @param string $after String to use after the tags. |
1197 |
* @param int $post_id Post ID. |
|
5 | 1198 |
*/ |
16 | 1199 |
return apply_filters( 'the_tags', $tag_list, $before, $sep, $after, $post_id ); |
0 | 1200 |
} |
1201 |
||
1202 |
/** |
|
16 | 1203 |
* Displays the tags for a post. |
0 | 1204 |
* |
1205 |
* @since 2.3.0 |
|
1206 |
* |
|
16 | 1207 |
* @param string $before Optional. String to use before the tags. Defaults to 'Tags:'. |
1208 |
* @param string $sep Optional. String to use between the tags. Default ', '. |
|
1209 |
* @param string $after Optional. String to use after the tags. Default empty. |
|
0 | 1210 |
*/ |
1211 |
function the_tags( $before = null, $sep = ', ', $after = '' ) { |
|
9 | 1212 |
if ( null === $before ) { |
1213 |
$before = __( 'Tags: ' ); |
|
1214 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1215 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1216 |
$the_tags = get_the_tag_list( $before, $sep, $after ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1217 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1218 |
if ( ! is_wp_error( $the_tags ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1219 |
echo $the_tags; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1220 |
} |
0 | 1221 |
} |
1222 |
||
1223 |
/** |
|
16 | 1224 |
* Retrieves tag description. |
0 | 1225 |
* |
5 | 1226 |
* @since 2.8.0 |
0 | 1227 |
* |
16 | 1228 |
* @param int $tag Optional. Tag ID. Defaults to the current tag ID. |
1229 |
* @return string Tag description, if available. |
|
0 | 1230 |
*/ |
1231 |
function tag_description( $tag = 0 ) { |
|
1232 |
return term_description( $tag ); |
|
1233 |
} |
|
1234 |
||
1235 |
/** |
|
16 | 1236 |
* Retrieves term description. |
0 | 1237 |
* |
5 | 1238 |
* @since 2.8.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1239 |
* @since 4.9.2 The `$taxonomy` parameter was deprecated. |
0 | 1240 |
* |
16 | 1241 |
* @param int $term Optional. Term ID. Defaults to the current term ID. |
1242 |
* @param null $deprecated Deprecated. Not used. |
|
1243 |
* @return string Term description, if available. |
|
0 | 1244 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1245 |
function term_description( $term = 0, $deprecated = null ) { |
0 | 1246 |
if ( ! $term && ( is_tax() || is_tag() || is_category() ) ) { |
1247 |
$term = get_queried_object(); |
|
1248 |
if ( $term ) { |
|
1249 |
$term = $term->term_id; |
|
1250 |
} |
|
1251 |
} |
|
16 | 1252 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1253 |
$description = get_term_field( 'description', $term ); |
16 | 1254 |
|
0 | 1255 |
return is_wp_error( $description ) ? '' : $description; |
1256 |
} |
|
1257 |
||
1258 |
/** |
|
16 | 1259 |
* Retrieves the terms of the taxonomy that are attached to the post. |
0 | 1260 |
* |
1261 |
* @since 2.5.0 |
|
1262 |
* |
|
9 | 1263 |
* @param int|WP_Post $post Post ID or object. |
1264 |
* @param string $taxonomy Taxonomy name. |
|
1265 |
* @return WP_Term[]|false|WP_Error Array of WP_Term objects on success, false if there are no terms |
|
1266 |
* or the post does not exist, WP_Error on failure. |
|
0 | 1267 |
*/ |
1268 |
function get_the_terms( $post, $taxonomy ) { |
|
16 | 1269 |
$post = get_post( $post ); |
1270 |
if ( ! $post ) { |
|
0 | 1271 |
return false; |
9 | 1272 |
} |
0 | 1273 |
|
1274 |
$terms = get_object_term_cache( $post->ID, $taxonomy ); |
|
1275 |
if ( false === $terms ) { |
|
1276 |
$terms = wp_get_object_terms( $post->ID, $taxonomy ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1277 |
if ( ! is_wp_error( $terms ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1278 |
$term_ids = wp_list_pluck( $terms, 'term_id' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1279 |
wp_cache_add( $post->ID, $term_ids, $taxonomy . '_relationships' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1280 |
} |
0 | 1281 |
} |
1282 |
||
5 | 1283 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1284 |
* Filters the list of terms attached to the given post. |
5 | 1285 |
* |
1286 |
* @since 3.1.0 |
|
1287 |
* |
|
9 | 1288 |
* @param WP_Term[]|WP_Error $terms Array of attached terms, or WP_Error on failure. |
1289 |
* @param int $post_id Post ID. |
|
1290 |
* @param string $taxonomy Name of the taxonomy. |
|
5 | 1291 |
*/ |
0 | 1292 |
$terms = apply_filters( 'get_the_terms', $terms, $post->ID, $taxonomy ); |
1293 |
||
9 | 1294 |
if ( empty( $terms ) ) { |
0 | 1295 |
return false; |
9 | 1296 |
} |
0 | 1297 |
|
1298 |
return $terms; |
|
1299 |
} |
|
1300 |
||
1301 |
/** |
|
16 | 1302 |
* Retrieves a post's terms as a list with specified format. |
1303 |
* |
|
1304 |
* Terms are linked to their respective term listing pages. |
|
0 | 1305 |
* |
1306 |
* @since 2.5.0 |
|
1307 |
* |
|
16 | 1308 |
* @param int $post_id Post ID. |
0 | 1309 |
* @param string $taxonomy Taxonomy name. |
16 | 1310 |
* @param string $before Optional. String to use before the terms. Default empty. |
1311 |
* @param string $sep Optional. String to use between the terms. Default empty. |
|
1312 |
* @param string $after Optional. String to use after the terms. Default empty. |
|
1313 |
* @return string|false|WP_Error A list of terms on success, false if there are no terms, |
|
1314 |
* WP_Error on failure. |
|
0 | 1315 |
*/ |
16 | 1316 |
function get_the_term_list( $post_id, $taxonomy, $before = '', $sep = '', $after = '' ) { |
1317 |
$terms = get_the_terms( $post_id, $taxonomy ); |
|
0 | 1318 |
|
9 | 1319 |
if ( is_wp_error( $terms ) ) { |
0 | 1320 |
return $terms; |
9 | 1321 |
} |
0 | 1322 |
|
9 | 1323 |
if ( empty( $terms ) ) { |
0 | 1324 |
return false; |
9 | 1325 |
} |
0 | 1326 |
|
5 | 1327 |
$links = array(); |
1328 |
||
0 | 1329 |
foreach ( $terms as $term ) { |
1330 |
$link = get_term_link( $term, $taxonomy ); |
|
5 | 1331 |
if ( is_wp_error( $link ) ) { |
0 | 1332 |
return $link; |
5 | 1333 |
} |
1334 |
$links[] = '<a href="' . esc_url( $link ) . '" rel="tag">' . $term->name . '</a>'; |
|
0 | 1335 |
} |
1336 |
||
5 | 1337 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1338 |
* Filters the term links for a given taxonomy. |
5 | 1339 |
* |
1340 |
* The dynamic portion of the filter name, `$taxonomy`, refers |
|
1341 |
* to the taxonomy slug. |
|
1342 |
* |
|
1343 |
* @since 2.5.0 |
|
1344 |
* |
|
9 | 1345 |
* @param string[] $links An array of term links. |
5 | 1346 |
*/ |
16 | 1347 |
$term_links = apply_filters( "term_links-{$taxonomy}", $links ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
0 | 1348 |
|
1349 |
return $before . join( $sep, $term_links ) . $after; |
|
1350 |
} |
|
1351 |
||
1352 |
/** |
|
16 | 1353 |
* Retrieves term parents with separator. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1354 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1355 |
* @since 4.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1356 |
* |
16 | 1357 |
* @param int $term_id Term ID. |
1358 |
* @param string $taxonomy Taxonomy name. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1359 |
* @param string|array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1360 |
* Array of optional arguments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1361 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1362 |
* @type string $format Use term names or slugs for display. Accepts 'name' or 'slug'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1363 |
* Default 'name'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1364 |
* @type string $separator Separator for between the terms. Default '/'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1365 |
* @type bool $link Whether to format as a link. Default true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1366 |
* @type bool $inclusive Include the term to get the parents for. Default true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1367 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1368 |
* @return string|WP_Error A list of term parents on success, WP_Error or empty string on failure. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1369 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1370 |
function get_term_parents_list( $term_id, $taxonomy, $args = array() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1371 |
$list = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1372 |
$term = get_term( $term_id, $taxonomy ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1373 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1374 |
if ( is_wp_error( $term ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1375 |
return $term; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1376 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1377 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1378 |
if ( ! $term ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1379 |
return $list; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1380 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1381 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1382 |
$term_id = $term->term_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1383 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1384 |
$defaults = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1385 |
'format' => 'name', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1386 |
'separator' => '/', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1387 |
'link' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1388 |
'inclusive' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1389 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1390 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1391 |
$args = wp_parse_args( $args, $defaults ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1392 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1393 |
foreach ( array( 'link', 'inclusive' ) as $bool ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1394 |
$args[ $bool ] = wp_validate_boolean( $args[ $bool ] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1395 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1396 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1397 |
$parents = get_ancestors( $term_id, $taxonomy, 'taxonomy' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1398 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1399 |
if ( $args['inclusive'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1400 |
array_unshift( $parents, $term_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1401 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1402 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1403 |
foreach ( array_reverse( $parents ) as $term_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1404 |
$parent = get_term( $term_id, $taxonomy ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1405 |
$name = ( 'slug' === $args['format'] ) ? $parent->slug : $parent->name; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1406 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1407 |
if ( $args['link'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1408 |
$list .= '<a href="' . esc_url( get_term_link( $parent->term_id, $taxonomy ) ) . '">' . $name . '</a>' . $args['separator']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1409 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1410 |
$list .= $name . $args['separator']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1411 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1412 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1413 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1414 |
return $list; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1415 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1416 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1417 |
/** |
16 | 1418 |
* Displays the terms for a post in a list. |
0 | 1419 |
* |
1420 |
* @since 2.5.0 |
|
1421 |
* |
|
16 | 1422 |
* @param int $post_id Post ID. |
0 | 1423 |
* @param string $taxonomy Taxonomy name. |
16 | 1424 |
* @param string $before Optional. String to use before the terms. Default empty. |
1425 |
* @param string $sep Optional. String to use between the terms. Default ', '. |
|
1426 |
* @param string $after Optional. String to use after the terms. Default empty. |
|
1427 |
* @return void|false Void on success, false on failure. |
|
0 | 1428 |
*/ |
16 | 1429 |
function the_terms( $post_id, $taxonomy, $before = '', $sep = ', ', $after = '' ) { |
1430 |
$term_list = get_the_term_list( $post_id, $taxonomy, $before, $sep, $after ); |
|
0 | 1431 |
|
9 | 1432 |
if ( is_wp_error( $term_list ) ) { |
0 | 1433 |
return false; |
9 | 1434 |
} |
0 | 1435 |
|
5 | 1436 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1437 |
* Filters the list of terms to display. |
5 | 1438 |
* |
1439 |
* @since 2.9.0 |
|
1440 |
* |
|
9 | 1441 |
* @param string $term_list List of terms to display. |
5 | 1442 |
* @param string $taxonomy The taxonomy name. |
1443 |
* @param string $before String to use before the terms. |
|
1444 |
* @param string $sep String to use between the terms. |
|
1445 |
* @param string $after String to use after the terms. |
|
1446 |
*/ |
|
1447 |
echo apply_filters( 'the_terms', $term_list, $taxonomy, $before, $sep, $after ); |
|
0 | 1448 |
} |
1449 |
||
1450 |
/** |
|
16 | 1451 |
* Checks if the current post has any of given category. |
1452 |
* |
|
1453 |
* The given categories are checked against the post's categories' term_ids, names and slugs. |
|
1454 |
* Categories given as integers will only be checked against the post's categories' term_ids. |
|
1455 |
* |
|
1456 |
* If no categories are given, determines if post has any categories. |
|
0 | 1457 |
* |
1458 |
* @since 3.1.0 |
|
1459 |
* |
|
16 | 1460 |
* @param string|int|array $category Optional. The category name/term_id/slug, |
1461 |
* or an array of them to check for. Default empty. |
|
1462 |
* @param int|object $post Optional. Post to check instead of the current post. |
|
1463 |
* @return bool True if the current post has any of the given categories |
|
1464 |
* (or any category, if no category specified). False otherwise. |
|
0 | 1465 |
*/ |
1466 |
function has_category( $category = '', $post = null ) { |
|
1467 |
return has_term( $category, 'category', $post ); |
|
1468 |
} |
|
1469 |
||
1470 |
/** |
|
9 | 1471 |
* Checks if the current post has any of given tags. |
0 | 1472 |
* |
1473 |
* The given tags are checked against the post's tags' term_ids, names and slugs. |
|
1474 |
* Tags given as integers will only be checked against the post's tags' term_ids. |
|
16 | 1475 |
* |
0 | 1476 |
* If no tags are given, determines if post has any tags. |
1477 |
* |
|
9 | 1478 |
* For more information on this and similar theme functions, check out |
1479 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
1480 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
1481 |
* |
|
0 | 1482 |
* @since 2.6.0 |
16 | 1483 |
* @since 2.7.0 Tags given as integers are only checked against |
1484 |
* the post's tags' term_ids, not names or slugs. |
|
1485 |
* @since 2.7.0 Can be used outside of the WordPress Loop if `$post` is provided. |
|
0 | 1486 |
* |
16 | 1487 |
* @param string|int|array $tag Optional. The tag name/term_id/slug, |
1488 |
* or an array of them to check for. Default empty. |
|
1489 |
* @param int|object $post Optional. Post to check instead of the current post. |
|
1490 |
* @return bool True if the current post has any of the given tags |
|
1491 |
* (or any tag, if no tag specified). False otherwise. |
|
0 | 1492 |
*/ |
1493 |
function has_tag( $tag = '', $post = null ) { |
|
1494 |
return has_term( $tag, 'post_tag', $post ); |
|
1495 |
} |
|
1496 |
||
1497 |
/** |
|
16 | 1498 |
* Checks if the current post has any of given terms. |
0 | 1499 |
* |
1500 |
* The given terms are checked against the post's terms' term_ids, names and slugs. |
|
1501 |
* Terms given as integers will only be checked against the post's terms' term_ids. |
|
16 | 1502 |
* |
0 | 1503 |
* If no terms are given, determines if post has any terms. |
1504 |
* |
|
1505 |
* @since 3.1.0 |
|
1506 |
* |
|
16 | 1507 |
* @param string|int|array $term Optional. The term name/term_id/slug, |
1508 |
* or an array of them to check for. Default empty. |
|
1509 |
* @param string $taxonomy Optional. Taxonomy name. Default empty. |
|
1510 |
* @param int|WP_Post $post Optional. Post to check instead of the current post. |
|
1511 |
* @return bool True if the current post has any of the given terms |
|
1512 |
* (or any term, if no term specified). False otherwise. |
|
0 | 1513 |
*/ |
1514 |
function has_term( $term = '', $taxonomy = '', $post = null ) { |
|
9 | 1515 |
$post = get_post( $post ); |
0 | 1516 |
|
9 | 1517 |
if ( ! $post ) { |
0 | 1518 |
return false; |
9 | 1519 |
} |
0 | 1520 |
|
1521 |
$r = is_object_in_term( $post->ID, $taxonomy, $term ); |
|
9 | 1522 |
if ( is_wp_error( $r ) ) { |
0 | 1523 |
return false; |
9 | 1524 |
} |
0 | 1525 |
|
1526 |
return $r; |
|
1527 |
} |