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