32 /** |
32 /** |
33 * Displays or retrieves the current post title with optional markup. |
33 * Displays or retrieves the current post title with optional markup. |
34 * |
34 * |
35 * @since 0.71 |
35 * @since 0.71 |
36 * |
36 * |
37 * @param string $before Optional. Markup to prepend to the title. Default empty. |
37 * @param string $before Optional. Markup to prepend to the title. Default empty. |
38 * @param string $after Optional. Markup to append to the title. Default empty. |
38 * @param string $after Optional. Markup to append to the title. Default empty. |
39 * @param bool $echo Optional. Whether to echo or return the title. Default true for echo. |
39 * @param bool $display Optional. Whether to echo or return the title. Default true for echo. |
40 * @return void|string Void if `$echo` argument is true, current post title if `$echo` is false. |
40 * @return void|string Void if `$display` argument is true or the title is empty, |
41 */ |
41 * current post title if `$display` is false. |
42 function the_title( $before = '', $after = '', $echo = true ) { |
42 */ |
|
43 function the_title( $before = '', $after = '', $display = true ) { |
43 $title = get_the_title(); |
44 $title = get_the_title(); |
44 |
45 |
45 if ( strlen( $title ) == 0 ) { |
46 if ( strlen( $title ) === 0 ) { |
46 return; |
47 return; |
47 } |
48 } |
48 |
49 |
49 $title = $before . $title . $after; |
50 $title = $before . $title . $after; |
50 |
51 |
51 if ( $echo ) { |
52 if ( $display ) { |
52 echo $title; |
53 echo $title; |
53 } else { |
54 } else { |
54 return $title; |
55 return $title; |
55 } |
56 } |
56 } |
57 } |
136 * @param string $prepend Text displayed before the post title. |
137 * @param string $prepend Text displayed before the post title. |
137 * Default 'Protected: %s'. |
138 * Default 'Protected: %s'. |
138 * @param WP_Post $post Current post object. |
139 * @param WP_Post $post Current post object. |
139 */ |
140 */ |
140 $protected_title_format = apply_filters( 'protected_title_format', $prepend, $post ); |
141 $protected_title_format = apply_filters( 'protected_title_format', $prepend, $post ); |
141 $title = sprintf( $protected_title_format, $title ); |
142 |
|
143 $post_title = sprintf( $protected_title_format, $post_title ); |
142 } elseif ( isset( $post->post_status ) && 'private' === $post->post_status ) { |
144 } elseif ( isset( $post->post_status ) && 'private' === $post->post_status ) { |
143 |
145 |
144 /* translators: %s: Private post title. */ |
146 /* translators: %s: Private post title. */ |
145 $prepend = __( 'Private: %s' ); |
147 $prepend = __( 'Private: %s' ); |
146 |
148 |
154 * @param string $prepend Text displayed before the post title. |
156 * @param string $prepend Text displayed before the post title. |
155 * Default 'Private: %s'. |
157 * Default 'Private: %s'. |
156 * @param WP_Post $post Current post object. |
158 * @param WP_Post $post Current post object. |
157 */ |
159 */ |
158 $private_title_format = apply_filters( 'private_title_format', $prepend, $post ); |
160 $private_title_format = apply_filters( 'private_title_format', $prepend, $post ); |
159 $title = sprintf( $private_title_format, $title ); |
161 |
|
162 $post_title = sprintf( $private_title_format, $post_title ); |
160 } |
163 } |
161 } |
164 } |
162 |
165 |
163 /** |
166 /** |
164 * Filters the post title. |
167 * Filters the post title. |
165 * |
168 * |
166 * @since 0.71 |
169 * @since 0.71 |
167 * |
170 * |
168 * @param string $title The post title. |
171 * @param string $post_title The post title. |
169 * @param int $id The post ID. |
172 * @param int $post_id The post ID. |
170 */ |
173 */ |
171 return apply_filters( 'the_title', $title, $id ); |
174 return apply_filters( 'the_title', $post_title, $post_id ); |
172 } |
175 } |
173 |
176 |
174 /** |
177 /** |
175 * Displays the Post Global Unique Identifier (guid). |
178 * Displays the Post Global Unique Identifier (guid). |
176 * |
179 * |
185 * @param int|WP_Post $post Optional. Post ID or post object. Default is global $post. |
188 * @param int|WP_Post $post Optional. Post ID or post object. Default is global $post. |
186 */ |
189 */ |
187 function the_guid( $post = 0 ) { |
190 function the_guid( $post = 0 ) { |
188 $post = get_post( $post ); |
191 $post = get_post( $post ); |
189 |
192 |
190 $guid = isset( $post->guid ) ? get_the_guid( $post ) : ''; |
193 $post_guid = isset( $post->guid ) ? get_the_guid( $post ) : ''; |
191 $id = isset( $post->ID ) ? $post->ID : 0; |
194 $post_id = isset( $post->ID ) ? $post->ID : 0; |
192 |
195 |
193 /** |
196 /** |
194 * Filters the escaped Global Unique Identifier (guid) of the post. |
197 * Filters the escaped Global Unique Identifier (guid) of the post. |
195 * |
198 * |
196 * @since 4.2.0 |
199 * @since 4.2.0 |
197 * |
200 * |
198 * @see get_the_guid() |
201 * @see get_the_guid() |
199 * |
202 * |
200 * @param string $guid Escaped Global Unique Identifier (guid) of the post. |
203 * @param string $post_guid Escaped Global Unique Identifier (guid) of the post. |
201 * @param int $id The post ID. |
204 * @param int $post_id The post ID. |
202 */ |
205 */ |
203 echo apply_filters( 'the_guid', $guid, $id ); |
206 echo apply_filters( 'the_guid', $post_guid, $post_id ); |
204 } |
207 } |
205 |
208 |
206 /** |
209 /** |
207 * Retrieves the Post Global Unique Identifier (guid). |
210 * Retrieves the Post Global Unique Identifier (guid). |
208 * |
211 * |
216 * @return string |
219 * @return string |
217 */ |
220 */ |
218 function get_the_guid( $post = 0 ) { |
221 function get_the_guid( $post = 0 ) { |
219 $post = get_post( $post ); |
222 $post = get_post( $post ); |
220 |
223 |
221 $guid = isset( $post->guid ) ? $post->guid : ''; |
224 $post_guid = isset( $post->guid ) ? $post->guid : ''; |
222 $id = isset( $post->ID ) ? $post->ID : 0; |
225 $post_id = isset( $post->ID ) ? $post->ID : 0; |
223 |
226 |
224 /** |
227 /** |
225 * Filters the Global Unique Identifier (guid) of the post. |
228 * Filters the Global Unique Identifier (guid) of the post. |
226 * |
229 * |
227 * @since 1.5.0 |
230 * @since 1.5.0 |
228 * |
231 * |
229 * @param string $guid Global Unique Identifier (guid) of the post. |
232 * @param string $post_guid Global Unique Identifier (guid) of the post. |
230 * @param int $id The post ID. |
233 * @param int $post_id The post ID. |
231 */ |
234 */ |
232 return apply_filters( 'get_the_guid', $guid, $id ); |
235 return apply_filters( 'get_the_guid', $post_guid, $post_id ); |
233 } |
236 } |
234 |
237 |
235 /** |
238 /** |
236 * Displays the post content. |
239 * Displays the post content. |
237 * |
240 * |
280 |
283 |
281 if ( ! ( $_post instanceof WP_Post ) ) { |
284 if ( ! ( $_post instanceof WP_Post ) ) { |
282 return ''; |
285 return ''; |
283 } |
286 } |
284 |
287 |
285 // Use the globals if the $post parameter was not specified, |
288 /* |
286 // but only after they have been set up in setup_postdata(). |
289 * Use the globals if the $post parameter was not specified, |
|
290 * but only after they have been set up in setup_postdata(). |
|
291 */ |
287 if ( null === $post && did_action( 'the_post' ) ) { |
292 if ( null === $post && did_action( 'the_post' ) ) { |
288 $elements = compact( 'page', 'more', 'preview', 'pages', 'multipage' ); |
293 $elements = compact( 'page', 'more', 'preview', 'pages', 'multipage' ); |
289 } else { |
294 } else { |
290 $elements = generate_postdata( $_post ); |
295 $elements = generate_postdata( $_post ); |
291 } |
296 } |
449 /** |
456 /** |
450 * Displays the classes for the post container element. |
457 * Displays the classes for the post container element. |
451 * |
458 * |
452 * @since 2.7.0 |
459 * @since 2.7.0 |
453 * |
460 * |
454 * @param string|string[] $class One or more classes to add to the class list. |
461 * @param string|string[] $css_class Optional. One or more classes to add to the class list. |
455 * @param int|WP_Post $post_id Optional. Post ID or post object. Defaults to the global `$post`. |
462 * Default empty. |
456 */ |
463 * @param int|WP_Post $post Optional. Post ID or post object. Defaults to the global `$post`. |
457 function post_class( $class = '', $post_id = null ) { |
464 */ |
|
465 function post_class( $css_class = '', $post = null ) { |
458 // Separates classes with a single space, collates classes for post DIV. |
466 // Separates classes with a single space, collates classes for post DIV. |
459 echo 'class="' . esc_attr( implode( ' ', get_post_class( $class, $post_id ) ) ) . '"'; |
467 echo 'class="' . esc_attr( implode( ' ', get_post_class( $css_class, $post ) ) ) . '"'; |
460 } |
468 } |
461 |
469 |
462 /** |
470 /** |
463 * Retrieves an array of the class names for the post container element. |
471 * Retrieves an array of the class names for the post container element. |
464 * |
472 * |
465 * The class names are many. If the post is a sticky, then the 'sticky' |
473 * The class names are many: |
466 * class name. The class 'hentry' is always added to each post. If the post has a |
474 * |
467 * post thumbnail, 'has-post-thumbnail' is added as a class. For each taxonomy that |
475 * - If the post has a post thumbnail, `has-post-thumbnail` is added as a class. |
468 * the post belongs to, a class will be added of the format '{$taxonomy}-{$slug}' - |
476 * - If the post is sticky, then the `sticky` class name is added. |
469 * eg 'category-foo' or 'my_custom_taxonomy-bar'. |
477 * - The class `hentry` is always added to each post. |
470 * |
478 * - For each taxonomy that the post belongs to, a class will be added of the format |
471 * The 'post_tag' taxonomy is a special |
479 * `{$taxonomy}-{$slug}`, e.g. `category-foo` or `my_custom_taxonomy-bar`. |
472 * case; the class has the 'tag-' prefix instead of 'post_tag-'. All class names are |
480 * The `post_tag` taxonomy is a special case; the class has the `tag-` prefix |
473 * passed through the filter, {@see 'post_class'}, with the list of class names, followed by |
481 * instead of `post_tag-`. |
474 * $class parameter value, with the post ID as the last parameter. |
482 * |
|
483 * All class names are passed through the filter, {@see 'post_class'}, followed by |
|
484 * `$css_class` parameter value, with the post ID as the last parameter. |
475 * |
485 * |
476 * @since 2.7.0 |
486 * @since 2.7.0 |
477 * @since 4.2.0 Custom taxonomy class names were added. |
487 * @since 4.2.0 Custom taxonomy class names were added. |
478 * |
488 * |
479 * @param string|string[] $class Space-separated string or array of class names to add to the class list. |
489 * @param string|string[] $css_class Optional. Space-separated string or array of class names |
480 * @param int|WP_Post $post_id Optional. Post ID or post object. |
490 * to add to the class list. Default empty. |
|
491 * @param int|WP_Post $post Optional. Post ID or post object. |
481 * @return string[] Array of class names. |
492 * @return string[] Array of class names. |
482 */ |
493 */ |
483 function get_post_class( $class = '', $post_id = null ) { |
494 function get_post_class( $css_class = '', $post = null ) { |
484 $post = get_post( $post_id ); |
495 $post = get_post( $post ); |
485 |
496 |
486 $classes = array(); |
497 $classes = array(); |
487 |
498 |
488 if ( $class ) { |
499 if ( $css_class ) { |
489 if ( ! is_array( $class ) ) { |
500 if ( ! is_array( $css_class ) ) { |
490 $class = preg_split( '#\s+#', $class ); |
501 $css_class = preg_split( '#\s+#', $css_class ); |
491 } |
502 } |
492 $classes = array_map( 'esc_attr', $class ); |
503 $classes = array_map( 'esc_attr', $css_class ); |
493 } else { |
504 } else { |
494 // Ensure that we always coerce class to being an array. |
505 // Ensure that we always coerce class to being an array. |
495 $class = array(); |
506 $css_class = array(); |
496 } |
507 } |
497 |
508 |
498 if ( ! $post ) { |
509 if ( ! $post ) { |
499 return $classes; |
510 return $classes; |
500 } |
511 } |
543 // hentry for hAtom compliance. |
554 // hentry for hAtom compliance. |
544 $classes[] = 'hentry'; |
555 $classes[] = 'hentry'; |
545 |
556 |
546 // All public taxonomies. |
557 // All public taxonomies. |
547 $taxonomies = get_taxonomies( array( 'public' => true ) ); |
558 $taxonomies = get_taxonomies( array( 'public' => true ) ); |
|
559 |
|
560 /** |
|
561 * Filters the taxonomies to generate classes for each individual term. |
|
562 * |
|
563 * Default is all public taxonomies registered to the post type. |
|
564 * |
|
565 * @since 6.1.0 |
|
566 * |
|
567 * @param string[] $taxonomies List of all taxonomy names to generate classes for. |
|
568 * @param int $post_id The post ID. |
|
569 * @param string[] $classes An array of post class names. |
|
570 * @param string[] $css_class An array of additional class names added to the post. |
|
571 */ |
|
572 $taxonomies = apply_filters( 'post_class_taxonomies', $taxonomies, $post->ID, $classes, $css_class ); |
|
573 |
548 foreach ( (array) $taxonomies as $taxonomy ) { |
574 foreach ( (array) $taxonomies as $taxonomy ) { |
549 if ( is_object_in_taxonomy( $post->post_type, $taxonomy ) ) { |
575 if ( is_object_in_taxonomy( $post->post_type, $taxonomy ) ) { |
550 foreach ( (array) get_the_terms( $post->ID, $taxonomy ) as $term ) { |
576 foreach ( (array) get_the_terms( $post->ID, $taxonomy ) as $term ) { |
551 if ( empty( $term->slug ) ) { |
577 if ( empty( $term->slug ) ) { |
552 continue; |
578 continue; |
572 /** |
598 /** |
573 * Filters the list of CSS class names for the current post. |
599 * Filters the list of CSS class names for the current post. |
574 * |
600 * |
575 * @since 2.7.0 |
601 * @since 2.7.0 |
576 * |
602 * |
577 * @param string[] $classes An array of post class names. |
603 * @param string[] $classes An array of post class names. |
578 * @param string[] $class An array of additional class names added to the post. |
604 * @param string[] $css_class An array of additional class names added to the post. |
579 * @param int $post_id The post ID. |
605 * @param int $post_id The post ID. |
580 */ |
606 */ |
581 $classes = apply_filters( 'post_class', $classes, $class, $post->ID ); |
607 $classes = apply_filters( 'post_class', $classes, $css_class, $post->ID ); |
582 |
608 |
583 return array_unique( $classes ); |
609 return array_unique( $classes ); |
584 } |
610 } |
585 |
611 |
586 /** |
612 /** |
587 * Displays the class names for the body element. |
613 * Displays the class names for the body element. |
588 * |
614 * |
589 * @since 2.8.0 |
615 * @since 2.8.0 |
590 * |
616 * |
591 * @param string|string[] $class Space-separated string or array of class names to add to the class list. |
617 * @param string|string[] $css_class Optional. Space-separated string or array of class names |
592 */ |
618 * to add to the class list. Default empty. |
593 function body_class( $class = '' ) { |
619 */ |
|
620 function body_class( $css_class = '' ) { |
594 // Separates class names with a single space, collates class names for body element. |
621 // Separates class names with a single space, collates class names for body element. |
595 echo 'class="' . esc_attr( implode( ' ', get_body_class( $class ) ) ) . '"'; |
622 echo 'class="' . esc_attr( implode( ' ', get_body_class( $css_class ) ) ) . '"'; |
596 } |
623 } |
597 |
624 |
598 /** |
625 /** |
599 * Retrieves an array of the class names for the body element. |
626 * Retrieves an array of the class names for the body element. |
600 * |
627 * |
601 * @since 2.8.0 |
628 * @since 2.8.0 |
602 * |
629 * |
603 * @global WP_Query $wp_query WordPress Query object. |
630 * @global WP_Query $wp_query WordPress Query object. |
604 * |
631 * |
605 * @param string|string[] $class Space-separated string or array of class names to add to the class list. |
632 * @param string|string[] $css_class Optional. Space-separated string or array of class names |
|
633 * to add to the class list. Default empty. |
606 * @return string[] Array of class names. |
634 * @return string[] Array of class names. |
607 */ |
635 */ |
608 function get_body_class( $class = '' ) { |
636 function get_body_class( $css_class = '' ) { |
609 global $wp_query; |
637 global $wp_query; |
610 |
638 |
611 $classes = array(); |
639 $classes = array(); |
612 |
640 |
613 if ( is_rtl() ) { |
641 if ( is_rtl() ) { |
686 $mime_prefix = array( 'application/', 'image/', 'text/', 'audio/', 'video/', 'music/' ); |
714 $mime_prefix = array( 'application/', 'image/', 'text/', 'audio/', 'video/', 'music/' ); |
687 $classes[] = 'attachmentid-' . $post_id; |
715 $classes[] = 'attachmentid-' . $post_id; |
688 $classes[] = 'attachment-' . str_replace( $mime_prefix, '', $mime_type ); |
716 $classes[] = 'attachment-' . str_replace( $mime_prefix, '', $mime_type ); |
689 } elseif ( is_page() ) { |
717 } elseif ( is_page() ) { |
690 $classes[] = 'page'; |
718 $classes[] = 'page'; |
691 |
719 $classes[] = 'page-id-' . $post_id; |
692 $page_id = $wp_query->get_queried_object_id(); |
|
693 |
|
694 $post = get_post( $page_id ); |
|
695 |
|
696 $classes[] = 'page-id-' . $page_id; |
|
697 |
720 |
698 if ( get_pages( |
721 if ( get_pages( |
699 array( |
722 array( |
700 'parent' => $page_id, |
723 'parent' => $post_id, |
701 'number' => 1, |
724 'number' => 1, |
702 ) |
725 ) |
703 ) ) { |
726 ) ) { |
704 $classes[] = 'page-parent'; |
727 $classes[] = 'page-parent'; |
705 } |
728 } |
811 } elseif ( is_post_type_archive() ) { |
834 } elseif ( is_post_type_archive() ) { |
812 $classes[] = 'post-type-paged-' . $page; |
835 $classes[] = 'post-type-paged-' . $page; |
813 } |
836 } |
814 } |
837 } |
815 |
838 |
816 if ( ! empty( $class ) ) { |
839 if ( ! empty( $css_class ) ) { |
817 if ( ! is_array( $class ) ) { |
840 if ( ! is_array( $css_class ) ) { |
818 $class = preg_split( '#\s+#', $class ); |
841 $css_class = preg_split( '#\s+#', $css_class ); |
819 } |
842 } |
820 $classes = array_merge( $classes, $class ); |
843 $classes = array_merge( $classes, $css_class ); |
821 } else { |
844 } else { |
822 // Ensure that we always coerce class to being an array. |
845 // Ensure that we always coerce class to being an array. |
823 $class = array(); |
846 $css_class = array(); |
824 } |
847 } |
825 |
848 |
826 $classes = array_map( 'esc_attr', $classes ); |
849 $classes = array_map( 'esc_attr', $classes ); |
827 |
850 |
828 /** |
851 /** |
829 * Filters the list of CSS body class names for the current post or page. |
852 * Filters the list of CSS body class names for the current post or page. |
830 * |
853 * |
831 * @since 2.8.0 |
854 * @since 2.8.0 |
832 * |
855 * |
833 * @param string[] $classes An array of body class names. |
856 * @param string[] $classes An array of body class names. |
834 * @param string[] $class An array of additional class names added to the body. |
857 * @param string[] $css_class An array of additional class names added to the body. |
835 */ |
858 */ |
836 $classes = apply_filters( 'body_class', $classes, $class ); |
859 $classes = apply_filters( 'body_class', $classes, $css_class ); |
837 |
860 |
838 return array_unique( $classes ); |
861 return array_unique( $classes ); |
839 } |
862 } |
840 |
863 |
841 /** |
864 /** |
955 if ( $multipage ) { |
978 if ( $multipage ) { |
956 if ( 'number' === $parsed_args['next_or_number'] ) { |
979 if ( 'number' === $parsed_args['next_or_number'] ) { |
957 $output .= $parsed_args['before']; |
980 $output .= $parsed_args['before']; |
958 for ( $i = 1; $i <= $numpages; $i++ ) { |
981 for ( $i = 1; $i <= $numpages; $i++ ) { |
959 $link = $parsed_args['link_before'] . str_replace( '%', $i, $parsed_args['pagelink'] ) . $parsed_args['link_after']; |
982 $link = $parsed_args['link_before'] . str_replace( '%', $i, $parsed_args['pagelink'] ) . $parsed_args['link_after']; |
960 if ( $i != $page || ! $more && 1 == $page ) { |
983 |
|
984 if ( $i !== $page || ! $more && 1 === $page ) { |
961 $link = _wp_link_page( $i ) . $link . '</a>'; |
985 $link = _wp_link_page( $i ) . $link . '</a>'; |
962 } elseif ( $i === $page ) { |
986 } elseif ( $i === $page ) { |
963 $link = '<span class="post-page-numbers current" aria-current="' . esc_attr( $parsed_args['aria_current'] ) . '">' . $link . '</span>'; |
987 $link = '<span class="post-page-numbers current" aria-current="' . esc_attr( $parsed_args['aria_current'] ) . '">' . $link . '</span>'; |
964 } |
988 } |
|
989 |
965 /** |
990 /** |
966 * Filters the HTML output of individual page number links. |
991 * Filters the HTML output of individual page number links. |
967 * |
992 * |
968 * @since 3.6.0 |
993 * @since 3.6.0 |
969 * |
994 * |
1031 function _wp_link_page( $i ) { |
1056 function _wp_link_page( $i ) { |
1032 global $wp_rewrite; |
1057 global $wp_rewrite; |
1033 $post = get_post(); |
1058 $post = get_post(); |
1034 $query_args = array(); |
1059 $query_args = array(); |
1035 |
1060 |
1036 if ( 1 == $i ) { |
1061 if ( 1 === $i ) { |
1037 $url = get_permalink(); |
1062 $url = get_permalink(); |
1038 } else { |
1063 } else { |
1039 if ( ! get_option( 'permalink_structure' ) || in_array( $post->post_status, array( 'draft', 'pending' ), true ) ) { |
1064 if ( ! get_option( 'permalink_structure' ) || in_array( $post->post_status, array( 'draft', 'pending' ), true ) ) { |
1040 $url = add_query_arg( 'page', $i, get_permalink() ); |
1065 $url = add_query_arg( 'page', $i, get_permalink() ); |
1041 } elseif ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $post->ID ) { |
1066 } elseif ( 'page' === get_option( 'show_on_front' ) && (int) get_option( 'page_on_front' ) === $post->ID ) { |
1042 $url = trailingslashit( get_permalink() ) . user_trailingslashit( "$wp_rewrite->pagination_base/" . $i, 'single_paged' ); |
1067 $url = trailingslashit( get_permalink() ) . user_trailingslashit( "$wp_rewrite->pagination_base/" . $i, 'single_paged' ); |
1043 } else { |
1068 } else { |
1044 $url = trailingslashit( get_permalink() ) . user_trailingslashit( $i, 'single_paged' ); |
1069 $url = trailingslashit( get_permalink() ) . user_trailingslashit( $i, 'single_paged' ); |
1045 } |
1070 } |
1046 } |
1071 } |
1141 * @since 4.3.0 The `$class` argument was added. |
1166 * @since 4.3.0 The `$class` argument was added. |
1142 * |
1167 * |
1143 * @see get_pages() |
1168 * @see get_pages() |
1144 * |
1169 * |
1145 * @param array|string $args { |
1170 * @param array|string $args { |
1146 * Optional. Array or string of arguments to generate a page dropdown. See `get_pages()` for additional arguments. |
1171 * Optional. Array or string of arguments to generate a page dropdown. See get_pages() for additional arguments. |
1147 * |
1172 * |
1148 * @type int $depth Maximum depth. Default 0. |
1173 * @type int $depth Maximum depth. Default 0. |
1149 * @type int $child_of Page ID to retrieve child pages of. Default 0. |
1174 * @type int $child_of Page ID to retrieve child pages of. Default 0. |
1150 * @type int|string $selected Value of the option that should be selected. Default 0. |
1175 * @type int|string $selected Value of the option that should be selected. Default 0. |
1151 * @type bool|int $echo Whether to echo or return the generated markup. Accepts 0, 1, |
1176 * @type bool|int $echo Whether to echo or return the generated markup. Accepts 0, 1, |
1203 $output .= walk_page_dropdown_tree( $pages, $parsed_args['depth'], $parsed_args ); |
1228 $output .= walk_page_dropdown_tree( $pages, $parsed_args['depth'], $parsed_args ); |
1204 $output .= "</select>\n"; |
1229 $output .= "</select>\n"; |
1205 } |
1230 } |
1206 |
1231 |
1207 /** |
1232 /** |
1208 * Filters the HTML output of a list of pages as a drop down. |
1233 * Filters the HTML output of a list of pages as a dropdown. |
1209 * |
1234 * |
1210 * @since 2.1.0 |
1235 * @since 2.1.0 |
1211 * @since 4.4.0 `$parsed_args` and `$pages` added as arguments. |
1236 * @since 4.4.0 `$parsed_args` and `$pages` added as arguments. |
1212 * |
1237 * |
1213 * @param string $output HTML output for drop down list of pages. |
1238 * @param string $output HTML output for dropdown list of pages. |
1214 * @param array $parsed_args The parsed arguments array. See wp_dropdown_pages() |
1239 * @param array $parsed_args The parsed arguments array. See wp_dropdown_pages() |
1215 * for information on accepted arguments. |
1240 * for information on accepted arguments. |
1216 * @param WP_Post[] $pages Array of the page objects. |
1241 * @param WP_Post[] $pages Array of the page objects. |
1217 */ |
1242 */ |
1218 $html = apply_filters( 'wp_dropdown_pages', $output, $parsed_args, $pages ); |
1243 $html = apply_filters( 'wp_dropdown_pages', $output, $parsed_args, $pages ); |
1233 * @see get_pages() |
1258 * @see get_pages() |
1234 * |
1259 * |
1235 * @global WP_Query $wp_query WordPress Query object. |
1260 * @global WP_Query $wp_query WordPress Query object. |
1236 * |
1261 * |
1237 * @param array|string $args { |
1262 * @param array|string $args { |
1238 * Optional. Array or string of arguments to generate a list of pages. See `get_pages()` for additional arguments. |
1263 * Optional. Array or string of arguments to generate a list of pages. See get_pages() for additional arguments. |
1239 * |
1264 * |
1240 * @type int $child_of Display only the sub-pages of a single page by ID. Default 0 (all pages). |
1265 * @type int $child_of Display only the sub-pages of a single page by ID. Default 0 (all pages). |
1241 * @type string $authors Comma-separated list of author IDs. Default empty (all authors). |
1266 * @type string $authors Comma-separated list of author IDs. Default empty (all authors). |
1242 * @type string $date_format PHP date format to use for the listed pages. Relies on the 'show_date' parameter. |
1267 * @type string $date_format PHP date format to use for the listed pages. Relies on the 'show_date' parameter. |
1243 * Default is the value of 'date_format' option. |
1268 * Default is the value of 'date_format' option. |
1364 * @since 2.7.0 |
1389 * @since 2.7.0 |
1365 * @since 4.4.0 Added `menu_id`, `container`, `before`, `after`, and `walker` arguments. |
1390 * @since 4.4.0 Added `menu_id`, `container`, `before`, `after`, and `walker` arguments. |
1366 * @since 4.7.0 Added the `item_spacing` argument. |
1391 * @since 4.7.0 Added the `item_spacing` argument. |
1367 * |
1392 * |
1368 * @param array|string $args { |
1393 * @param array|string $args { |
1369 * Optional. Array or string of arguments to generate a page menu. See `wp_list_pages()` for additional arguments. |
1394 * Optional. Array or string of arguments to generate a page menu. See wp_list_pages() for additional arguments. |
1370 * |
1395 * |
1371 * @type string $sort_column How to sort the list of pages. Accepts post column names. |
1396 * @type string $sort_column How to sort the list of pages. Accepts post column names. |
1372 * Default 'menu_order, post_title'. |
1397 * Default 'menu_order, post_title'. |
1373 * @type string $menu_id ID for the div containing the page list. Default is empty string. |
1398 * @type string $menu_id ID for the div containing the page list. Default is empty string. |
1374 * @type string $menu_class Class to use for the element containing the page list. Default 'menu'. |
1399 * @type string $menu_class Class to use for the element containing the page list. Default 'menu'. |
1442 } |
1467 } |
1443 $class = ''; |
1468 $class = ''; |
1444 if ( is_front_page() && ! is_paged() ) { |
1469 if ( is_front_page() && ! is_paged() ) { |
1445 $class = 'class="current_page_item"'; |
1470 $class = 'class="current_page_item"'; |
1446 } |
1471 } |
1447 $menu .= '<li ' . $class . '><a href="' . home_url( '/' ) . '">' . $args['link_before'] . $text . $args['link_after'] . '</a></li>'; |
1472 $menu .= '<li ' . $class . '><a href="' . esc_url( home_url( '/' ) ) . '">' . $args['link_before'] . $text . $args['link_after'] . '</a></li>'; |
1448 // If the front page is a page, add it to the exclude list. |
1473 // If the front page is a page, add it to the exclude list. |
1449 if ( 'page' === get_option( 'show_on_front' ) ) { |
1474 if ( 'page' === get_option( 'show_on_front' ) ) { |
1450 if ( ! empty( $list_args['exclude'] ) ) { |
1475 if ( ! empty( $list_args['exclude'] ) ) { |
1451 $list_args['exclude'] .= ','; |
1476 $list_args['exclude'] .= ','; |
1452 } else { |
1477 } else { |
1579 /** |
1604 /** |
1580 * Displays an attachment page link using an image or icon. |
1605 * Displays an attachment page link using an image or icon. |
1581 * |
1606 * |
1582 * @since 2.0.0 |
1607 * @since 2.0.0 |
1583 * |
1608 * |
1584 * @param int|WP_Post $id Optional. Post ID or post object. |
1609 * @param int|WP_Post $post Optional. Post ID or post object. |
1585 * @param bool $fullsize Optional. Whether to use full size. Default false. |
1610 * @param bool $fullsize Optional. Whether to use full size. Default false. |
1586 * @param bool $deprecated Deprecated. Not used. |
1611 * @param bool $deprecated Deprecated. Not used. |
1587 * @param bool $permalink Optional. Whether to include permalink. Default false. |
1612 * @param bool $permalink Optional. Whether to include permalink. Default false. |
1588 */ |
1613 */ |
1589 function the_attachment_link( $id = 0, $fullsize = false, $deprecated = false, $permalink = false ) { |
1614 function the_attachment_link( $post = 0, $fullsize = false, $deprecated = false, $permalink = false ) { |
1590 if ( ! empty( $deprecated ) ) { |
1615 if ( ! empty( $deprecated ) ) { |
1591 _deprecated_argument( __FUNCTION__, '2.5.0' ); |
1616 _deprecated_argument( __FUNCTION__, '2.5.0' ); |
1592 } |
1617 } |
1593 |
1618 |
1594 if ( $fullsize ) { |
1619 if ( $fullsize ) { |
1595 echo wp_get_attachment_link( $id, 'full', $permalink ); |
1620 echo wp_get_attachment_link( $post, 'full', $permalink ); |
1596 } else { |
1621 } else { |
1597 echo wp_get_attachment_link( $id, 'thumbnail', $permalink ); |
1622 echo wp_get_attachment_link( $post, 'thumbnail', $permalink ); |
1598 } |
1623 } |
1599 } |
1624 } |
1600 |
1625 |
1601 /** |
1626 /** |
1602 * Retrieves an attachment page link using an image or icon, if possible. |
1627 * Retrieves an attachment page link using an image or icon, if possible. |
1603 * |
1628 * |
1604 * @since 2.5.0 |
1629 * @since 2.5.0 |
1605 * @since 4.4.0 The `$id` parameter can now accept either a post ID or `WP_Post` object. |
1630 * @since 4.4.0 The `$post` parameter can now accept either a post ID or `WP_Post` object. |
1606 * |
1631 * |
1607 * @param int|WP_Post $id Optional. Post ID or post object. |
1632 * @param int|WP_Post $post Optional. Post ID or post object. |
1608 * @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array |
1633 * @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array |
1609 * of width and height values in pixels (in that order). Default 'thumbnail'. |
1634 * of width and height values in pixels (in that order). Default 'thumbnail'. |
1610 * @param bool $permalink Optional. Whether to add permalink to image. Default false. |
1635 * @param bool $permalink Optional. Whether to add permalink to image. Default false. |
1611 * @param bool $icon Optional. Whether the attachment is an icon. Default false. |
1636 * @param bool $icon Optional. Whether the attachment is an icon. Default false. |
1612 * @param string|false $text Optional. Link text to use. Activated by passing a string, false otherwise. |
1637 * @param string|false $text Optional. Link text to use. Activated by passing a string, false otherwise. |
1613 * Default false. |
1638 * Default false. |
1614 * @param array|string $attr Optional. Array or string of attributes. Default empty. |
1639 * @param array|string $attr Optional. Array or string of attributes. Default empty. |
1615 * @return string HTML content. |
1640 * @return string HTML content. |
1616 */ |
1641 */ |
1617 function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '' ) { |
1642 function wp_get_attachment_link( $post = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '' ) { |
1618 $_post = get_post( $id ); |
1643 $_post = get_post( $post ); |
1619 |
1644 |
1620 if ( empty( $_post ) || ( 'attachment' !== $_post->post_type ) || ! wp_get_attachment_url( $_post->ID ) ) { |
1645 if ( empty( $_post ) || ( 'attachment' !== $_post->post_type ) || ! wp_get_attachment_url( $_post->ID ) ) { |
1621 return __( 'Missing Attachment' ); |
1646 return __( 'Missing Attachment' ); |
1622 } |
1647 } |
1623 |
1648 |
1640 } |
1665 } |
1641 |
1666 |
1642 if ( '' === trim( $link_text ) ) { |
1667 if ( '' === trim( $link_text ) ) { |
1643 $link_text = esc_html( pathinfo( get_attached_file( $_post->ID ), PATHINFO_FILENAME ) ); |
1668 $link_text = esc_html( pathinfo( get_attached_file( $_post->ID ), PATHINFO_FILENAME ) ); |
1644 } |
1669 } |
|
1670 |
|
1671 /** |
|
1672 * Filters the list of attachment link attributes. |
|
1673 * |
|
1674 * @since 6.2.0 |
|
1675 * |
|
1676 * @param array $attributes An array of attributes for the link markup, |
|
1677 * keyed on the attribute name. |
|
1678 * @param int $id Post ID. |
|
1679 */ |
|
1680 $attributes = apply_filters( 'wp_get_attachment_link_attributes', array( 'href' => $url ), $_post->ID ); |
|
1681 |
|
1682 $link_attributes = ''; |
|
1683 foreach ( $attributes as $name => $value ) { |
|
1684 $value = 'href' === $name ? esc_url( $value ) : esc_attr( $value ); |
|
1685 $link_attributes .= ' ' . esc_attr( $name ) . "='" . $value . "'"; |
|
1686 } |
|
1687 |
|
1688 $link_html = "<a$link_attributes>$link_text</a>"; |
|
1689 |
1645 /** |
1690 /** |
1646 * Filters a retrieved attachment page link. |
1691 * Filters a retrieved attachment page link. |
1647 * |
1692 * |
1648 * @since 2.7.0 |
1693 * @since 2.7.0 |
1649 * @since 5.1.0 Added the `$attr` parameter. |
1694 * @since 5.1.0 Added the `$attr` parameter. |
1650 * |
1695 * |
1651 * @param string $link_html The page link HTML output. |
1696 * @param string $link_html The page link HTML output. |
1652 * @param int|WP_Post $id Post ID or object. Can be 0 for the current global post. |
1697 * @param int|WP_Post $post Post ID or object. Can be 0 for the current global post. |
1653 * @param string|int[] $size Requested image size. Can be any registered image size name, or |
1698 * @param string|int[] $size Requested image size. Can be any registered image size name, or |
1654 * an array of width and height values in pixels (in that order). |
1699 * an array of width and height values in pixels (in that order). |
1655 * @param bool $permalink Whether to add permalink to image. Default false. |
1700 * @param bool $permalink Whether to add permalink to image. Default false. |
1656 * @param bool $icon Whether to include an icon. |
1701 * @param bool $icon Whether to include an icon. |
1657 * @param string|false $text If string, will be link text. |
1702 * @param string|false $text If string, will be link text. |
1658 * @param array|string $attr Array or string of attributes. |
1703 * @param array|string $attr Array or string of attributes. |
1659 */ |
1704 */ |
1660 return apply_filters( 'wp_get_attachment_link', "<a href='" . esc_url( $url ) . "'>$link_text</a>", $id, $size, $permalink, $icon, $text, $attr ); |
1705 return apply_filters( 'wp_get_attachment_link', $link_html, $post, $size, $permalink, $icon, $text, $attr ); |
1661 } |
1706 } |
1662 |
1707 |
1663 /** |
1708 /** |
1664 * Wraps attachment in paragraph tag before content. |
1709 * Wraps attachment in paragraph tag before content. |
1665 * |
1710 * |
1724 function get_the_password_form( $post = 0 ) { |
1769 function get_the_password_form( $post = 0 ) { |
1725 $post = get_post( $post ); |
1770 $post = get_post( $post ); |
1726 $label = 'pwbox-' . ( empty( $post->ID ) ? rand() : $post->ID ); |
1771 $label = 'pwbox-' . ( empty( $post->ID ) ? rand() : $post->ID ); |
1727 $output = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" class="post-password-form" method="post"> |
1772 $output = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" class="post-password-form" method="post"> |
1728 <p>' . __( 'This content is password protected. To view it please enter your password below:' ) . '</p> |
1773 <p>' . __( 'This content is password protected. To view it please enter your password below:' ) . '</p> |
1729 <p><label for="' . $label . '">' . __( 'Password:' ) . ' <input name="post_password" id="' . $label . '" type="password" size="20" /></label> <input type="submit" name="Submit" value="' . esc_attr_x( 'Enter', 'post password form' ) . '" /></p></form> |
1774 <p><label for="' . $label . '">' . __( 'Password:' ) . ' <input name="post_password" id="' . $label . '" type="password" spellcheck="false" size="20" /></label> <input type="submit" name="Submit" value="' . esc_attr_x( 'Enter', 'post password form' ) . '" /></p></form> |
1730 '; |
1775 '; |
1731 |
1776 |
1732 /** |
1777 /** |
1733 * Filters the HTML output for the protected post password form. |
1778 * Filters the HTML output for the protected post password form. |
1734 * |
1779 * |
1818 /** |
1863 /** |
1819 * Retrieves formatted date timestamp of a revision (linked to that revisions's page). |
1864 * Retrieves formatted date timestamp of a revision (linked to that revisions's page). |
1820 * |
1865 * |
1821 * @since 2.6.0 |
1866 * @since 2.6.0 |
1822 * |
1867 * |
1823 * @param int|object $revision Revision ID or revision object. |
1868 * @param int|WP_Post $revision Revision ID or revision object. |
1824 * @param bool $link Optional. Whether to link to revision's page. Default true. |
1869 * @param bool $link Optional. Whether to link to revision's page. Default true. |
1825 * @return string|false i18n formatted datetimestamp or localized 'Current Revision'. |
1870 * @return string|false i18n formatted datetimestamp or localized 'Current Revision'. |
1826 */ |
1871 */ |
1827 function wp_post_revision_title( $revision, $link = true ) { |
1872 function wp_post_revision_title( $revision, $link = true ) { |
1828 $revision = get_post( $revision ); |
1873 $revision = get_post( $revision ); |
|
1874 |
1829 if ( ! $revision ) { |
1875 if ( ! $revision ) { |
1830 return $revision; |
1876 return $revision; |
1831 } |
1877 } |
1832 |
1878 |
1833 if ( ! in_array( $revision->post_type, array( 'post', 'page', 'revision' ), true ) ) { |
1879 if ( ! in_array( $revision->post_type, array( 'post', 'page', 'revision' ), true ) ) { |
1859 /** |
1905 /** |
1860 * Retrieves formatted date timestamp of a revision (linked to that revisions's page). |
1906 * Retrieves formatted date timestamp of a revision (linked to that revisions's page). |
1861 * |
1907 * |
1862 * @since 3.6.0 |
1908 * @since 3.6.0 |
1863 * |
1909 * |
1864 * @param int|object $revision Revision ID or revision object. |
1910 * @param int|WP_Post $revision Revision ID or revision object. |
1865 * @param bool $link Optional. Whether to link to revision's page. Default true. |
1911 * @param bool $link Optional. Whether to link to revision's page. Default true. |
1866 * @return string|false gravatar, user, i18n formatted datetimestamp or localized 'Current Revision'. |
1912 * @return string|false gravatar, user, i18n formatted datetimestamp or localized 'Current Revision'. |
1867 */ |
1913 */ |
1868 function wp_post_revision_title_expanded( $revision, $link = true ) { |
1914 function wp_post_revision_title_expanded( $revision, $link = true ) { |
1869 $revision = get_post( $revision ); |
1915 $revision = get_post( $revision ); |
|
1916 |
1870 if ( ! $revision ) { |
1917 if ( ! $revision ) { |
1871 return $revision; |
1918 return $revision; |
1872 } |
1919 } |
1873 |
1920 |
1874 if ( ! in_array( $revision->post_type, array( 'post', 'page', 'revision' ), true ) ) { |
1921 if ( ! in_array( $revision->post_type, array( 'post', 'page', 'revision' ), true ) ) { |
1926 * Can output either a UL with edit links or a TABLE with diff interface, and |
1973 * Can output either a UL with edit links or a TABLE with diff interface, and |
1927 * restore action links. |
1974 * restore action links. |
1928 * |
1975 * |
1929 * @since 2.6.0 |
1976 * @since 2.6.0 |
1930 * |
1977 * |
1931 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post. |
1978 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post. |
1932 * @param string $type 'all' (default), 'revision' or 'autosave' |
1979 * @param string $type 'all' (default), 'revision' or 'autosave' |
1933 */ |
1980 */ |
1934 function wp_list_post_revisions( $post_id = 0, $type = 'all' ) { |
1981 function wp_list_post_revisions( $post = 0, $type = 'all' ) { |
1935 $post = get_post( $post_id ); |
1982 $post = get_post( $post ); |
|
1983 |
1936 if ( ! $post ) { |
1984 if ( ! $post ) { |
1937 return; |
1985 return; |
1938 } |
1986 } |
1939 |
1987 |
1940 // $args array with (parent, format, right, left, type) deprecated since 3.6. |
1988 // $args array with (parent, format, right, left, type) deprecated since 3.6. |