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