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