author | ymh <ymh.work@gmail.com> |
Fri, 05 Sep 2025 18:40:08 +0200 | |
changeset 21 | 48c4eec2b7e6 |
parent 19 | 3d72ae0968f4 |
child 22 | 8c2e4d02f4ef |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* WordPress Post Template Functions. |
|
4 |
* |
|
5 |
* Gets content for the current post in the loop. |
|
6 |
* |
|
7 |
* @package WordPress |
|
8 |
* @subpackage Template |
|
9 |
*/ |
|
10 |
||
11 |
/** |
|
19 | 12 |
* Displays the ID of the current item in the WordPress Loop. |
0 | 13 |
* |
14 |
* @since 0.71 |
|
15 |
*/ |
|
16 | 16 |
function the_ID() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid |
0 | 17 |
echo get_the_ID(); |
18 |
} |
|
19 |
||
20 |
/** |
|
19 | 21 |
* Retrieves the ID of the current item in the WordPress Loop. |
0 | 22 |
* |
23 |
* @since 2.1.0 |
|
24 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
25 |
* @return int|false The ID of the current item in the WordPress Loop. False if $post is not set. |
0 | 26 |
*/ |
16 | 27 |
function get_the_ID() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid |
5 | 28 |
$post = get_post(); |
29 |
return ! empty( $post ) ? $post->ID : false; |
|
0 | 30 |
} |
31 |
||
32 |
/** |
|
19 | 33 |
* Displays or retrieves the current post title with optional markup. |
0 | 34 |
* |
35 |
* @since 0.71 |
|
36 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
37 |
* @param string $before Optional. Markup to prepend to the title. Default empty. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
38 |
* @param string $after Optional. Markup to append to the title. Default empty. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
39 |
* @param bool $display Optional. Whether to echo or return the title. Default true for echo. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
40 |
* @return void|string Void if `$display` argument is true or the title is empty, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
41 |
* current post title if `$display` is false. |
0 | 42 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
43 |
function the_title( $before = '', $after = '', $display = true ) { |
0 | 44 |
$title = get_the_title(); |
45 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
46 |
if ( strlen( $title ) === 0 ) { |
0 | 47 |
return; |
9 | 48 |
} |
0 | 49 |
|
50 |
$title = $before . $title . $after; |
|
51 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
52 |
if ( $display ) { |
0 | 53 |
echo $title; |
9 | 54 |
} else { |
0 | 55 |
return $title; |
9 | 56 |
} |
0 | 57 |
} |
58 |
||
59 |
/** |
|
19 | 60 |
* Sanitizes the current title when retrieving or displaying. |
0 | 61 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
62 |
* Works like the_title(), except the parameters can be in a string or |
0 | 63 |
* an array. See the function for what can be override in the $args parameter. |
64 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
65 |
* The title before it is displayed will have the tags stripped and esc_attr() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
66 |
* before it is passed to the user or displayed. The default as with the_title(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
67 |
* is to display the title. |
0 | 68 |
* |
69 |
* @since 2.3.0 |
|
70 |
* |
|
5 | 71 |
* @param string|array $args { |
72 |
* Title attribute arguments. Optional. |
|
73 |
* |
|
74 |
* @type string $before Markup to prepend to the title. Default empty. |
|
75 |
* @type string $after Markup to append to the title. Default empty. |
|
76 |
* @type bool $echo Whether to echo or return the title. Default true for echo. |
|
77 |
* @type WP_Post $post Current post object to retrieve the title for. |
|
78 |
* } |
|
16 | 79 |
* @return void|string Void if 'echo' argument is true, the title attribute if 'echo' is false. |
0 | 80 |
*/ |
81 |
function the_title_attribute( $args = '' ) { |
|
16 | 82 |
$defaults = array( |
9 | 83 |
'before' => '', |
84 |
'after' => '', |
|
85 |
'echo' => true, |
|
86 |
'post' => get_post(), |
|
87 |
); |
|
16 | 88 |
$parsed_args = wp_parse_args( $args, $defaults ); |
0 | 89 |
|
16 | 90 |
$title = get_the_title( $parsed_args['post'] ); |
0 | 91 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
92 |
if ( strlen( $title ) === 0 ) { |
0 | 93 |
return; |
5 | 94 |
} |
0 | 95 |
|
16 | 96 |
$title = $parsed_args['before'] . $title . $parsed_args['after']; |
5 | 97 |
$title = esc_attr( strip_tags( $title ) ); |
0 | 98 |
|
16 | 99 |
if ( $parsed_args['echo'] ) { |
0 | 100 |
echo $title; |
5 | 101 |
} else { |
0 | 102 |
return $title; |
5 | 103 |
} |
0 | 104 |
} |
105 |
||
106 |
/** |
|
19 | 107 |
* Retrieves the post title. |
0 | 108 |
* |
109 |
* If the post is protected and the visitor is not an admin, then "Protected" |
|
19 | 110 |
* will be inserted before the post title. If the post is private, then |
111 |
* "Private" will be inserted before the post title. |
|
0 | 112 |
* |
113 |
* @since 0.71 |
|
114 |
* |
|
5 | 115 |
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post. |
0 | 116 |
* @return string |
117 |
*/ |
|
118 |
function get_the_title( $post = 0 ) { |
|
119 |
$post = get_post( $post ); |
|
120 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
121 |
$post_title = isset( $post->post_title ) ? $post->post_title : ''; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
122 |
$post_id = isset( $post->ID ) ? $post->ID : 0; |
0 | 123 |
|
124 |
if ( ! is_admin() ) { |
|
125 |
if ( ! empty( $post->post_password ) ) { |
|
5 | 126 |
|
16 | 127 |
/* translators: %s: Protected post title. */ |
128 |
$prepend = __( 'Protected: %s' ); |
|
129 |
||
5 | 130 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
131 |
* Filters the text prepended to the post title for protected posts. |
5 | 132 |
* |
133 |
* The filter is only applied on the front end. |
|
134 |
* |
|
135 |
* @since 2.8.0 |
|
136 |
* |
|
137 |
* @param string $prepend Text displayed before the post title. |
|
138 |
* Default 'Protected: %s'. |
|
139 |
* @param WP_Post $post Current post object. |
|
140 |
*/ |
|
16 | 141 |
$protected_title_format = apply_filters( 'protected_title_format', $prepend, $post ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
142 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
143 |
$post_title = sprintf( $protected_title_format, $post_title ); |
16 | 144 |
} elseif ( isset( $post->post_status ) && 'private' === $post->post_status ) { |
145 |
||
146 |
/* translators: %s: Private post title. */ |
|
147 |
$prepend = __( 'Private: %s' ); |
|
5 | 148 |
|
149 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
150 |
* Filters the text prepended to the post title of private posts. |
5 | 151 |
* |
152 |
* The filter is only applied on the front end. |
|
153 |
* |
|
154 |
* @since 2.8.0 |
|
155 |
* |
|
156 |
* @param string $prepend Text displayed before the post title. |
|
157 |
* Default 'Private: %s'. |
|
158 |
* @param WP_Post $post Current post object. |
|
159 |
*/ |
|
16 | 160 |
$private_title_format = apply_filters( 'private_title_format', $prepend, $post ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
161 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
162 |
$post_title = sprintf( $private_title_format, $post_title ); |
0 | 163 |
} |
164 |
} |
|
165 |
||
5 | 166 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
167 |
* Filters the post title. |
5 | 168 |
* |
169 |
* @since 0.71 |
|
170 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
171 |
* @param string $post_title The post title. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
172 |
* @param int $post_id The post ID. |
5 | 173 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
174 |
return apply_filters( 'the_title', $post_title, $post_id ); |
0 | 175 |
} |
176 |
||
177 |
/** |
|
19 | 178 |
* Displays the Post Global Unique Identifier (guid). |
0 | 179 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
180 |
* The guid will appear to be a link, but should not be used as a link to the |
0 | 181 |
* post. The reason you should not use it as a link, is because of moving the |
182 |
* blog across domains. |
|
183 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
184 |
* URL is escaped to make it XML-safe. |
0 | 185 |
* |
186 |
* @since 1.5.0 |
|
187 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
188 |
* @param int|WP_Post $post Optional. Post ID or post object. Default is global $post. |
0 | 189 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
190 |
function the_guid( $post = 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
191 |
$post = get_post( $post ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
192 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
193 |
$post_guid = isset( $post->guid ) ? get_the_guid( $post ) : ''; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
194 |
$post_id = isset( $post->ID ) ? $post->ID : 0; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
195 |
|
5 | 196 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
197 |
* Filters the escaped Global Unique Identifier (guid) of the post. |
5 | 198 |
* |
199 |
* @since 4.2.0 |
|
200 |
* |
|
201 |
* @see get_the_guid() |
|
202 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
203 |
* @param string $post_guid Escaped Global Unique Identifier (guid) of the post. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
204 |
* @param int $post_id The post ID. |
5 | 205 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
206 |
echo apply_filters( 'the_guid', $post_guid, $post_id ); |
0 | 207 |
} |
208 |
||
209 |
/** |
|
19 | 210 |
* Retrieves the Post Global Unique Identifier (guid). |
0 | 211 |
* |
212 |
* The guid will appear to be a link, but should not be used as an link to the |
|
213 |
* post. The reason you should not use it as a link, is because of moving the |
|
214 |
* blog across domains. |
|
215 |
* |
|
216 |
* @since 1.5.0 |
|
217 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
218 |
* @param int|WP_Post $post Optional. Post ID or post object. Default is global $post. |
0 | 219 |
* @return string |
220 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
221 |
function get_the_guid( $post = 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
222 |
$post = get_post( $post ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
223 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
224 |
$post_guid = isset( $post->guid ) ? $post->guid : ''; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
225 |
$post_id = isset( $post->ID ) ? $post->ID : 0; |
0 | 226 |
|
5 | 227 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
228 |
* Filters the Global Unique Identifier (guid) of the post. |
5 | 229 |
* |
230 |
* @since 1.5.0 |
|
231 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
232 |
* @param string $post_guid Global Unique Identifier (guid) of the post. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
233 |
* @param int $post_id The post ID. |
5 | 234 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
235 |
return apply_filters( 'get_the_guid', $post_guid, $post_id ); |
0 | 236 |
} |
237 |
||
238 |
/** |
|
19 | 239 |
* Displays the post content. |
0 | 240 |
* |
241 |
* @since 0.71 |
|
242 |
* |
|
243 |
* @param string $more_link_text Optional. Content for when there is more text. |
|
16 | 244 |
* @param bool $strip_teaser Optional. Strip teaser content before the more text. Default false. |
0 | 245 |
*/ |
9 | 246 |
function the_content( $more_link_text = null, $strip_teaser = false ) { |
0 | 247 |
$content = get_the_content( $more_link_text, $strip_teaser ); |
5 | 248 |
|
249 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
250 |
* Filters the post content. |
5 | 251 |
* |
252 |
* @since 0.71 |
|
253 |
* |
|
254 |
* @param string $content Content of the current post. |
|
255 |
*/ |
|
0 | 256 |
$content = apply_filters( 'the_content', $content ); |
257 |
$content = str_replace( ']]>', ']]>', $content ); |
|
258 |
echo $content; |
|
259 |
} |
|
260 |
||
261 |
/** |
|
19 | 262 |
* Retrieves the post content. |
0 | 263 |
* |
264 |
* @since 0.71 |
|
9 | 265 |
* @since 5.2.0 Added the `$post` parameter. |
0 | 266 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
267 |
* @global int $page Page number of a single post/page. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
268 |
* @global int $more Boolean indicator for whether single post/page is being viewed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
269 |
* @global bool $preview Whether post/page is in preview mode. |
9 | 270 |
* @global array $pages Array of all pages in post/page. Each array element contains |
271 |
* part of the content separated by the `<!--nextpage-->` tag. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
272 |
* @global int $multipage Boolean indicator for whether multiple pages are in play. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
273 |
* |
9 | 274 |
* @param string $more_link_text Optional. Content for when there is more text. |
16 | 275 |
* @param bool $strip_teaser Optional. Strip teaser content before the more text. Default false. |
276 |
* @param WP_Post|object|int $post Optional. WP_Post instance or Post ID/object. Default null. |
|
0 | 277 |
* @return string |
278 |
*/ |
|
9 | 279 |
function get_the_content( $more_link_text = null, $strip_teaser = false, $post = null ) { |
0 | 280 |
global $page, $more, $preview, $pages, $multipage; |
281 |
||
9 | 282 |
$_post = get_post( $post ); |
283 |
||
284 |
if ( ! ( $_post instanceof WP_Post ) ) { |
|
285 |
return ''; |
|
286 |
} |
|
287 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
288 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
289 |
* Use the globals if the $post parameter was not specified, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
290 |
* but only after they have been set up in setup_postdata(). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
291 |
*/ |
16 | 292 |
if ( null === $post && did_action( 'the_post' ) ) { |
9 | 293 |
$elements = compact( 'page', 'more', 'preview', 'pages', 'multipage' ); |
294 |
} else { |
|
295 |
$elements = generate_postdata( $_post ); |
|
296 |
} |
|
0 | 297 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
298 |
if ( null === $more_link_text ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
299 |
$more_link_text = sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
300 |
'<span aria-label="%1$s">%2$s</span>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
301 |
sprintf( |
16 | 302 |
/* translators: %s: Post title. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
303 |
__( 'Continue reading %s' ), |
9 | 304 |
the_title_attribute( |
305 |
array( |
|
306 |
'echo' => false, |
|
307 |
'post' => $_post, |
|
308 |
) |
|
309 |
) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
310 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
311 |
__( '(more…)' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
312 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
313 |
} |
0 | 314 |
|
9 | 315 |
$output = ''; |
0 | 316 |
$has_teaser = false; |
317 |
||
318 |
// If post password required and it doesn't match the cookie. |
|
9 | 319 |
if ( post_password_required( $_post ) ) { |
320 |
return get_the_password_form( $_post ); |
|
321 |
} |
|
0 | 322 |
|
16 | 323 |
// If the requested page doesn't exist. |
324 |
if ( $elements['page'] > count( $elements['pages'] ) ) { |
|
325 |
// Give them the highest numbered page that DOES exist. |
|
326 |
$elements['page'] = count( $elements['pages'] ); |
|
9 | 327 |
} |
0 | 328 |
|
9 | 329 |
$page_no = $elements['page']; |
330 |
$content = $elements['pages'][ $page_no - 1 ]; |
|
0 | 331 |
if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) { |
9 | 332 |
if ( has_block( 'more', $content ) ) { |
333 |
// Remove the core/more block delimiters. They will be left over after $content is split up. |
|
334 |
$content = preg_replace( '/<!-- \/?wp:more(.*?) -->/', '', $content ); |
|
335 |
} |
|
336 |
||
0 | 337 |
$content = explode( $matches[0], $content, 2 ); |
9 | 338 |
|
339 |
if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) ) { |
|
0 | 340 |
$more_link_text = strip_tags( wp_kses_no_null( trim( $matches[1] ) ) ); |
9 | 341 |
} |
0 | 342 |
|
343 |
$has_teaser = true; |
|
344 |
} else { |
|
345 |
$content = array( $content ); |
|
346 |
} |
|
347 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
348 |
if ( str_contains( $_post->post_content, '<!--noteaser-->' ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
349 |
&& ( ! $elements['multipage'] || 1 === $elements['page'] ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
350 |
) { |
0 | 351 |
$strip_teaser = true; |
9 | 352 |
} |
0 | 353 |
|
354 |
$teaser = $content[0]; |
|
355 |
||
9 | 356 |
if ( $elements['more'] && $strip_teaser && $has_teaser ) { |
0 | 357 |
$teaser = ''; |
9 | 358 |
} |
0 | 359 |
|
360 |
$output .= $teaser; |
|
361 |
||
362 |
if ( count( $content ) > 1 ) { |
|
9 | 363 |
if ( $elements['more'] ) { |
364 |
$output .= '<span id="more-' . $_post->ID . '"></span>' . $content[1]; |
|
0 | 365 |
} else { |
9 | 366 |
if ( ! empty( $more_link_text ) ) { |
5 | 367 |
|
368 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
369 |
* Filters the Read More link text. |
5 | 370 |
* |
371 |
* @since 2.8.0 |
|
372 |
* |
|
373 |
* @param string $more_link_element Read More link element. |
|
374 |
* @param string $more_link_text Read More text. |
|
375 |
*/ |
|
9 | 376 |
$output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink( $_post ) . "#more-{$_post->ID}\" class=\"more-link\">$more_link_text</a>", $more_link_text ); |
377 |
} |
|
0 | 378 |
$output = force_balance_tags( $output ); |
379 |
} |
|
380 |
} |
|
381 |
||
382 |
return $output; |
|
383 |
} |
|
384 |
||
385 |
/** |
|
19 | 386 |
* Displays the post excerpt. |
0 | 387 |
* |
388 |
* @since 0.71 |
|
389 |
*/ |
|
390 |
function the_excerpt() { |
|
5 | 391 |
|
392 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
393 |
* Filters the displayed post excerpt. |
5 | 394 |
* |
395 |
* @since 0.71 |
|
396 |
* |
|
397 |
* @see get_the_excerpt() |
|
398 |
* |
|
399 |
* @param string $post_excerpt The post excerpt. |
|
400 |
*/ |
|
401 |
echo apply_filters( 'the_excerpt', get_the_excerpt() ); |
|
0 | 402 |
} |
403 |
||
404 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
405 |
* Retrieves the post excerpt. |
0 | 406 |
* |
407 |
* @since 0.71 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
408 |
* @since 4.5.0 Introduced the `$post` parameter. |
0 | 409 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
410 |
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
411 |
* @return string Post excerpt. |
0 | 412 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
413 |
function get_the_excerpt( $post = null ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
414 |
if ( is_bool( $post ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
415 |
_deprecated_argument( __FUNCTION__, '2.3.0' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
416 |
} |
0 | 417 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
418 |
$post = get_post( $post ); |
5 | 419 |
if ( empty( $post ) ) { |
420 |
return ''; |
|
421 |
} |
|
0 | 422 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
423 |
if ( post_password_required( $post ) ) { |
0 | 424 |
return __( 'There is no excerpt because this is a protected post.' ); |
425 |
} |
|
426 |
||
5 | 427 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
428 |
* Filters the retrieved post excerpt. |
5 | 429 |
* |
430 |
* @since 1.2.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
431 |
* @since 4.5.0 Introduced the `$post` parameter. |
5 | 432 |
* |
16 | 433 |
* @param string $post_excerpt The post excerpt. |
434 |
* @param WP_Post $post Post object. |
|
5 | 435 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
436 |
return apply_filters( 'get_the_excerpt', $post->post_excerpt, $post ); |
0 | 437 |
} |
438 |
||
439 |
/** |
|
9 | 440 |
* Determines whether the post has a custom excerpt. |
441 |
* |
|
442 |
* For more information on this and similar theme functions, check out |
|
443 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
444 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
0 | 445 |
* |
446 |
* @since 2.3.0 |
|
447 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
448 |
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
449 |
* @return bool True if the post has a custom excerpt, false otherwise. |
0 | 450 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
451 |
function has_excerpt( $post = 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
452 |
$post = get_post( $post ); |
9 | 453 |
return ( ! empty( $post->post_excerpt ) ); |
0 | 454 |
} |
455 |
||
456 |
/** |
|
9 | 457 |
* Displays the classes for the post container element. |
0 | 458 |
* |
459 |
* @since 2.7.0 |
|
460 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
461 |
* @param string|string[] $css_class Optional. One or more classes to add to the class list. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
462 |
* Default empty. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
463 |
* @param int|WP_Post $post Optional. Post ID or post object. Defaults to the global `$post`. |
0 | 464 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
465 |
function post_class( $css_class = '', $post = null ) { |
16 | 466 |
// Separates classes with a single space, collates classes for post DIV. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
467 |
echo 'class="' . esc_attr( implode( ' ', get_post_class( $css_class, $post ) ) ) . '"'; |
0 | 468 |
} |
469 |
||
470 |
/** |
|
9 | 471 |
* Retrieves an array of the class names for the post container element. |
0 | 472 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
473 |
* The class names are many: |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
474 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
475 |
* - If the post has a post thumbnail, `has-post-thumbnail` is added as a class. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
476 |
* - If the post is sticky, then the `sticky` class name is added. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
477 |
* - The class `hentry` is always added to each post. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
478 |
* - For each taxonomy that the post belongs to, a class will be added of the format |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
479 |
* `{$taxonomy}-{$slug}`, e.g. `category-foo` or `my_custom_taxonomy-bar`. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
480 |
* The `post_tag` taxonomy is a special case; the class has the `tag-` prefix |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
481 |
* instead of `post_tag-`. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
482 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
483 |
* All class names are passed through the filter, {@see 'post_class'}, followed by |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
484 |
* `$css_class` parameter value, with the post ID as the last parameter. |
0 | 485 |
* |
486 |
* @since 2.7.0 |
|
9 | 487 |
* @since 4.2.0 Custom taxonomy class names were added. |
0 | 488 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
489 |
* @param string|string[] $css_class Optional. Space-separated string or array of class names |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
490 |
* to add to the class list. Default empty. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
491 |
* @param int|WP_Post $post Optional. Post ID or post object. |
9 | 492 |
* @return string[] Array of class names. |
0 | 493 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
494 |
function get_post_class( $css_class = '', $post = null ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
495 |
$post = get_post( $post ); |
0 | 496 |
|
497 |
$classes = array(); |
|
498 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
499 |
if ( $css_class ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
500 |
if ( ! is_array( $css_class ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
501 |
$css_class = preg_split( '#\s+#', $css_class ); |
5 | 502 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
503 |
$classes = array_map( 'esc_attr', $css_class ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
504 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
505 |
// Ensure that we always coerce class to being an array. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
506 |
$css_class = array(); |
5 | 507 |
} |
508 |
||
509 |
if ( ! $post ) { |
|
0 | 510 |
return $classes; |
5 | 511 |
} |
0 | 512 |
|
513 |
$classes[] = 'post-' . $post->ID; |
|
9 | 514 |
if ( ! is_admin() ) { |
0 | 515 |
$classes[] = $post->post_type; |
9 | 516 |
} |
0 | 517 |
$classes[] = 'type-' . $post->post_type; |
518 |
$classes[] = 'status-' . $post->post_status; |
|
519 |
||
16 | 520 |
// Post Format. |
0 | 521 |
if ( post_type_supports( $post->post_type, 'post-formats' ) ) { |
522 |
$post_format = get_post_format( $post->ID ); |
|
523 |
||
9 | 524 |
if ( $post_format && ! is_wp_error( $post_format ) ) { |
0 | 525 |
$classes[] = 'format-' . sanitize_html_class( $post_format ); |
9 | 526 |
} else { |
0 | 527 |
$classes[] = 'format-standard'; |
9 | 528 |
} |
0 | 529 |
} |
530 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
531 |
$post_password_required = post_password_required( $post->ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
532 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
533 |
// Post requires password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
534 |
if ( $post_password_required ) { |
0 | 535 |
$classes[] = 'post-password-required'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
536 |
} elseif ( ! empty( $post->post_password ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
537 |
$classes[] = 'post-password-protected'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
538 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
539 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
540 |
// Post thumbnails. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
541 |
if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $post->ID ) && ! is_attachment( $post ) && ! $post_password_required ) { |
5 | 542 |
$classes[] = 'has-post-thumbnail'; |
543 |
} |
|
0 | 544 |
|
16 | 545 |
// Sticky for Sticky Posts. |
5 | 546 |
if ( is_sticky( $post->ID ) ) { |
547 |
if ( is_home() && ! is_paged() ) { |
|
548 |
$classes[] = 'sticky'; |
|
549 |
} elseif ( is_admin() ) { |
|
550 |
$classes[] = 'status-sticky'; |
|
551 |
} |
|
552 |
} |
|
0 | 553 |
|
16 | 554 |
// hentry for hAtom compliance. |
0 | 555 |
$classes[] = 'hentry'; |
556 |
||
16 | 557 |
// All public taxonomies. |
5 | 558 |
$taxonomies = get_taxonomies( array( 'public' => true ) ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
559 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
560 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
561 |
* Filters the taxonomies to generate classes for each individual term. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
562 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
563 |
* Default is all public taxonomies registered to the post type. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
564 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
565 |
* @since 6.1.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
566 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
567 |
* @param string[] $taxonomies List of all taxonomy names to generate classes for. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
568 |
* @param int $post_id The post ID. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
569 |
* @param string[] $classes An array of post class names. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
570 |
* @param string[] $css_class An array of additional class names added to the post. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
571 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
572 |
$taxonomies = apply_filters( 'post_class_taxonomies', $taxonomies, $post->ID, $classes, $css_class ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
573 |
|
5 | 574 |
foreach ( (array) $taxonomies as $taxonomy ) { |
575 |
if ( is_object_in_taxonomy( $post->post_type, $taxonomy ) ) { |
|
576 |
foreach ( (array) get_the_terms( $post->ID, $taxonomy ) as $term ) { |
|
577 |
if ( empty( $term->slug ) ) { |
|
578 |
continue; |
|
579 |
} |
|
580 |
||
581 |
$term_class = sanitize_html_class( $term->slug, $term->term_id ); |
|
582 |
if ( is_numeric( $term_class ) || ! trim( $term_class, '-' ) ) { |
|
583 |
$term_class = $term->term_id; |
|
584 |
} |
|
585 |
||
586 |
// 'post_tag' uses the 'tag' prefix for backward compatibility. |
|
16 | 587 |
if ( 'post_tag' === $taxonomy ) { |
5 | 588 |
$classes[] = 'tag-' . $term_class; |
589 |
} else { |
|
590 |
$classes[] = sanitize_html_class( $taxonomy . '-' . $term_class, $taxonomy . '-' . $term->term_id ); |
|
591 |
} |
|
592 |
} |
|
0 | 593 |
} |
594 |
} |
|
595 |
||
5 | 596 |
$classes = array_map( 'esc_attr', $classes ); |
0 | 597 |
|
5 | 598 |
/** |
9 | 599 |
* Filters the list of CSS class names for the current post. |
5 | 600 |
* |
601 |
* @since 2.7.0 |
|
602 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
603 |
* @param string[] $classes An array of post class names. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
604 |
* @param string[] $css_class An array of additional class names added to the post. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
605 |
* @param int $post_id The post ID. |
5 | 606 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
607 |
$classes = apply_filters( 'post_class', $classes, $css_class, $post->ID ); |
0 | 608 |
|
5 | 609 |
return array_unique( $classes ); |
0 | 610 |
} |
611 |
||
612 |
/** |
|
9 | 613 |
* Displays the class names for the body element. |
0 | 614 |
* |
615 |
* @since 2.8.0 |
|
616 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
617 |
* @param string|string[] $css_class Optional. Space-separated string or array of class names |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
618 |
* to add to the class list. Default empty. |
0 | 619 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
620 |
function body_class( $css_class = '' ) { |
16 | 621 |
// Separates class names with a single space, collates class names for body element. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
622 |
echo 'class="' . esc_attr( implode( ' ', get_body_class( $css_class ) ) ) . '"'; |
0 | 623 |
} |
624 |
||
625 |
/** |
|
9 | 626 |
* Retrieves an array of the class names for the body element. |
0 | 627 |
* |
628 |
* @since 2.8.0 |
|
629 |
* |
|
16 | 630 |
* @global WP_Query $wp_query WordPress Query object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
631 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
632 |
* @param string|string[] $css_class Optional. Space-separated string or array of class names |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
633 |
* to add to the class list. Default empty. |
9 | 634 |
* @return string[] Array of class names. |
0 | 635 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
636 |
function get_body_class( $css_class = '' ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
637 |
global $wp_query; |
0 | 638 |
|
639 |
$classes = array(); |
|
640 |
||
9 | 641 |
if ( is_rtl() ) { |
0 | 642 |
$classes[] = 'rtl'; |
9 | 643 |
} |
0 | 644 |
|
9 | 645 |
if ( is_front_page() ) { |
0 | 646 |
$classes[] = 'home'; |
9 | 647 |
} |
648 |
if ( is_home() ) { |
|
0 | 649 |
$classes[] = 'blog'; |
9 | 650 |
} |
651 |
if ( is_privacy_policy() ) { |
|
652 |
$classes[] = 'privacy-policy'; |
|
653 |
} |
|
654 |
if ( is_archive() ) { |
|
0 | 655 |
$classes[] = 'archive'; |
9 | 656 |
} |
657 |
if ( is_date() ) { |
|
0 | 658 |
$classes[] = 'date'; |
9 | 659 |
} |
0 | 660 |
if ( is_search() ) { |
661 |
$classes[] = 'search'; |
|
662 |
$classes[] = $wp_query->posts ? 'search-results' : 'search-no-results'; |
|
663 |
} |
|
9 | 664 |
if ( is_paged() ) { |
0 | 665 |
$classes[] = 'paged'; |
9 | 666 |
} |
667 |
if ( is_attachment() ) { |
|
0 | 668 |
$classes[] = 'attachment'; |
9 | 669 |
} |
670 |
if ( is_404() ) { |
|
0 | 671 |
$classes[] = 'error404'; |
9 | 672 |
} |
0 | 673 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
674 |
if ( is_singular() ) { |
9 | 675 |
$post = $wp_query->get_queried_object(); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
676 |
$post_id = $post->ID; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
677 |
$post_type = $post->post_type; |
0 | 678 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
679 |
if ( is_page_template() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
680 |
$classes[] = "{$post_type}-template"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
681 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
682 |
$template_slug = get_page_template_slug( $post_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
683 |
$template_parts = explode( '/', $template_slug ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
684 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
685 |
foreach ( $template_parts as $part ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
686 |
$classes[] = "{$post_type}-template-" . sanitize_html_class( str_replace( array( '.', '/' ), '-', basename( $part, '.php' ) ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
687 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
688 |
$classes[] = "{$post_type}-template-" . sanitize_html_class( str_replace( '.', '-', $template_slug ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
689 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
690 |
$classes[] = "{$post_type}-template-default"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
691 |
} |
0 | 692 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
693 |
if ( is_single() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
694 |
$classes[] = 'single'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
695 |
if ( isset( $post->post_type ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
696 |
$classes[] = 'single-' . sanitize_html_class( $post->post_type, $post_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
697 |
$classes[] = 'postid-' . $post_id; |
0 | 698 |
|
16 | 699 |
// Post Format. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
700 |
if ( post_type_supports( $post->post_type, 'post-formats' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
701 |
$post_format = get_post_format( $post->ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
702 |
|
9 | 703 |
if ( $post_format && ! is_wp_error( $post_format ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
704 |
$classes[] = 'single-format-' . sanitize_html_class( $post_format ); |
9 | 705 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
706 |
$classes[] = 'single-format-standard'; |
9 | 707 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
708 |
} |
0 | 709 |
} |
710 |
} |
|
711 |
||
712 |
if ( is_attachment() ) { |
|
9 | 713 |
$mime_type = get_post_mime_type( $post_id ); |
0 | 714 |
$mime_prefix = array( 'application/', 'image/', 'text/', 'audio/', 'video/', 'music/' ); |
9 | 715 |
$classes[] = 'attachmentid-' . $post_id; |
716 |
$classes[] = 'attachment-' . str_replace( $mime_prefix, '', $mime_type ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
717 |
} elseif ( is_page() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
718 |
$classes[] = 'page'; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
719 |
$classes[] = 'page-id-' . $post_id; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
720 |
|
9 | 721 |
if ( get_pages( |
722 |
array( |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
723 |
'parent' => $post_id, |
9 | 724 |
'number' => 1, |
725 |
) |
|
726 |
) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
727 |
$classes[] = 'page-parent'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
728 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
729 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
730 |
if ( $post->post_parent ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
731 |
$classes[] = 'page-child'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
732 |
$classes[] = 'parent-pageid-' . $post->post_parent; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
733 |
} |
0 | 734 |
} |
735 |
} elseif ( is_archive() ) { |
|
736 |
if ( is_post_type_archive() ) { |
|
737 |
$classes[] = 'post-type-archive'; |
|
738 |
$post_type = get_query_var( 'post_type' ); |
|
9 | 739 |
if ( is_array( $post_type ) ) { |
0 | 740 |
$post_type = reset( $post_type ); |
9 | 741 |
} |
0 | 742 |
$classes[] = 'post-type-archive-' . sanitize_html_class( $post_type ); |
5 | 743 |
} elseif ( is_author() ) { |
9 | 744 |
$author = $wp_query->get_queried_object(); |
0 | 745 |
$classes[] = 'author'; |
746 |
if ( isset( $author->user_nicename ) ) { |
|
747 |
$classes[] = 'author-' . sanitize_html_class( $author->user_nicename, $author->ID ); |
|
748 |
$classes[] = 'author-' . $author->ID; |
|
749 |
} |
|
750 |
} elseif ( is_category() ) { |
|
9 | 751 |
$cat = $wp_query->get_queried_object(); |
0 | 752 |
$classes[] = 'category'; |
753 |
if ( isset( $cat->term_id ) ) { |
|
5 | 754 |
$cat_class = sanitize_html_class( $cat->slug, $cat->term_id ); |
755 |
if ( is_numeric( $cat_class ) || ! trim( $cat_class, '-' ) ) { |
|
756 |
$cat_class = $cat->term_id; |
|
757 |
} |
|
758 |
||
759 |
$classes[] = 'category-' . $cat_class; |
|
0 | 760 |
$classes[] = 'category-' . $cat->term_id; |
761 |
} |
|
762 |
} elseif ( is_tag() ) { |
|
9 | 763 |
$tag = $wp_query->get_queried_object(); |
0 | 764 |
$classes[] = 'tag'; |
5 | 765 |
if ( isset( $tag->term_id ) ) { |
766 |
$tag_class = sanitize_html_class( $tag->slug, $tag->term_id ); |
|
767 |
if ( is_numeric( $tag_class ) || ! trim( $tag_class, '-' ) ) { |
|
768 |
$tag_class = $tag->term_id; |
|
769 |
} |
|
770 |
||
771 |
$classes[] = 'tag-' . $tag_class; |
|
772 |
$classes[] = 'tag-' . $tag->term_id; |
|
0 | 773 |
} |
774 |
} elseif ( is_tax() ) { |
|
775 |
$term = $wp_query->get_queried_object(); |
|
776 |
if ( isset( $term->term_id ) ) { |
|
5 | 777 |
$term_class = sanitize_html_class( $term->slug, $term->term_id ); |
778 |
if ( is_numeric( $term_class ) || ! trim( $term_class, '-' ) ) { |
|
779 |
$term_class = $term->term_id; |
|
780 |
} |
|
781 |
||
0 | 782 |
$classes[] = 'tax-' . sanitize_html_class( $term->taxonomy ); |
5 | 783 |
$classes[] = 'term-' . $term_class; |
0 | 784 |
$classes[] = 'term-' . $term->term_id; |
785 |
} |
|
786 |
} |
|
787 |
} |
|
788 |
||
9 | 789 |
if ( is_user_logged_in() ) { |
0 | 790 |
$classes[] = 'logged-in'; |
9 | 791 |
} |
0 | 792 |
|
793 |
if ( is_admin_bar_showing() ) { |
|
794 |
$classes[] = 'admin-bar'; |
|
795 |
$classes[] = 'no-customize-support'; |
|
796 |
} |
|
797 |
||
9 | 798 |
if ( current_theme_supports( 'custom-background' ) |
799 |
&& ( get_background_color() !== get_theme_support( 'custom-background', 'default-color' ) || get_background_image() ) ) { |
|
0 | 800 |
$classes[] = 'custom-background'; |
9 | 801 |
} |
0 | 802 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
803 |
if ( has_custom_logo() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
804 |
$classes[] = 'wp-custom-logo'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
805 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
806 |
|
9 | 807 |
if ( current_theme_supports( 'responsive-embeds' ) ) { |
808 |
$classes[] = 'wp-embed-responsive'; |
|
809 |
} |
|
810 |
||
0 | 811 |
$page = $wp_query->get( 'page' ); |
812 |
||
9 | 813 |
if ( ! $page || $page < 2 ) { |
0 | 814 |
$page = $wp_query->get( 'paged' ); |
9 | 815 |
} |
0 | 816 |
|
5 | 817 |
if ( $page && $page > 1 && ! is_404() ) { |
0 | 818 |
$classes[] = 'paged-' . $page; |
819 |
||
9 | 820 |
if ( is_single() ) { |
0 | 821 |
$classes[] = 'single-paged-' . $page; |
9 | 822 |
} elseif ( is_page() ) { |
0 | 823 |
$classes[] = 'page-paged-' . $page; |
9 | 824 |
} elseif ( is_category() ) { |
0 | 825 |
$classes[] = 'category-paged-' . $page; |
9 | 826 |
} elseif ( is_tag() ) { |
0 | 827 |
$classes[] = 'tag-paged-' . $page; |
9 | 828 |
} elseif ( is_date() ) { |
0 | 829 |
$classes[] = 'date-paged-' . $page; |
9 | 830 |
} elseif ( is_author() ) { |
0 | 831 |
$classes[] = 'author-paged-' . $page; |
9 | 832 |
} elseif ( is_search() ) { |
0 | 833 |
$classes[] = 'search-paged-' . $page; |
9 | 834 |
} elseif ( is_post_type_archive() ) { |
0 | 835 |
$classes[] = 'post-type-paged-' . $page; |
9 | 836 |
} |
0 | 837 |
} |
838 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
839 |
if ( ! empty( $css_class ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
840 |
if ( ! is_array( $css_class ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
841 |
$css_class = preg_split( '#\s+#', $css_class ); |
9 | 842 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
843 |
$classes = array_merge( $classes, $css_class ); |
0 | 844 |
} else { |
845 |
// Ensure that we always coerce class to being an array. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
846 |
$css_class = array(); |
0 | 847 |
} |
848 |
||
849 |
$classes = array_map( 'esc_attr', $classes ); |
|
850 |
||
5 | 851 |
/** |
9 | 852 |
* Filters the list of CSS body class names for the current post or page. |
5 | 853 |
* |
854 |
* @since 2.8.0 |
|
855 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
856 |
* @param string[] $classes An array of body class names. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
857 |
* @param string[] $css_class An array of additional class names added to the body. |
5 | 858 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
859 |
$classes = apply_filters( 'body_class', $classes, $css_class ); |
5 | 860 |
|
861 |
return array_unique( $classes ); |
|
0 | 862 |
} |
863 |
||
864 |
/** |
|
19 | 865 |
* Determines whether the post requires password and whether a correct password has been provided. |
0 | 866 |
* |
867 |
* @since 2.7.0 |
|
868 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
869 |
* @param int|WP_Post|null $post An optional post. Global $post used if not provided. |
0 | 870 |
* @return bool false if a password is not required or the correct password cookie is present, true otherwise. |
871 |
*/ |
|
872 |
function post_password_required( $post = null ) { |
|
9 | 873 |
$post = get_post( $post ); |
0 | 874 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
875 |
if ( empty( $post->post_password ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
876 |
/** This filter is documented in wp-includes/post-template.php */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
877 |
return apply_filters( 'post_password_required', false, $post ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
878 |
} |
0 | 879 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
880 |
if ( ! isset( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
881 |
/** This filter is documented in wp-includes/post-template.php */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
882 |
return apply_filters( 'post_password_required', true, $post ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
883 |
} |
0 | 884 |
|
5 | 885 |
require_once ABSPATH . WPINC . '/class-phpass.php'; |
0 | 886 |
$hasher = new PasswordHash( 8, true ); |
887 |
||
888 |
$hash = wp_unslash( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
889 |
if ( ! str_starts_with( $hash, '$P$B' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
890 |
$required = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
891 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
892 |
$required = ! $hasher->CheckPassword( $post->post_password, $hash ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
893 |
} |
0 | 894 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
895 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
896 |
* Filters whether a post requires the user to supply a password. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
897 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
898 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
899 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
900 |
* @param bool $required Whether the user needs to supply a password. True if password has not been |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
901 |
* provided or is incorrect, false if password has been supplied or is not required. |
18 | 902 |
* @param WP_Post $post Post object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
903 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
904 |
return apply_filters( 'post_password_required', $required, $post ); |
0 | 905 |
} |
906 |
||
5 | 907 |
// |
16 | 908 |
// Page Template Functions for usage in Themes. |
5 | 909 |
// |
0 | 910 |
|
911 |
/** |
|
912 |
* The formatted output of a list of pages. |
|
913 |
* |
|
9 | 914 |
* Displays page links for paginated posts (i.e. including the `<!--nextpage-->` |
0 | 915 |
* Quicktag one or more times). This tag must be within The Loop. |
916 |
* |
|
917 |
* @since 1.2.0 |
|
9 | 918 |
* @since 5.1.0 Added the `aria_current` argument. |
0 | 919 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
920 |
* @global int $page |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
921 |
* @global int $numpages |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
922 |
* @global int $multipage |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
923 |
* @global int $more |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
924 |
* |
5 | 925 |
* @param string|array $args { |
926 |
* Optional. Array or string of default arguments. |
|
927 |
* |
|
928 |
* @type string $before HTML or text to prepend to each link. Default is `<p> Pages:`. |
|
929 |
* @type string $after HTML or text to append to each link. Default is `</p>`. |
|
930 |
* @type string $link_before HTML or text to prepend to each link, inside the `<a>` tag. |
|
931 |
* Also prepended to the current item, which is not linked. Default empty. |
|
932 |
* @type string $link_after HTML or text to append to each Pages link inside the `<a>` tag. |
|
933 |
* Also appended to the current item, which is not linked. Default empty. |
|
9 | 934 |
* @type string $aria_current The value for the aria-current attribute. Possible values are 'page', |
935 |
* 'step', 'location', 'date', 'time', 'true', 'false'. Default is 'page'. |
|
5 | 936 |
* @type string $next_or_number Indicates whether page numbers should be used. Valid values are number |
937 |
* and next. Default is 'number'. |
|
938 |
* @type string $separator Text between pagination links. Default is ' '. |
|
939 |
* @type string $nextpagelink Link text for the next page link, if available. Default is 'Next Page'. |
|
940 |
* @type string $previouspagelink Link text for the previous page link, if available. Default is 'Previous Page'. |
|
941 |
* @type string $pagelink Format string for page numbers. The % in the parameter string will be |
|
942 |
* replaced with the page number, so 'Page %' generates "Page 1", "Page 2", etc. |
|
943 |
* Defaults to '%', just the page number. |
|
944 |
* @type int|bool $echo Whether to echo or not. Accepts 1|true or 0|false. Default 1|true. |
|
945 |
* } |
|
0 | 946 |
* @return string Formatted output in HTML. |
947 |
*/ |
|
948 |
function wp_link_pages( $args = '' ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
949 |
global $page, $numpages, $multipage, $more; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
950 |
|
0 | 951 |
$defaults = array( |
9 | 952 |
'before' => '<p class="post-nav-links">' . __( 'Pages:' ), |
0 | 953 |
'after' => '</p>', |
954 |
'link_before' => '', |
|
955 |
'link_after' => '', |
|
9 | 956 |
'aria_current' => 'page', |
0 | 957 |
'next_or_number' => 'number', |
958 |
'separator' => ' ', |
|
959 |
'nextpagelink' => __( 'Next page' ), |
|
960 |
'previouspagelink' => __( 'Previous page' ), |
|
961 |
'pagelink' => '%', |
|
9 | 962 |
'echo' => 1, |
0 | 963 |
); |
964 |
||
16 | 965 |
$parsed_args = wp_parse_args( $args, $defaults ); |
5 | 966 |
|
967 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
968 |
* Filters the arguments used in retrieving page links for paginated posts. |
5 | 969 |
* |
970 |
* @since 3.0.0 |
|
971 |
* |
|
18 | 972 |
* @param array $parsed_args An array of page link arguments. See wp_link_pages() |
973 |
* for information on accepted arguments. |
|
5 | 974 |
*/ |
16 | 975 |
$parsed_args = apply_filters( 'wp_link_pages_args', $parsed_args ); |
0 | 976 |
|
977 |
$output = ''; |
|
978 |
if ( $multipage ) { |
|
16 | 979 |
if ( 'number' === $parsed_args['next_or_number'] ) { |
980 |
$output .= $parsed_args['before']; |
|
0 | 981 |
for ( $i = 1; $i <= $numpages; $i++ ) { |
16 | 982 |
$link = $parsed_args['link_before'] . str_replace( '%', $i, $parsed_args['pagelink'] ) . $parsed_args['link_after']; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
983 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
984 |
if ( $i !== $page || ! $more && 1 === $page ) { |
0 | 985 |
$link = _wp_link_page( $i ) . $link . '</a>'; |
9 | 986 |
} elseif ( $i === $page ) { |
16 | 987 |
$link = '<span class="post-page-numbers current" aria-current="' . esc_attr( $parsed_args['aria_current'] ) . '">' . $link . '</span>'; |
5 | 988 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
989 |
|
5 | 990 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
991 |
* Filters the HTML output of individual page number links. |
5 | 992 |
* |
993 |
* @since 3.6.0 |
|
994 |
* |
|
995 |
* @param string $link The page number HTML output. |
|
996 |
* @param int $i Page number for paginated posts' page links. |
|
997 |
*/ |
|
0 | 998 |
$link = apply_filters( 'wp_link_pages_link', $link, $i ); |
5 | 999 |
|
1000 |
// Use the custom links separator beginning with the second link. |
|
16 | 1001 |
$output .= ( 1 === $i ) ? ' ' : $parsed_args['separator']; |
5 | 1002 |
$output .= $link; |
0 | 1003 |
} |
16 | 1004 |
$output .= $parsed_args['after']; |
0 | 1005 |
} elseif ( $more ) { |
16 | 1006 |
$output .= $parsed_args['before']; |
9 | 1007 |
$prev = $page - 1; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1008 |
if ( $prev > 0 ) { |
16 | 1009 |
$link = _wp_link_page( $prev ) . $parsed_args['link_before'] . $parsed_args['previouspagelink'] . $parsed_args['link_after'] . '</a>'; |
5 | 1010 |
|
1011 |
/** This filter is documented in wp-includes/post-template.php */ |
|
1012 |
$output .= apply_filters( 'wp_link_pages_link', $link, $prev ); |
|
0 | 1013 |
} |
5 | 1014 |
$next = $page + 1; |
1015 |
if ( $next <= $numpages ) { |
|
1016 |
if ( $prev ) { |
|
16 | 1017 |
$output .= $parsed_args['separator']; |
5 | 1018 |
} |
16 | 1019 |
$link = _wp_link_page( $next ) . $parsed_args['link_before'] . $parsed_args['nextpagelink'] . $parsed_args['link_after'] . '</a>'; |
5 | 1020 |
|
1021 |
/** This filter is documented in wp-includes/post-template.php */ |
|
1022 |
$output .= apply_filters( 'wp_link_pages_link', $link, $next ); |
|
0 | 1023 |
} |
16 | 1024 |
$output .= $parsed_args['after']; |
0 | 1025 |
} |
1026 |
} |
|
1027 |
||
5 | 1028 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1029 |
* Filters the HTML output of page links for paginated posts. |
5 | 1030 |
* |
1031 |
* @since 3.6.0 |
|
1032 |
* |
|
19 | 1033 |
* @param string $output HTML output of paginated posts' page links. |
1034 |
* @param array|string $args An array or query string of arguments. See wp_link_pages() |
|
1035 |
* for information on accepted arguments. |
|
5 | 1036 |
*/ |
1037 |
$html = apply_filters( 'wp_link_pages', $output, $args ); |
|
0 | 1038 |
|
16 | 1039 |
if ( $parsed_args['echo'] ) { |
5 | 1040 |
echo $html; |
1041 |
} |
|
1042 |
return $html; |
|
0 | 1043 |
} |
1044 |
||
1045 |
/** |
|
1046 |
* Helper function for wp_link_pages(). |
|
1047 |
* |
|
1048 |
* @since 3.1.0 |
|
1049 |
* @access private |
|
1050 |
* |
|
16 | 1051 |
* @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1052 |
* |
0 | 1053 |
* @param int $i Page number. |
1054 |
* @return string Link. |
|
1055 |
*/ |
|
1056 |
function _wp_link_page( $i ) { |
|
1057 |
global $wp_rewrite; |
|
9 | 1058 |
$post = get_post(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1059 |
$query_args = array(); |
0 | 1060 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1061 |
if ( 1 === $i ) { |
0 | 1062 |
$url = get_permalink(); |
1063 |
} else { |
|
16 | 1064 |
if ( ! get_option( 'permalink_structure' ) || in_array( $post->post_status, array( 'draft', 'pending' ), true ) ) { |
0 | 1065 |
$url = add_query_arg( 'page', $i, get_permalink() ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1066 |
} elseif ( 'page' === get_option( 'show_on_front' ) && (int) get_option( 'page_on_front' ) === $post->ID ) { |
9 | 1067 |
$url = trailingslashit( get_permalink() ) . user_trailingslashit( "$wp_rewrite->pagination_base/" . $i, 'single_paged' ); |
1068 |
} else { |
|
1069 |
$url = trailingslashit( get_permalink() ) . user_trailingslashit( $i, 'single_paged' ); |
|
1070 |
} |
|
0 | 1071 |
} |
1072 |
||
5 | 1073 |
if ( is_preview() ) { |
1074 |
||
1075 |
if ( ( 'draft' !== $post->post_status ) && isset( $_GET['preview_id'], $_GET['preview_nonce'] ) ) { |
|
9 | 1076 |
$query_args['preview_id'] = wp_unslash( $_GET['preview_id'] ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1077 |
$query_args['preview_nonce'] = wp_unslash( $_GET['preview_nonce'] ); |
5 | 1078 |
} |
7
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 |
$url = get_preview_post_link( $post, $query_args, $url ); |
5 | 1081 |
} |
1082 |
||
9 | 1083 |
return '<a href="' . esc_url( $url ) . '" class="post-page-numbers">'; |
0 | 1084 |
} |
1085 |
||
1086 |
// |
|
1087 |
// Post-meta: Custom per-post fields. |
|
1088 |
// |
|
1089 |
||
1090 |
/** |
|
19 | 1091 |
* Retrieves post custom meta data field. |
0 | 1092 |
* |
1093 |
* @since 1.5.0 |
|
1094 |
* |
|
1095 |
* @param string $key Meta data key name. |
|
16 | 1096 |
* @return array|string|false Array of values, or single value if only one element exists. |
1097 |
* False if the key does not exist. |
|
0 | 1098 |
*/ |
1099 |
function post_custom( $key = '' ) { |
|
1100 |
$custom = get_post_custom(); |
|
1101 |
||
9 | 1102 |
if ( ! isset( $custom[ $key ] ) ) { |
0 | 1103 |
return false; |
16 | 1104 |
} elseif ( 1 === count( $custom[ $key ] ) ) { |
9 | 1105 |
return $custom[ $key ][0]; |
1106 |
} else { |
|
1107 |
return $custom[ $key ]; |
|
1108 |
} |
|
0 | 1109 |
} |
1110 |
||
1111 |
/** |
|
19 | 1112 |
* Displays a list of post custom fields. |
0 | 1113 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1114 |
* @since 1.2.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1115 |
* |
19 | 1116 |
* @deprecated 6.0.2 Use get_post_meta() to retrieve post meta and render manually. |
0 | 1117 |
*/ |
1118 |
function the_meta() { |
|
19 | 1119 |
_deprecated_function( __FUNCTION__, '6.0.2', 'get_post_meta()' ); |
16 | 1120 |
$keys = get_post_custom_keys(); |
1121 |
if ( $keys ) { |
|
9 | 1122 |
$li_html = ''; |
0 | 1123 |
foreach ( (array) $keys as $key ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1124 |
$keyt = trim( $key ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1125 |
if ( is_protected_meta( $keyt, 'post' ) ) { |
0 | 1126 |
continue; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1127 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1128 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1129 |
$values = array_map( 'trim', get_post_custom_values( $key ) ); |
16 | 1130 |
$value = implode( ', ', $values ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1131 |
|
9 | 1132 |
$html = sprintf( |
1133 |
"<li><span class='post-meta-key'>%s</span> %s</li>\n", |
|
16 | 1134 |
/* translators: %s: Post custom field name. */ |
19 | 1135 |
esc_html( sprintf( _x( '%s:', 'Post custom field name' ), $key ) ), |
1136 |
esc_html( $value ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1137 |
); |
5 | 1138 |
|
1139 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1140 |
* Filters the HTML output of the li element in the post custom fields list. |
5 | 1141 |
* |
1142 |
* @since 2.2.0 |
|
1143 |
* |
|
1144 |
* @param string $html The HTML output for the li element. |
|
1145 |
* @param string $key Meta key. |
|
1146 |
* @param string $value Meta value. |
|
1147 |
*/ |
|
9 | 1148 |
$li_html .= apply_filters( 'the_meta_key', $html, $key, $value ); |
0 | 1149 |
} |
9 | 1150 |
|
1151 |
if ( $li_html ) { |
|
1152 |
echo "<ul class='post-meta'>\n{$li_html}</ul>\n"; |
|
1153 |
} |
|
0 | 1154 |
} |
1155 |
} |
|
1156 |
||
1157 |
// |
|
16 | 1158 |
// Pages. |
0 | 1159 |
// |
1160 |
||
1161 |
/** |
|
19 | 1162 |
* Retrieves or displays a list of pages as a dropdown (select list). |
0 | 1163 |
* |
1164 |
* @since 2.1.0 |
|
5 | 1165 |
* @since 4.2.0 The `$value_field` argument was added. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1166 |
* @since 4.3.0 The `$class` argument was added. |
0 | 1167 |
* |
9 | 1168 |
* @see get_pages() |
1169 |
* |
|
5 | 1170 |
* @param array|string $args { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1171 |
* Optional. Array or string of arguments to generate a page dropdown. See get_pages() for additional arguments. |
5 | 1172 |
* |
1173 |
* @type int $depth Maximum depth. Default 0. |
|
1174 |
* @type int $child_of Page ID to retrieve child pages of. Default 0. |
|
1175 |
* @type int|string $selected Value of the option that should be selected. Default 0. |
|
1176 |
* @type bool|int $echo Whether to echo or return the generated markup. Accepts 0, 1, |
|
1177 |
* or their bool equivalents. Default 1. |
|
1178 |
* @type string $name Value for the 'name' attribute of the select element. |
|
1179 |
* Default 'page_id'. |
|
1180 |
* @type string $id Value for the 'id' attribute of the select element. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1181 |
* @type string $class Value for the 'class' attribute of the select element. Default: none. |
5 | 1182 |
* Defaults to the value of `$name`. |
1183 |
* @type string $show_option_none Text to display for showing no pages. Default empty (does not display). |
|
1184 |
* @type string $show_option_no_change Text to display for "no change" option. Default empty (does not display). |
|
1185 |
* @type string $option_none_value Value to use when no page is selected. Default empty. |
|
1186 |
* @type string $value_field Post field used to populate the 'value' attribute of the option |
|
1187 |
* elements. Accepts any valid post field. Default 'ID'. |
|
1188 |
* } |
|
16 | 1189 |
* @return string HTML dropdown list of pages. |
0 | 1190 |
*/ |
5 | 1191 |
function wp_dropdown_pages( $args = '' ) { |
0 | 1192 |
$defaults = array( |
9 | 1193 |
'depth' => 0, |
1194 |
'child_of' => 0, |
|
1195 |
'selected' => 0, |
|
1196 |
'echo' => 1, |
|
1197 |
'name' => 'page_id', |
|
1198 |
'id' => '', |
|
1199 |
'class' => '', |
|
1200 |
'show_option_none' => '', |
|
1201 |
'show_option_no_change' => '', |
|
1202 |
'option_none_value' => '', |
|
1203 |
'value_field' => 'ID', |
|
0 | 1204 |
); |
1205 |
||
16 | 1206 |
$parsed_args = wp_parse_args( $args, $defaults ); |
0 | 1207 |
|
16 | 1208 |
$pages = get_pages( $parsed_args ); |
0 | 1209 |
$output = ''; |
16 | 1210 |
// Back-compat with old system where both id and name were based on $name argument. |
1211 |
if ( empty( $parsed_args['id'] ) ) { |
|
1212 |
$parsed_args['id'] = $parsed_args['name']; |
|
5 | 1213 |
} |
0 | 1214 |
|
5 | 1215 |
if ( ! empty( $pages ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1216 |
$class = ''; |
16 | 1217 |
if ( ! empty( $parsed_args['class'] ) ) { |
1218 |
$class = " class='" . esc_attr( $parsed_args['class'] ) . "'"; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1219 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1220 |
|
16 | 1221 |
$output = "<select name='" . esc_attr( $parsed_args['name'] ) . "'" . $class . " id='" . esc_attr( $parsed_args['id'] ) . "'>\n"; |
1222 |
if ( $parsed_args['show_option_no_change'] ) { |
|
1223 |
$output .= "\t<option value=\"-1\">" . $parsed_args['show_option_no_change'] . "</option>\n"; |
|
5 | 1224 |
} |
16 | 1225 |
if ( $parsed_args['show_option_none'] ) { |
1226 |
$output .= "\t<option value=\"" . esc_attr( $parsed_args['option_none_value'] ) . '">' . $parsed_args['show_option_none'] . "</option>\n"; |
|
5 | 1227 |
} |
16 | 1228 |
$output .= walk_page_dropdown_tree( $pages, $parsed_args['depth'], $parsed_args ); |
0 | 1229 |
$output .= "</select>\n"; |
1230 |
} |
|
1231 |
||
5 | 1232 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1233 |
* Filters the HTML output of a list of pages as a dropdown. |
5 | 1234 |
* |
1235 |
* @since 2.1.0 |
|
16 | 1236 |
* @since 4.4.0 `$parsed_args` and `$pages` added as arguments. |
5 | 1237 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1238 |
* @param string $output HTML output for dropdown list of pages. |
18 | 1239 |
* @param array $parsed_args The parsed arguments array. See wp_dropdown_pages() |
1240 |
* for information on accepted arguments. |
|
16 | 1241 |
* @param WP_Post[] $pages Array of the page objects. |
9 | 1242 |
*/ |
16 | 1243 |
$html = apply_filters( 'wp_dropdown_pages', $output, $parsed_args, $pages ); |
0 | 1244 |
|
16 | 1245 |
if ( $parsed_args['echo'] ) { |
5 | 1246 |
echo $html; |
1247 |
} |
|
16 | 1248 |
|
5 | 1249 |
return $html; |
0 | 1250 |
} |
1251 |
||
1252 |
/** |
|
19 | 1253 |
* Retrieves or displays a list of pages (or hierarchical post type items) in list (li) format. |
0 | 1254 |
* |
1255 |
* @since 1.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1256 |
* @since 4.7.0 Added the `item_spacing` argument. |
0 | 1257 |
* |
5 | 1258 |
* @see get_pages() |
1259 |
* |
|
16 | 1260 |
* @global WP_Query $wp_query WordPress Query object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1261 |
* |
5 | 1262 |
* @param array|string $args { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1263 |
* Optional. Array or string of arguments to generate a list of pages. See get_pages() for additional arguments. |
5 | 1264 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1265 |
* @type int $child_of Display only the sub-pages of a single page by ID. Default 0 (all pages). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1266 |
* @type string $authors Comma-separated list of author IDs. Default empty (all authors). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1267 |
* @type string $date_format PHP date format to use for the listed pages. Relies on the 'show_date' parameter. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1268 |
* Default is the value of 'date_format' option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1269 |
* @type int $depth Number of levels in the hierarchy of pages to include in the generated list. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1270 |
* Accepts -1 (any depth), 0 (all pages), 1 (top-level pages only), and n (pages to |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1271 |
* the given n depth). Default 0. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1272 |
* @type bool $echo Whether or not to echo the list of pages. Default true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1273 |
* @type string $exclude Comma-separated list of page IDs to exclude. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1274 |
* @type array $include Comma-separated list of page IDs to include. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1275 |
* @type string $link_after Text or HTML to follow the page link label. Default null. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1276 |
* @type string $link_before Text or HTML to precede the page link label. Default null. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1277 |
* @type string $post_type Post type to query for. Default 'page'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1278 |
* @type string|array $post_status Comma-separated list or array of post statuses to include. Default 'publish'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1279 |
* @type string $show_date Whether to display the page publish or modified date for each page. Accepts |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1280 |
* 'modified' or any other value. An empty value hides the date. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1281 |
* @type string $sort_column Comma-separated list of column names to sort the pages by. Accepts 'post_author', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1282 |
* 'post_date', 'post_title', 'post_name', 'post_modified', 'post_modified_gmt', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1283 |
* 'menu_order', 'post_parent', 'ID', 'rand', or 'comment_count'. Default 'post_title'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1284 |
* @type string $title_li List heading. Passing a null or empty value will result in no heading, and the list |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1285 |
* will not be wrapped with unordered list `<ul>` tags. Default 'Pages'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1286 |
* @type string $item_spacing Whether to preserve whitespace within the menu's HTML. Accepts 'preserve' or 'discard'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1287 |
* Default 'preserve'. |
19 | 1288 |
* @type Walker $walker Walker instance to use for listing pages. Default empty which results in a |
1289 |
* Walker_Page instance being used. |
|
5 | 1290 |
* } |
16 | 1291 |
* @return void|string Void if 'echo' argument is true, HTML list of pages if 'echo' is false. |
0 | 1292 |
*/ |
5 | 1293 |
function wp_list_pages( $args = '' ) { |
0 | 1294 |
$defaults = array( |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1295 |
'depth' => 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1296 |
'show_date' => '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1297 |
'date_format' => get_option( 'date_format' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1298 |
'child_of' => 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1299 |
'exclude' => '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1300 |
'title_li' => __( 'Pages' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1301 |
'echo' => 1, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1302 |
'authors' => '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1303 |
'sort_column' => 'menu_order, post_title', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1304 |
'link_before' => '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1305 |
'link_after' => '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1306 |
'item_spacing' => 'preserve', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1307 |
'walker' => '', |
0 | 1308 |
); |
1309 |
||
16 | 1310 |
$parsed_args = wp_parse_args( $args, $defaults ); |
0 | 1311 |
|
16 | 1312 |
if ( ! in_array( $parsed_args['item_spacing'], array( 'preserve', 'discard' ), true ) ) { |
1313 |
// Invalid value, fall back to default. |
|
1314 |
$parsed_args['item_spacing'] = $defaults['item_spacing']; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1315 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1316 |
|
9 | 1317 |
$output = ''; |
0 | 1318 |
$current_page = 0; |
1319 |
||
16 | 1320 |
// Sanitize, mostly to keep spaces out. |
1321 |
$parsed_args['exclude'] = preg_replace( '/[^0-9,]/', '', $parsed_args['exclude'] ); |
|
0 | 1322 |
|
16 | 1323 |
// Allow plugins to filter an array of excluded pages (but don't put a nullstring into the array). |
1324 |
$exclude_array = ( $parsed_args['exclude'] ) ? explode( ',', $parsed_args['exclude'] ) : array(); |
|
5 | 1325 |
|
1326 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1327 |
* Filters the array of pages to exclude from the pages list. |
5 | 1328 |
* |
1329 |
* @since 2.1.0 |
|
1330 |
* |
|
16 | 1331 |
* @param string[] $exclude_array An array of page IDs to exclude. |
5 | 1332 |
*/ |
16 | 1333 |
$parsed_args['exclude'] = implode( ',', apply_filters( 'wp_list_pages_excludes', $exclude_array ) ); |
1334 |
||
1335 |
$parsed_args['hierarchical'] = 0; |
|
0 | 1336 |
|
1337 |
// Query pages. |
|
16 | 1338 |
$pages = get_pages( $parsed_args ); |
0 | 1339 |
|
5 | 1340 |
if ( ! empty( $pages ) ) { |
16 | 1341 |
if ( $parsed_args['title_li'] ) { |
1342 |
$output .= '<li class="pagenav">' . $parsed_args['title_li'] . '<ul>'; |
|
5 | 1343 |
} |
0 | 1344 |
global $wp_query; |
5 | 1345 |
if ( is_page() || is_attachment() || $wp_query->is_posts_page ) { |
1346 |
$current_page = get_queried_object_id(); |
|
1347 |
} elseif ( is_singular() ) { |
|
1348 |
$queried_object = get_queried_object(); |
|
1349 |
if ( is_post_type_hierarchical( $queried_object->post_type ) ) { |
|
1350 |
$current_page = $queried_object->ID; |
|
1351 |
} |
|
1352 |
} |
|
0 | 1353 |
|
16 | 1354 |
$output .= walk_page_tree( $pages, $parsed_args['depth'], $current_page, $parsed_args ); |
5 | 1355 |
|
16 | 1356 |
if ( $parsed_args['title_li'] ) { |
0 | 1357 |
$output .= '</ul></li>'; |
5 | 1358 |
} |
0 | 1359 |
} |
1360 |
||
5 | 1361 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1362 |
* Filters the HTML output of the pages to list. |
5 | 1363 |
* |
1364 |
* @since 1.5.1 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1365 |
* @since 4.4.0 `$pages` added as arguments. |
5 | 1366 |
* |
1367 |
* @see wp_list_pages() |
|
1368 |
* |
|
16 | 1369 |
* @param string $output HTML output of the pages list. |
18 | 1370 |
* @param array $parsed_args An array of page-listing arguments. See wp_list_pages() |
1371 |
* for information on accepted arguments. |
|
16 | 1372 |
* @param WP_Post[] $pages Array of the page objects. |
5 | 1373 |
*/ |
16 | 1374 |
$html = apply_filters( 'wp_list_pages', $output, $parsed_args, $pages ); |
0 | 1375 |
|
16 | 1376 |
if ( $parsed_args['echo'] ) { |
5 | 1377 |
echo $html; |
1378 |
} else { |
|
1379 |
return $html; |
|
1380 |
} |
|
0 | 1381 |
} |
1382 |
||
1383 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1384 |
* Displays or retrieves a list of pages with an optional home link. |
0 | 1385 |
* |
9 | 1386 |
* The arguments are listed below and part of the arguments are for wp_list_pages() function. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1387 |
* Check that function for more info on those arguments. |
0 | 1388 |
* |
1389 |
* @since 2.7.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1390 |
* @since 4.4.0 Added `menu_id`, `container`, `before`, `after`, and `walker` arguments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1391 |
* @since 4.7.0 Added the `item_spacing` argument. |
0 | 1392 |
* |
5 | 1393 |
* @param array|string $args { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1394 |
* Optional. Array or string of arguments to generate a page menu. See wp_list_pages() for additional arguments. |
5 | 1395 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1396 |
* @type string $sort_column How to sort the list of pages. Accepts post column names. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1397 |
* Default 'menu_order, post_title'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1398 |
* @type string $menu_id ID for the div containing the page list. Default is empty string. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1399 |
* @type string $menu_class Class to use for the element containing the page list. Default 'menu'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1400 |
* @type string $container Element to use for the element containing the page list. Default 'div'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1401 |
* @type bool $echo Whether to echo the list or return it. Accepts true (echo) or false (return). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1402 |
* Default true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1403 |
* @type int|bool|string $show_home Whether to display the link to the home page. Can just enter the text |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1404 |
* you'd like shown for the home link. 1|true defaults to 'Home'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1405 |
* @type string $link_before The HTML or text to prepend to $show_home text. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1406 |
* @type string $link_after The HTML or text to append to $show_home text. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1407 |
* @type string $before The HTML or text to prepend to the menu. Default is '<ul>'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1408 |
* @type string $after The HTML or text to append to the menu. Default is '</ul>'. |
9 | 1409 |
* @type string $item_spacing Whether to preserve whitespace within the menu's HTML. Accepts 'preserve' |
1410 |
* or 'discard'. Default 'discard'. |
|
19 | 1411 |
* @type Walker $walker Walker instance to use for listing pages. Default empty which results in a |
1412 |
* Walker_Page instance being used. |
|
5 | 1413 |
* } |
16 | 1414 |
* @return void|string Void if 'echo' argument is true, HTML menu if 'echo' is false. |
0 | 1415 |
*/ |
1416 |
function wp_page_menu( $args = array() ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1417 |
$defaults = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1418 |
'sort_column' => 'menu_order, post_title', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1419 |
'menu_id' => '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1420 |
'menu_class' => 'menu', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1421 |
'container' => 'div', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1422 |
'echo' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1423 |
'link_before' => '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1424 |
'link_after' => '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1425 |
'before' => '<ul>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1426 |
'after' => '</ul>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1427 |
'item_spacing' => 'discard', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1428 |
'walker' => '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1429 |
); |
9 | 1430 |
$args = wp_parse_args( $args, $defaults ); |
5 | 1431 |
|
16 | 1432 |
if ( ! in_array( $args['item_spacing'], array( 'preserve', 'discard' ), true ) ) { |
1433 |
// Invalid value, fall back to default. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1434 |
$args['item_spacing'] = $defaults['item_spacing']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1435 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1436 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1437 |
if ( 'preserve' === $args['item_spacing'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1438 |
$t = "\t"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1439 |
$n = "\n"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1440 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1441 |
$t = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1442 |
$n = ''; |
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 |
|
5 | 1445 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1446 |
* Filters the arguments used to generate a page-based menu. |
5 | 1447 |
* |
1448 |
* @since 2.7.0 |
|
1449 |
* |
|
1450 |
* @see wp_page_menu() |
|
1451 |
* |
|
18 | 1452 |
* @param array $args An array of page menu arguments. See wp_page_menu() |
1453 |
* for information on accepted arguments. |
|
5 | 1454 |
*/ |
0 | 1455 |
$args = apply_filters( 'wp_page_menu_args', $args ); |
1456 |
||
1457 |
$menu = ''; |
|
1458 |
||
1459 |
$list_args = $args; |
|
1460 |
||
16 | 1461 |
// Show Home in the menu. |
9 | 1462 |
if ( ! empty( $args['show_home'] ) ) { |
1463 |
if ( true === $args['show_home'] || '1' === $args['show_home'] || 1 === $args['show_home'] ) { |
|
1464 |
$text = __( 'Home' ); |
|
1465 |
} else { |
|
0 | 1466 |
$text = $args['show_home']; |
9 | 1467 |
} |
0 | 1468 |
$class = ''; |
9 | 1469 |
if ( is_front_page() && ! is_paged() ) { |
0 | 1470 |
$class = 'class="current_page_item"'; |
9 | 1471 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1472 |
$menu .= '<li ' . $class . '><a href="' . esc_url( home_url( '/' ) ) . '">' . $args['link_before'] . $text . $args['link_after'] . '</a></li>'; |
16 | 1473 |
// If the front page is a page, add it to the exclude list. |
1474 |
if ( 'page' === get_option( 'show_on_front' ) ) { |
|
9 | 1475 |
if ( ! empty( $list_args['exclude'] ) ) { |
0 | 1476 |
$list_args['exclude'] .= ','; |
1477 |
} else { |
|
1478 |
$list_args['exclude'] = ''; |
|
1479 |
} |
|
9 | 1480 |
$list_args['exclude'] .= get_option( 'page_on_front' ); |
0 | 1481 |
} |
1482 |
} |
|
1483 |
||
9 | 1484 |
$list_args['echo'] = false; |
0 | 1485 |
$list_args['title_li'] = ''; |
9 | 1486 |
$menu .= wp_list_pages( $list_args ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1487 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1488 |
$container = sanitize_text_field( $args['container'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1489 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1490 |
// Fallback in case `wp_nav_menu()` was called without a container. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1491 |
if ( empty( $container ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1492 |
$container = 'div'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1493 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1494 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1495 |
if ( $menu ) { |
0 | 1496 |
|
16 | 1497 |
// wp_nav_menu() doesn't set before and after. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1498 |
if ( isset( $args['fallback_cb'] ) && |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1499 |
'wp_page_menu' === $args['fallback_cb'] && |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1500 |
'ul' !== $container ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1501 |
$args['before'] = "<ul>{$n}"; |
9 | 1502 |
$args['after'] = '</ul>'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1503 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1504 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1505 |
$menu = $args['before'] . $menu . $args['after']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1506 |
} |
0 | 1507 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1508 |
$attrs = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1509 |
if ( ! empty( $args['menu_id'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1510 |
$attrs .= ' id="' . esc_attr( $args['menu_id'] ) . '"'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1511 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1512 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1513 |
if ( ! empty( $args['menu_class'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1514 |
$attrs .= ' class="' . esc_attr( $args['menu_class'] ) . '"'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1515 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1516 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1517 |
$menu = "<{$container}{$attrs}>" . $menu . "</{$container}>{$n}"; |
5 | 1518 |
|
1519 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1520 |
* Filters the HTML output of a page-based menu. |
5 | 1521 |
* |
1522 |
* @since 2.7.0 |
|
1523 |
* |
|
1524 |
* @see wp_page_menu() |
|
1525 |
* |
|
1526 |
* @param string $menu The HTML output. |
|
18 | 1527 |
* @param array $args An array of arguments. See wp_page_menu() |
1528 |
* for information on accepted arguments. |
|
5 | 1529 |
*/ |
0 | 1530 |
$menu = apply_filters( 'wp_page_menu', $menu, $args ); |
16 | 1531 |
|
9 | 1532 |
if ( $args['echo'] ) { |
0 | 1533 |
echo $menu; |
9 | 1534 |
} else { |
0 | 1535 |
return $menu; |
9 | 1536 |
} |
0 | 1537 |
} |
1538 |
||
1539 |
// |
|
16 | 1540 |
// Page helpers. |
0 | 1541 |
// |
1542 |
||
1543 |
/** |
|
19 | 1544 |
* Retrieves HTML list content for page list. |
0 | 1545 |
* |
1546 |
* @uses Walker_Page to create HTML list content. |
|
1547 |
* @since 2.1.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1548 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1549 |
* @param array $pages |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1550 |
* @param int $depth |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1551 |
* @param int $current_page |
19 | 1552 |
* @param array $args |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1553 |
* @return string |
0 | 1554 |
*/ |
19 | 1555 |
function walk_page_tree( $pages, $depth, $current_page, $args ) { |
1556 |
if ( empty( $args['walker'] ) ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1557 |
$walker = new Walker_Page(); |
9 | 1558 |
} else { |
16 | 1559 |
/** |
1560 |
* @var Walker $walker |
|
1561 |
*/ |
|
19 | 1562 |
$walker = $args['walker']; |
9 | 1563 |
} |
0 | 1564 |
|
1565 |
foreach ( (array) $pages as $page ) { |
|
9 | 1566 |
if ( $page->post_parent ) { |
19 | 1567 |
$args['pages_with_children'][ $page->post_parent ] = true; |
9 | 1568 |
} |
0 | 1569 |
} |
1570 |
||
19 | 1571 |
return $walker->walk( $pages, $depth, $args, $current_page ); |
0 | 1572 |
} |
1573 |
||
1574 |
/** |
|
19 | 1575 |
* Retrieves HTML dropdown (select) content for page list. |
0 | 1576 |
* |
16 | 1577 |
* @since 2.1.0 |
1578 |
* @since 5.3.0 Formalized the existing `...$args` parameter by adding it |
|
1579 |
* to the function signature. |
|
1580 |
* |
|
0 | 1581 |
* @uses Walker_PageDropdown to create HTML dropdown content. |
1582 |
* @see Walker_PageDropdown::walk() for parameters and return description. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1583 |
* |
16 | 1584 |
* @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
|
1585 |
* @return string |
0 | 1586 |
*/ |
16 | 1587 |
function walk_page_dropdown_tree( ...$args ) { |
1588 |
if ( empty( $args[2]['walker'] ) ) { // The user's options are the third parameter. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1589 |
$walker = new Walker_PageDropdown(); |
9 | 1590 |
} else { |
16 | 1591 |
/** |
1592 |
* @var Walker $walker |
|
1593 |
*/ |
|
0 | 1594 |
$walker = $args[2]['walker']; |
9 | 1595 |
} |
0 | 1596 |
|
16 | 1597 |
return $walker->walk( ...$args ); |
0 | 1598 |
} |
1599 |
||
1600 |
// |
|
16 | 1601 |
// Attachments. |
0 | 1602 |
// |
1603 |
||
1604 |
/** |
|
19 | 1605 |
* Displays an attachment page link using an image or icon. |
0 | 1606 |
* |
1607 |
* @since 2.0.0 |
|
1608 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1609 |
* @param int|WP_Post $post Optional. Post ID or post object. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1610 |
* @param bool $fullsize Optional. Whether to use full size. Default false. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1611 |
* @param bool $deprecated Deprecated. Not used. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1612 |
* @param bool $permalink Optional. Whether to include permalink. Default false. |
0 | 1613 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1614 |
function the_attachment_link( $post = 0, $fullsize = false, $deprecated = false, $permalink = false ) { |
9 | 1615 |
if ( ! empty( $deprecated ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1616 |
_deprecated_argument( __FUNCTION__, '2.5.0' ); |
9 | 1617 |
} |
0 | 1618 |
|
9 | 1619 |
if ( $fullsize ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1620 |
echo wp_get_attachment_link( $post, 'full', $permalink ); |
9 | 1621 |
} else { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1622 |
echo wp_get_attachment_link( $post, 'thumbnail', $permalink ); |
9 | 1623 |
} |
0 | 1624 |
} |
1625 |
||
1626 |
/** |
|
19 | 1627 |
* Retrieves an attachment page link using an image or icon, if possible. |
0 | 1628 |
* |
1629 |
* @since 2.5.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1630 |
* @since 4.4.0 The `$post` parameter can now accept either a post ID or `WP_Post` object. |
0 | 1631 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1632 |
* @param int|WP_Post $post Optional. Post ID or post object. |
18 | 1633 |
* @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array |
1634 |
* of width and height values in pixels (in that order). Default 'thumbnail'. |
|
16 | 1635 |
* @param bool $permalink Optional. Whether to add permalink to image. Default false. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1636 |
* @param bool $icon Optional. Whether the attachment is an icon. Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1637 |
* @param string|false $text Optional. Link text to use. Activated by passing a string, false otherwise. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1638 |
* Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1639 |
* @param array|string $attr Optional. Array or string of attributes. Default empty. |
0 | 1640 |
* @return string HTML content. |
1641 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1642 |
function wp_get_attachment_link( $post = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '' ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1643 |
$_post = get_post( $post ); |
0 | 1644 |
|
16 | 1645 |
if ( empty( $_post ) || ( 'attachment' !== $_post->post_type ) || ! wp_get_attachment_url( $_post->ID ) ) { |
0 | 1646 |
return __( 'Missing Attachment' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1647 |
} |
0 | 1648 |
|
16 | 1649 |
$url = wp_get_attachment_url( $_post->ID ); |
1650 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1651 |
if ( $permalink ) { |
0 | 1652 |
$url = get_attachment_link( $_post->ID ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1653 |
} |
0 | 1654 |
|
5 | 1655 |
if ( $text ) { |
0 | 1656 |
$link_text = $text; |
16 | 1657 |
} elseif ( $size && 'none' !== $size ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1658 |
$link_text = wp_get_attachment_image( $_post->ID, $size, $icon, $attr ); |
5 | 1659 |
} else { |
0 | 1660 |
$link_text = ''; |
5 | 1661 |
} |
0 | 1662 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1663 |
if ( '' === trim( $link_text ) ) { |
0 | 1664 |
$link_text = $_post->post_title; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1665 |
} |
0 | 1666 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1667 |
if ( '' === trim( $link_text ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1668 |
$link_text = esc_html( pathinfo( get_attached_file( $_post->ID ), PATHINFO_FILENAME ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1669 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1670 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1671 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1672 |
* Filters the list of attachment link attributes. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1673 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1674 |
* @since 6.2.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1675 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1676 |
* @param array $attributes An array of attributes for the link markup, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1677 |
* keyed on the attribute name. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1678 |
* @param int $id Post ID. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1679 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1680 |
$attributes = apply_filters( 'wp_get_attachment_link_attributes', array( 'href' => $url ), $_post->ID ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1681 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1682 |
$link_attributes = ''; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1683 |
foreach ( $attributes as $name => $value ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1684 |
$value = 'href' === $name ? esc_url( $value ) : esc_attr( $value ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1685 |
$link_attributes .= ' ' . esc_attr( $name ) . "='" . $value . "'"; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1686 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1687 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1688 |
$link_html = "<a$link_attributes>$link_text</a>"; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1689 |
|
5 | 1690 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1691 |
* Filters a retrieved attachment page link. |
5 | 1692 |
* |
1693 |
* @since 2.7.0 |
|
18 | 1694 |
* @since 5.1.0 Added the `$attr` parameter. |
5 | 1695 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1696 |
* @param string $link_html The page link HTML output. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1697 |
* @param int|WP_Post $post Post ID or object. Can be 0 for the current global post. |
18 | 1698 |
* @param string|int[] $size Requested image size. Can be any registered image size name, or |
1699 |
* an array of width and height values in pixels (in that order). |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1700 |
* @param bool $permalink Whether to add permalink to image. Default false. |
18 | 1701 |
* @param bool $icon Whether to include an icon. |
1702 |
* @param string|false $text If string, will be link text. |
|
1703 |
* @param array|string $attr Array or string of attributes. |
|
5 | 1704 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1705 |
return apply_filters( 'wp_get_attachment_link', $link_html, $post, $size, $permalink, $icon, $text, $attr ); |
0 | 1706 |
} |
1707 |
||
1708 |
/** |
|
19 | 1709 |
* Wraps attachment in paragraph tag before content. |
0 | 1710 |
* |
1711 |
* @since 2.0.0 |
|
1712 |
* |
|
1713 |
* @param string $content |
|
1714 |
* @return string |
|
1715 |
*/ |
|
9 | 1716 |
function prepend_attachment( $content ) { |
0 | 1717 |
$post = get_post(); |
1718 |
||
16 | 1719 |
if ( empty( $post->post_type ) || 'attachment' !== $post->post_type ) { |
0 | 1720 |
return $content; |
9 | 1721 |
} |
0 | 1722 |
|
5 | 1723 |
if ( wp_attachment_is( 'video', $post ) ) { |
1724 |
$meta = wp_get_attachment_metadata( get_the_ID() ); |
|
1725 |
$atts = array( 'src' => wp_get_attachment_url() ); |
|
1726 |
if ( ! empty( $meta['width'] ) && ! empty( $meta['height'] ) ) { |
|
9 | 1727 |
$atts['width'] = (int) $meta['width']; |
5 | 1728 |
$atts['height'] = (int) $meta['height']; |
1729 |
} |
|
1730 |
if ( has_post_thumbnail() ) { |
|
1731 |
$atts['poster'] = wp_get_attachment_url( get_post_thumbnail_id() ); |
|
1732 |
} |
|
1733 |
$p = wp_video_shortcode( $atts ); |
|
1734 |
} elseif ( wp_attachment_is( 'audio', $post ) ) { |
|
1735 |
$p = wp_audio_shortcode( array( 'src' => wp_get_attachment_url() ) ); |
|
1736 |
} else { |
|
1737 |
$p = '<p class="attachment">'; |
|
16 | 1738 |
// Show the medium sized image representation of the attachment if available, and link to the raw file. |
9 | 1739 |
$p .= wp_get_attachment_link( 0, 'medium', false ); |
5 | 1740 |
$p .= '</p>'; |
1741 |
} |
|
1742 |
||
1743 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1744 |
* Filters the attachment markup to be prepended to the post content. |
5 | 1745 |
* |
1746 |
* @since 2.0.0 |
|
1747 |
* |
|
1748 |
* @see prepend_attachment() |
|
1749 |
* |
|
1750 |
* @param string $p The attachment HTML output. |
|
1751 |
*/ |
|
1752 |
$p = apply_filters( 'prepend_attachment', $p ); |
|
0 | 1753 |
|
1754 |
return "$p\n$content"; |
|
1755 |
} |
|
1756 |
||
1757 |
// |
|
16 | 1758 |
// Misc. |
0 | 1759 |
// |
1760 |
||
1761 |
/** |
|
19 | 1762 |
* Retrieves protected post password form content. |
0 | 1763 |
* |
1764 |
* @since 1.0.0 |
|
5 | 1765 |
* |
1766 |
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post. |
|
0 | 1767 |
* @return string HTML content for password form for password protected post. |
1768 |
*/ |
|
1769 |
function get_the_password_form( $post = 0 ) { |
|
9 | 1770 |
$post = get_post( $post ); |
1771 |
$label = 'pwbox-' . ( empty( $post->ID ) ? rand() : $post->ID ); |
|
0 | 1772 |
$output = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" class="post-password-form" method="post"> |
1773 |
<p>' . __( 'This content is password protected. To view it please enter your password below:' ) . '</p> |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1774 |
<p><label for="' . $label . '">' . __( 'Password:' ) . ' <input name="post_password" id="' . $label . '" type="password" spellcheck="false" size="20" /></label> <input type="submit" name="Submit" value="' . esc_attr_x( 'Enter', 'post password form' ) . '" /></p></form> |
0 | 1775 |
'; |
5 | 1776 |
|
1777 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1778 |
* Filters the HTML output for the protected post password form. |
5 | 1779 |
* |
1780 |
* If modifying the password field, please note that the core database schema |
|
1781 |
* limits the password field to 20 characters regardless of the value of the |
|
1782 |
* size attribute in the form input. |
|
1783 |
* |
|
1784 |
* @since 2.7.0 |
|
18 | 1785 |
* @since 5.8.0 Added the `$post` parameter. |
5 | 1786 |
* |
18 | 1787 |
* @param string $output The password form HTML output. |
1788 |
* @param WP_Post $post Post object. |
|
5 | 1789 |
*/ |
18 | 1790 |
return apply_filters( 'the_password_form', $output, $post ); |
0 | 1791 |
} |
1792 |
||
1793 |
/** |
|
19 | 1794 |
* Determines whether the current post uses a page template. |
0 | 1795 |
* |
1796 |
* This template tag allows you to determine if you are in a page template. |
|
16 | 1797 |
* You can optionally provide a template filename or array of template filenames |
5 | 1798 |
* and then the check will be specific to that template. |
0 | 1799 |
* |
9 | 1800 |
* For more information on this and similar theme functions, check out |
1801 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
1802 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
1803 |
* |
|
0 | 1804 |
* @since 2.5.0 |
5 | 1805 |
* @since 4.2.0 The `$template` parameter was changed to also accept an array of page templates. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1806 |
* @since 4.7.0 Now works with any post type, not just pages. |
0 | 1807 |
* |
18 | 1808 |
* @param string|string[] $template The specific template filename or array of templates to match. |
0 | 1809 |
* @return bool True on success, false on failure. |
1810 |
*/ |
|
1811 |
function is_page_template( $template = '' ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1812 |
if ( ! is_singular() ) { |
0 | 1813 |
return false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1814 |
} |
0 | 1815 |
|
1816 |
$page_template = get_page_template_slug( get_queried_object_id() ); |
|
1817 |
||
9 | 1818 |
if ( empty( $template ) ) { |
0 | 1819 |
return (bool) $page_template; |
9 | 1820 |
} |
0 | 1821 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1822 |
if ( $template === $page_template ) { |
0 | 1823 |
return true; |
9 | 1824 |
} |
0 | 1825 |
|
5 | 1826 |
if ( is_array( $template ) ) { |
1827 |
if ( ( in_array( 'default', $template, true ) && ! $page_template ) |
|
1828 |
|| in_array( $page_template, $template, true ) |
|
1829 |
) { |
|
1830 |
return true; |
|
1831 |
} |
|
1832 |
} |
|
1833 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1834 |
return ( 'default' === $template && ! $page_template ); |
0 | 1835 |
} |
1836 |
||
1837 |
/** |
|
19 | 1838 |
* Gets the specific template filename for a given post. |
0 | 1839 |
* |
1840 |
* @since 3.4.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1841 |
* @since 4.7.0 Now works with any post type, not just pages. |
0 | 1842 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1843 |
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1844 |
* @return string|false Page template filename. Returns an empty string when the default page template |
16 | 1845 |
* is in use. Returns false if the post does not exist. |
0 | 1846 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1847 |
function get_page_template_slug( $post = null ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1848 |
$post = get_post( $post ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1849 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1850 |
if ( ! $post ) { |
0 | 1851 |
return false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1852 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1853 |
|
0 | 1854 |
$template = get_post_meta( $post->ID, '_wp_page_template', true ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1855 |
|
16 | 1856 |
if ( ! $template || 'default' === $template ) { |
0 | 1857 |
return ''; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1858 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1859 |
|
0 | 1860 |
return $template; |
1861 |
} |
|
1862 |
||
1863 |
/** |
|
19 | 1864 |
* Retrieves formatted date timestamp of a revision (linked to that revisions's page). |
0 | 1865 |
* |
1866 |
* @since 2.6.0 |
|
1867 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1868 |
* @param int|WP_Post $revision Revision ID or revision object. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1869 |
* @param bool $link Optional. Whether to link to revision's page. Default true. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1870 |
* @return string|false i18n formatted datetimestamp or localized 'Current Revision'. |
0 | 1871 |
*/ |
1872 |
function wp_post_revision_title( $revision, $link = true ) { |
|
16 | 1873 |
$revision = get_post( $revision ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1874 |
|
16 | 1875 |
if ( ! $revision ) { |
0 | 1876 |
return $revision; |
9 | 1877 |
} |
0 | 1878 |
|
16 | 1879 |
if ( ! in_array( $revision->post_type, array( 'post', 'page', 'revision' ), true ) ) { |
0 | 1880 |
return false; |
9 | 1881 |
} |
0 | 1882 |
|
18 | 1883 |
/* translators: Revision date format, see https://www.php.net/manual/datetime.format.php */ |
5 | 1884 |
$datef = _x( 'F j, Y @ H:i:s', 'revision date format' ); |
16 | 1885 |
/* translators: %s: Revision date. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1886 |
$autosavef = __( '%s [Autosave]' ); |
16 | 1887 |
/* translators: %s: Revision date. */ |
9 | 1888 |
$currentf = __( '%s [Current Revision]' ); |
0 | 1889 |
|
16 | 1890 |
$date = date_i18n( $datef, strtotime( $revision->post_modified ) ); |
1891 |
$edit_link = get_edit_post_link( $revision->ID ); |
|
1892 |
if ( $link && current_user_can( 'edit_post', $revision->ID ) && $edit_link ) { |
|
1893 |
$date = "<a href='$edit_link'>$date</a>"; |
|
9 | 1894 |
} |
0 | 1895 |
|
9 | 1896 |
if ( ! wp_is_post_revision( $revision ) ) { |
0 | 1897 |
$date = sprintf( $currentf, $date ); |
9 | 1898 |
} elseif ( wp_is_post_autosave( $revision ) ) { |
0 | 1899 |
$date = sprintf( $autosavef, $date ); |
9 | 1900 |
} |
0 | 1901 |
|
1902 |
return $date; |
|
1903 |
} |
|
1904 |
||
1905 |
/** |
|
19 | 1906 |
* Retrieves formatted date timestamp of a revision (linked to that revisions's page). |
0 | 1907 |
* |
1908 |
* @since 3.6.0 |
|
1909 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1910 |
* @param int|WP_Post $revision Revision ID or revision object. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1911 |
* @param bool $link Optional. Whether to link to revision's page. Default true. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1912 |
* @return string|false gravatar, user, i18n formatted datetimestamp or localized 'Current Revision'. |
0 | 1913 |
*/ |
1914 |
function wp_post_revision_title_expanded( $revision, $link = true ) { |
|
16 | 1915 |
$revision = get_post( $revision ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1916 |
|
16 | 1917 |
if ( ! $revision ) { |
0 | 1918 |
return $revision; |
9 | 1919 |
} |
0 | 1920 |
|
16 | 1921 |
if ( ! in_array( $revision->post_type, array( 'post', 'page', 'revision' ), true ) ) { |
0 | 1922 |
return false; |
9 | 1923 |
} |
0 | 1924 |
|
1925 |
$author = get_the_author_meta( 'display_name', $revision->post_author ); |
|
18 | 1926 |
/* translators: Revision date format, see https://www.php.net/manual/datetime.format.php */ |
5 | 1927 |
$datef = _x( 'F j, Y @ H:i:s', 'revision date format' ); |
0 | 1928 |
|
1929 |
$gravatar = get_avatar( $revision->post_author, 24 ); |
|
1930 |
||
16 | 1931 |
$date = date_i18n( $datef, strtotime( $revision->post_modified ) ); |
1932 |
$edit_link = get_edit_post_link( $revision->ID ); |
|
1933 |
if ( $link && current_user_can( 'edit_post', $revision->ID ) && $edit_link ) { |
|
1934 |
$date = "<a href='$edit_link'>$date</a>"; |
|
9 | 1935 |
} |
0 | 1936 |
|
1937 |
$revision_date_author = sprintf( |
|
16 | 1938 |
/* translators: Post revision title. 1: Author avatar, 2: Author name, 3: Time ago, 4: Date. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1939 |
__( '%1$s %2$s, %3$s ago (%4$s)' ), |
0 | 1940 |
$gravatar, |
1941 |
$author, |
|
16 | 1942 |
human_time_diff( strtotime( $revision->post_modified_gmt ) ), |
0 | 1943 |
$date |
1944 |
); |
|
1945 |
||
16 | 1946 |
/* translators: %s: Revision date with author avatar. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1947 |
$autosavef = __( '%s [Autosave]' ); |
16 | 1948 |
/* translators: %s: Revision date with author avatar. */ |
9 | 1949 |
$currentf = __( '%s [Current Revision]' ); |
0 | 1950 |
|
9 | 1951 |
if ( ! wp_is_post_revision( $revision ) ) { |
0 | 1952 |
$revision_date_author = sprintf( $currentf, $revision_date_author ); |
9 | 1953 |
} elseif ( wp_is_post_autosave( $revision ) ) { |
0 | 1954 |
$revision_date_author = sprintf( $autosavef, $revision_date_author ); |
9 | 1955 |
} |
0 | 1956 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1957 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1958 |
* Filters the formatted author and date for a revision. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1959 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1960 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1961 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1962 |
* @param string $revision_date_author The formatted string. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1963 |
* @param WP_Post $revision The revision object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1964 |
* @param bool $link Whether to link to the revisions page, as passed into |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1965 |
* wp_post_revision_title_expanded(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1966 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1967 |
return apply_filters( 'wp_post_revision_title_expanded', $revision_date_author, $revision, $link ); |
0 | 1968 |
} |
1969 |
||
1970 |
/** |
|
19 | 1971 |
* Displays a list of a post's revisions. |
0 | 1972 |
* |
1973 |
* Can output either a UL with edit links or a TABLE with diff interface, and |
|
1974 |
* restore action links. |
|
1975 |
* |
|
1976 |
* @since 2.6.0 |
|
1977 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1978 |
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1979 |
* @param string $type 'all' (default), 'revision' or 'autosave' |
0 | 1980 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1981 |
function wp_list_post_revisions( $post = 0, $type = 'all' ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1982 |
$post = get_post( $post ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1983 |
|
16 | 1984 |
if ( ! $post ) { |
0 | 1985 |
return; |
9 | 1986 |
} |
0 | 1987 |
|
16 | 1988 |
// $args array with (parent, format, right, left, type) deprecated since 3.6. |
0 | 1989 |
if ( is_array( $type ) ) { |
9 | 1990 |
$type = ! empty( $type['type'] ) ? $type['type'] : $type; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1991 |
_deprecated_argument( __FUNCTION__, '3.6.0' ); |
0 | 1992 |
} |
1993 |
||
16 | 1994 |
$revisions = wp_get_post_revisions( $post->ID ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1995 |
|
16 | 1996 |
if ( ! $revisions ) { |
0 | 1997 |
return; |
9 | 1998 |
} |
0 | 1999 |
|
2000 |
$rows = ''; |
|
2001 |
foreach ( $revisions as $revision ) { |
|
9 | 2002 |
if ( ! current_user_can( 'read_post', $revision->ID ) ) { |
0 | 2003 |
continue; |
9 | 2004 |
} |
0 | 2005 |
|
2006 |
$is_autosave = wp_is_post_autosave( $revision ); |
|
9 | 2007 |
if ( ( 'revision' === $type && $is_autosave ) || ( 'autosave' === $type && ! $is_autosave ) ) { |
0 | 2008 |
continue; |
9 | 2009 |
} |
0 | 2010 |
|
2011 |
$rows .= "\t<li>" . wp_post_revision_title_expanded( $revision ) . "</li>\n"; |
|
2012 |
} |
|
2013 |
||
2014 |
echo "<div class='hide-if-js'><p>" . __( 'JavaScript must be enabled to use this feature.' ) . "</p></div>\n"; |
|
2015 |
||
2016 |
echo "<ul class='post-revisions hide-if-no-js'>\n"; |
|
2017 |
echo $rows; |
|
9 | 2018 |
echo '</ul>'; |
0 | 2019 |
} |
18 | 2020 |
|
2021 |
/** |
|
2022 |
* Retrieves the parent post object for the given post. |
|
2023 |
* |
|
2024 |
* @since 5.7.0 |
|
2025 |
* |
|
2026 |
* @param int|WP_Post|null $post Optional. Post ID or WP_Post object. Default is global $post. |
|
2027 |
* @return WP_Post|null Parent post object, or null if there isn't one. |
|
2028 |
*/ |
|
2029 |
function get_post_parent( $post = null ) { |
|
2030 |
$wp_post = get_post( $post ); |
|
2031 |
return ! empty( $wp_post->post_parent ) ? get_post( $wp_post->post_parent ) : null; |
|
2032 |
} |
|
2033 |
||
2034 |
/** |
|
2035 |
* Returns whether the given post has a parent post. |
|
2036 |
* |
|
2037 |
* @since 5.7.0 |
|
2038 |
* |
|
2039 |
* @param int|WP_Post|null $post Optional. Post ID or WP_Post object. Default is global $post. |
|
2040 |
* @return bool Whether the post has a parent post. |
|
2041 |
*/ |
|
2042 |
function has_post_parent( $post = null ) { |
|
2043 |
return (bool) get_post_parent( $post ); |
|
2044 |
} |