42
42
function the_title( $before = '', $after = '', $echo = true ) {
43
43
$title = get_the_title();
45
if ( strlen($title) == 0 )
45
if ( strlen( $title ) == 0 ) {
48
49
$title = $before . $title . $after;
76
78
* @return string|void String when echo is false.
78
80
function the_title_attribute( $args = '' ) {
79
$defaults = array( 'before' => '', 'after' => '', 'echo' => true, 'post' => get_post() );
80
$r = wp_parse_args( $args, $defaults );
87
$r = wp_parse_args( $args, $defaults );
82
89
$title = get_the_title( $r['post'] );
111
118
$post = get_post( $post );
113
120
$title = isset( $post->post_title ) ? $post->post_title : '';
114
$id = isset( $post->ID ) ? $post->ID : 0;
121
$id = isset( $post->ID ) ? $post->ID : 0;
116
123
if ( ! is_admin() ) {
117
124
if ( ! empty( $post->post_password ) ) {
128
135
* @param WP_Post $post Current post object.
130
137
$protected_title_format = apply_filters( 'protected_title_format', __( 'Protected: %s' ), $post );
131
$title = sprintf( $protected_title_format, $title );
138
$title = sprintf( $protected_title_format, $title );
132
139
} elseif ( isset( $post->post_status ) && 'private' == $post->post_status ) {
143
150
* @param WP_Post $post Current post object.
145
152
$private_title_format = apply_filters( 'private_title_format', __( 'Private: %s' ), $post );
146
$title = sprintf( $private_title_format, $title );
153
$title = sprintf( $private_title_format, $title );
227
234
* @param string $more_link_text Optional. Content for when there is more text.
228
235
* @param bool $strip_teaser Optional. Strip teaser content before the more text. Default is false.
230
function the_content( $more_link_text = null, $strip_teaser = false) {
237
function the_content( $more_link_text = null, $strip_teaser = false ) {
231
238
$content = get_the_content( $more_link_text, $strip_teaser );
250
257
* @global int $page Page number of a single post/page.
251
258
* @global int $more Boolean indicator for whether single post/page is being viewed.
252
259
* @global bool $preview Whether post/page is in preview mode.
253
* @global array $pages Array of all pages in post/page. Each array element contains part of the content separated by the <!--nextpage--> tag.
260
* @global array $pages Array of all pages in post/page. Each array element contains
261
* part of the content separated by the `<!--nextpage-->` tag.
254
262
* @global int $multipage Boolean indicator for whether multiple pages are in play.
256
264
* @param string $more_link_text Optional. Content for when there is more text.
278
286
$has_teaser = false;
280
288
// If post password required and it doesn't match the cookie.
281
if ( post_password_required( $post ) )
289
if ( post_password_required( $post ) ) {
282
290
return get_the_password_form( $post );
284
if ( $page > count( $pages ) ) // if the requested page doesn't exist
293
if ( $page > count( $pages ) ) { // if the requested page doesn't exist
285
294
$page = count( $pages ); // give them the highest numbered page that DOES exist
287
$content = $pages[$page - 1];
297
$content = $pages[ $page - 1 ];
288
298
if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) {
289
299
$content = explode( $matches[0], $content, 2 );
290
if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) )
300
if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) ) {
291
301
$more_link_text = strip_tags( wp_kses_no_null( trim( $matches[1] ) ) );
293
304
$has_teaser = true;
295
306
$content = array( $content );
298
if ( false !== strpos( $post->post_content, '<!--noteaser-->' ) && ( ! $multipage || $page == 1 ) )
309
if ( false !== strpos( $post->post_content, '<!--noteaser-->' ) && ( ! $multipage || $page == 1 ) ) {
299
310
$strip_teaser = true;
301
313
$teaser = $content[0];
303
if ( $more && $strip_teaser && $has_teaser )
315
if ( $more && $strip_teaser && $has_teaser ) {
306
319
$output .= $teaser;
320
333
* @param string $more_link_text Read More text.
322
335
$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
337
$output = force_balance_tags( $output );
327
if ( $preview ) // Preview fix for JavaScript bug with foreign languages.
328
$output = preg_replace_callback( '/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output );
341
if ( $preview ) { // Preview fix for JavaScript bug with foreign languages.
342
$output = preg_replace_callback( '/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output );
401
416
* Determines whether the post has a custom excerpt.
403
418
* For more information on this and similar theme functions, check out
404
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
419
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
405
420
* Conditional Tags} article in the Theme Developer Handbook.
412
427
function has_excerpt( $post = 0 ) {
413
428
$post = get_post( $post );
414
return ( !empty( $post->post_excerpt ) );
429
return ( ! empty( $post->post_excerpt ) );
418
* Display the classes for the post div.
433
* Displays the classes for the post container element.
431
* Retrieves the classes for the post div as an array.
446
* Retrieves an array of the class names for the post container element.
433
448
* The class names are many. If the post is a sticky, then the 'sticky'
434
449
* class name. The class 'hentry' is always added to each post. If the post has a
437
452
* eg 'category-foo' or 'my_custom_taxonomy-bar'.
439
454
* The 'post_tag' taxonomy is a special
440
* case; the class has the 'tag-' prefix instead of 'post_tag-'. All classes are
441
* passed through the filter, {@see 'post_class'}, with the list of classes, followed by
455
* case; the class has the 'tag-' prefix instead of 'post_tag-'. All class names are
456
* passed through the filter, {@see 'post_class'}, with the list of class names, followed by
442
457
* $class parameter value, with the post ID as the last parameter.
445
* @since 4.2.0 Custom taxonomy classes were added.
460
* @since 4.2.0 Custom taxonomy class names were added.
447
* @param string|array $class One or more classes to add to the class list.
448
* @param int|WP_Post $post_id Optional. Post ID or post object.
449
* @return array Array of classes.
462
* @param string|string[] $class Space-separated string or array of class names to add to the class list.
463
* @param int|WP_Post $post_id Optional. Post ID or post object.
464
* @return string[] Array of class names.
451
466
function get_post_class( $class = '', $post_id = null ) {
452
467
$post = get_post( $post_id );
477
493
if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
478
494
$post_format = get_post_format( $post->ID );
480
if ( $post_format && !is_wp_error($post_format) )
496
if ( $post_format && ! is_wp_error( $post_format ) ) {
481
497
$classes[] = 'format-' . sanitize_html_class( $post_format );
483
499
$classes[] = 'format-standard';
486
503
$post_password_required = post_password_required( $post->ID );
536
553
$classes = array_map( 'esc_attr', $classes );
539
* Filters the list of CSS classes for the current post.
556
* Filters the list of CSS class names for the current post.
543
* @param array $classes An array of post classes.
544
* @param array $class An array of additional classes added to the post.
545
* @param int $post_id The post ID.
560
* @param string[] $classes An array of post class names.
561
* @param string[] $class An array of additional class names added to the post.
562
* @param int $post_id The post ID.
547
564
$classes = apply_filters( 'post_class', $classes, $class, $post->ID );
553
* Display the classes for the body element.
570
* Displays the class names for the body element.
557
* @param string|array $class One or more classes to add to the class list.
574
* @param string|string[] $class Space-separated string or array of class names to add to the class list.
559
576
function body_class( $class = '' ) {
560
// Separates classes with a single space, collates classes for body element
577
// Separates class names with a single space, collates class names for body element
561
578
echo 'class="' . join( ' ', get_body_class( $class ) ) . '"';
565
* Retrieve the classes for the body element as an array.
582
* Retrieves an array of the class names for the body element.
569
586
* @global WP_Query $wp_query
571
* @param string|array $class One or more classes to add to the class list.
572
* @return array Array of classes.
588
* @param string|string[] $class Space-separated string or array of class names to add to the class list.
589
* @return string[] Array of class names.
574
591
function get_body_class( $class = '' ) {
575
592
global $wp_query;
577
594
$classes = array();
580
597
$classes[] = 'rtl';
582
if ( is_front_page() )
600
if ( is_front_page() ) {
583
601
$classes[] = 'home';
585
604
$classes[] = 'blog';
606
if ( is_archive() ) {
587
607
$classes[] = 'archive';
589
610
$classes[] = 'date';
590
612
if ( is_search() ) {
591
613
$classes[] = 'search';
592
614
$classes[] = $wp_query->posts ? 'search-results' : 'search-no-results';
595
617
$classes[] = 'paged';
596
if ( is_attachment() )
619
if ( is_attachment() ) {
597
620
$classes[] = 'attachment';
599
623
$classes[] = 'error404';
601
626
if ( is_singular() ) {
602
$post_id = $wp_query->get_queried_object_id();
603
$post = $wp_query->get_queried_object();
627
$post_id = $wp_query->get_queried_object_id();
628
$post = $wp_query->get_queried_object();
604
629
$post_type = $post->post_type;
606
631
if ( is_page_template() ) {
627
652
if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
628
653
$post_format = get_post_format( $post->ID );
630
if ( $post_format && !is_wp_error($post_format) )
655
if ( $post_format && ! is_wp_error( $post_format ) ) {
631
656
$classes[] = 'single-format-' . sanitize_html_class( $post_format );
633
658
$classes[] = 'single-format-standard';
638
664
if ( is_attachment() ) {
639
$mime_type = get_post_mime_type($post_id);
665
$mime_type = get_post_mime_type( $post_id );
640
666
$mime_prefix = array( 'application/', 'image/', 'text/', 'audio/', 'video/', 'music/' );
641
$classes[] = 'attachmentid-' . $post_id;
642
$classes[] = 'attachment-' . str_replace( $mime_prefix, '', $mime_type );
667
$classes[] = 'attachmentid-' . $post_id;
668
$classes[] = 'attachment-' . str_replace( $mime_prefix, '', $mime_type );
643
669
} elseif ( is_page() ) {
644
670
$classes[] = 'page';
646
672
$page_id = $wp_query->get_queried_object_id();
648
$post = get_post($page_id);
674
$post = get_post( $page_id );
650
676
$classes[] = 'page-id-' . $page_id;
652
if ( get_pages( array( 'parent' => $page_id, 'number' => 1 ) ) ) {
680
'parent' => $page_id,
653
684
$classes[] = 'page-parent';
662
693
if ( is_post_type_archive() ) {
663
694
$classes[] = 'post-type-archive';
664
695
$post_type = get_query_var( 'post_type' );
665
if ( is_array( $post_type ) )
696
if ( is_array( $post_type ) ) {
666
697
$post_type = reset( $post_type );
667
699
$classes[] = 'post-type-archive-' . sanitize_html_class( $post_type );
668
700
} elseif ( is_author() ) {
669
$author = $wp_query->get_queried_object();
701
$author = $wp_query->get_queried_object();
670
702
$classes[] = 'author';
671
703
if ( isset( $author->user_nicename ) ) {
672
704
$classes[] = 'author-' . sanitize_html_class( $author->user_nicename, $author->ID );
673
705
$classes[] = 'author-' . $author->ID;
675
707
} elseif ( is_category() ) {
676
$cat = $wp_query->get_queried_object();
708
$cat = $wp_query->get_queried_object();
677
709
$classes[] = 'category';
678
710
if ( isset( $cat->term_id ) ) {
679
711
$cat_class = sanitize_html_class( $cat->slug, $cat->term_id );
685
717
$classes[] = 'category-' . $cat->term_id;
687
719
} elseif ( is_tag() ) {
688
$tag = $wp_query->get_queried_object();
720
$tag = $wp_query->get_queried_object();
689
721
$classes[] = 'tag';
690
722
if ( isset( $tag->term_id ) ) {
691
723
$tag_class = sanitize_html_class( $tag->slug, $tag->term_id );
714
if ( is_user_logged_in() )
746
if ( is_user_logged_in() ) {
715
747
$classes[] = 'logged-in';
717
750
if ( is_admin_bar_showing() ) {
718
751
$classes[] = 'admin-bar';
719
752
$classes[] = 'no-customize-support';
722
if ( get_background_color() !== get_theme_support( 'custom-background', 'default-color' ) || get_background_image() )
755
if ( get_background_color() !== get_theme_support( 'custom-background', 'default-color' ) || get_background_image() ) {
723
756
$classes[] = 'custom-background';
725
759
if ( has_custom_logo() ) {
726
760
$classes[] = 'wp-custom-logo';
733
767
$page = $wp_query->get( 'page' );
735
if ( ! $page || $page < 2 )
769
if ( ! $page || $page < 2 ) {
736
770
$page = $wp_query->get( 'paged' );
738
773
if ( $page && $page > 1 && ! is_404() ) {
739
774
$classes[] = 'paged-' . $page;
742
777
$classes[] = 'single-paged-' . $page;
778
} elseif ( is_page() ) {
744
779
$classes[] = 'page-paged-' . $page;
745
elseif ( is_category() )
780
} elseif ( is_category() ) {
746
781
$classes[] = 'category-paged-' . $page;
782
} elseif ( is_tag() ) {
748
783
$classes[] = 'tag-paged-' . $page;
784
} elseif ( is_date() ) {
750
785
$classes[] = 'date-paged-' . $page;
751
elseif ( is_author() )
786
} elseif ( is_author() ) {
752
787
$classes[] = 'author-paged-' . $page;
753
elseif ( is_search() )
788
} elseif ( is_search() ) {
754
789
$classes[] = 'search-paged-' . $page;
755
elseif ( is_post_type_archive() )
790
} elseif ( is_post_type_archive() ) {
756
791
$classes[] = 'post-type-paged-' . $page;
759
795
if ( ! empty( $class ) ) {
760
if ( !is_array( $class ) )
796
if ( ! is_array( $class ) ) {
761
797
$class = preg_split( '#\s+#', $class );
762
799
$classes = array_merge( $classes, $class );
764
801
// Ensure that we always coerce class to being an array.
768
805
$classes = array_map( 'esc_attr', $classes );
771
* Filters the list of CSS body classes for the current post or page.
808
* Filters the list of CSS body class names for the current post or page.
775
* @param array $classes An array of body classes.
776
* @param array $class An array of additional classes added to the body.
812
* @param string[] $classes An array of body class names.
813
* @param string[] $class An array of additional class names added to the body.
778
815
$classes = apply_filters( 'body_class', $classes, $class );
789
826
* @return bool false if a password is not required or the correct password cookie is present, true otherwise.
791
828
function post_password_required( $post = null ) {
792
$post = get_post($post);
829
$post = get_post( $post );
794
831
if ( empty( $post->post_password ) ) {
795
832
/** This filter is documented in wp-includes/post-template.php */
831
868
* The formatted output of a list of pages.
833
* Displays page links for paginated posts (i.e. includes the <!--nextpage-->.
870
* Displays page links for paginated posts (i.e. including the `<!--nextpage-->`
834
871
* Quicktag one or more times). This tag must be within The Loop.
874
* @since 5.1.0 Added the `aria_current` argument.
838
876
* @global int $page
839
877
* @global int $numpages
849
887
* Also prepended to the current item, which is not linked. Default empty.
850
888
* @type string $link_after HTML or text to append to each Pages link inside the `<a>` tag.
851
889
* Also appended to the current item, which is not linked. Default empty.
890
* @type string $aria_current The value for the aria-current attribute. Possible values are 'page',
891
* 'step', 'location', 'date', 'time', 'true', 'false'. Default is 'page'.
852
892
* @type string $next_or_number Indicates whether page numbers should be used. Valid values are number
853
893
* and next. Default is 'number'.
854
894
* @type string $separator Text between pagination links. Default is ' '.
865
905
global $page, $numpages, $multipage, $more;
867
907
$defaults = array(
868
'before' => '<p>' . __( 'Pages:' ),
908
'before' => '<p class="post-nav-links">' . __( 'Pages:' ),
869
909
'after' => '</p>',
870
910
'link_before' => '',
871
911
'link_after' => '',
912
'aria_current' => 'page',
872
913
'next_or_number' => 'number',
873
914
'separator' => ' ',
874
915
'nextpagelink' => __( 'Next page' ),
875
916
'previouspagelink' => __( 'Previous page' ),
876
917
'pagelink' => '%',
880
921
$params = wp_parse_args( $args, $defaults );
896
937
$link = $r['link_before'] . str_replace( '%', $i, $r['pagelink'] ) . $r['link_after'];
897
938
if ( $i != $page || ! $more && 1 == $page ) {
898
939
$link = _wp_link_page( $i ) . $link . '</a>';
940
} elseif ( $i === $page ) {
941
$link = '<span class="post-page-numbers current" aria-current="' . esc_attr( $r['aria_current'] ) . '">' . $link . '</span>';
901
944
* Filters the HTML output of individual page number links.
965
1008
function _wp_link_page( $i ) {
966
1009
global $wp_rewrite;
968
1011
$query_args = array();
970
1013
if ( 1 == $i ) {
971
1014
$url = get_permalink();
973
if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) )
1016
if ( '' == get_option( 'permalink_structure' ) || in_array( $post->post_status, array( 'draft', 'pending' ) ) ) {
974
1017
$url = add_query_arg( 'page', $i, get_permalink() );
975
elseif ( 'page' == get_option('show_on_front') && get_option('page_on_front') == $post->ID )
976
$url = trailingslashit(get_permalink()) . user_trailingslashit("$wp_rewrite->pagination_base/" . $i, 'single_paged');
978
$url = trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged');
1018
} elseif ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $post->ID ) {
1019
$url = trailingslashit( get_permalink() ) . user_trailingslashit( "$wp_rewrite->pagination_base/" . $i, 'single_paged' );
1021
$url = trailingslashit( get_permalink() ) . user_trailingslashit( $i, 'single_paged' );
981
1025
if ( is_preview() ) {
983
1027
if ( ( 'draft' !== $post->post_status ) && isset( $_GET['preview_id'], $_GET['preview_nonce'] ) ) {
984
$query_args['preview_id'] = wp_unslash( $_GET['preview_id'] );
1028
$query_args['preview_id'] = wp_unslash( $_GET['preview_id'] );
985
1029
$query_args['preview_nonce'] = wp_unslash( $_GET['preview_nonce'] );
988
1032
$url = get_preview_post_link( $post, $query_args, $url );
991
return '<a href="' . esc_url( $url ) . '">';
1035
return '<a href="' . esc_url( $url ) . '" class="post-page-numbers">';
1006
1050
function post_custom( $key = '' ) {
1007
1051
$custom = get_post_custom();
1009
if ( !isset( $custom[$key] ) )
1053
if ( ! isset( $custom[ $key ] ) ) {
1011
elseif ( 1 == count($custom[$key]) )
1012
return $custom[$key][0];
1014
return $custom[$key];
1055
} elseif ( 1 == count( $custom[ $key ] ) ) {
1056
return $custom[ $key ][0];
1058
return $custom[ $key ];
1018
* Display list of post custom fields.
1063
* Display a list of post custom fields.
1022
1067
* @internal This will probably change at some point...
1025
1069
function the_meta() {
1026
1070
if ( $keys = get_post_custom_keys() ) {
1027
echo "<ul class='post-meta'>\n";
1028
1072
foreach ( (array) $keys as $key ) {
1029
1073
$keyt = trim( $key );
1030
1074
if ( is_protected_meta( $keyt, 'post' ) ) {
1034
1078
$values = array_map( 'trim', get_post_custom_values( $key ) );
1035
$value = implode( $values, ', ' );
1079
$value = implode( $values, ', ' );
1037
$html = sprintf( "<li><span class='post-meta-key'>%s</span> %s</li>\n",
1082
"<li><span class='post-meta-key'>%s</span> %s</li>\n",
1038
1083
/* translators: %s: Post custom field name */
1039
1084
sprintf( _x( '%s:', 'Post custom field name' ), $key ),
1049
1094
* @param string $key Meta key.
1050
1095
* @param string $value Meta value.
1052
echo apply_filters( 'the_meta_key', $html, $key, $value );
1097
$li_html .= apply_filters( 'the_meta_key', $html, $key, $value );
1101
echo "<ul class='post-meta'>\n{$li_html}</ul>\n";
1063
* Retrieve or display list of pages as a dropdown (select list).
1111
* Retrieve or display a list of pages as a dropdown (select list).
1066
1114
* @since 4.2.0 The `$value_field` argument was added.
1067
1115
* @since 4.3.0 The `$class` argument was added.
1069
1119
* @param array|string $args {
1070
* Optional. Array or string of arguments to generate a pages drop-down element.
1120
* Optional. Array or string of arguments to generate a page dropdown. See `get_pages()` for additional arguments.
1072
1122
* @type int $depth Maximum depth. Default 0.
1073
1123
* @type int $child_of Page ID to retrieve child pages of. Default 0.
1090
1140
function wp_dropdown_pages( $args = '' ) {
1091
1141
$defaults = array(
1092
'depth' => 0, 'child_of' => 0,
1093
'selected' => 0, 'echo' => 1,
1094
'name' => 'page_id', 'id' => '',
1096
'show_option_none' => '', 'show_option_no_change' => '',
1097
'option_none_value' => '',
1098
'value_field' => 'ID',
1146
'name' => 'page_id',
1149
'show_option_none' => '',
1150
'show_option_no_change' => '',
1151
'option_none_value' => '',
1152
'value_field' => 'ID',
1101
1155
$r = wp_parse_args( $args, $defaults );
1103
$pages = get_pages( $r );
1157
$pages = get_pages( $r );
1105
1159
// Back-compat with old system where both id and name were based on $name argument
1106
1160
if ( empty( $r['id'] ) ) {
1133
1187
* @param string $output HTML output for drop down list of pages.
1134
1188
* @param array $r The parsed arguments array.
1135
1189
* @param array $pages List of WP_Post objects returned by `get_pages()`
1137
1191
$html = apply_filters( 'wp_dropdown_pages', $output, $r, $pages );
1139
1193
if ( $r['echo'] ) {
1153
1207
* @global WP_Query $wp_query
1155
1209
* @param array|string $args {
1156
* Array or string of arguments. Optional.
1210
* Optional. Array or string of arguments to generate a list of pages. See `get_pages()` for additional arguments.
1158
1212
* @type int $child_of Display only the sub-pages of a single page by ID. Default 0 (all pages).
1159
1213
* @type string $authors Comma-separated list of author IDs. Default empty (all authors).
1274
1328
* Displays or retrieves a list of pages with an optional home link.
1276
* The arguments are listed below and part of the arguments are for wp_list_pages()} function.
1330
* The arguments are listed below and part of the arguments are for wp_list_pages() function.
1277
1331
* Check that function for more info on those arguments.
1281
1335
* @since 4.7.0 Added the `item_spacing` argument.
1283
1337
* @param array|string $args {
1284
* Optional. Arguments to generate a page menu. See wp_list_pages() for additional arguments.
1338
* Optional. Array or string of arguments to generate a page menu. See `wp_list_pages()` for additional arguments.
1286
1340
* @type string $sort_column How to sort the list of pages. Accepts post column names.
1287
1341
* Default 'menu_order, post_title'.
1296
1350
* @type string $link_after The HTML or text to append to $show_home text. Default empty.
1297
1351
* @type string $before The HTML or text to prepend to the menu. Default is '<ul>'.
1298
1352
* @type string $after The HTML or text to append to the menu. Default is '</ul>'.
1299
* @type string $item_spacing Whether to preserve whitespace within the menu's HTML. Accepts 'preserve' or 'discard'. Default 'discard'.
1353
* @type string $item_spacing Whether to preserve whitespace within the menu's HTML. Accepts 'preserve'
1354
* or 'discard'. Default 'discard'.
1300
1355
* @type Walker $walker Walker instance to use for listing pages. Default empty (Walker_Page).
1302
1357
* @return string|void HTML menu
1315
1370
'item_spacing' => 'discard',
1316
1371
'walker' => '',
1318
$args = wp_parse_args( $args, $defaults );
1373
$args = wp_parse_args( $args, $defaults );
1320
1375
if ( ! in_array( $args['item_spacing'], array( 'preserve', 'discard' ) ) ) {
1321
1376
// invalid value, fall back to default.
1346
1401
$list_args = $args;
1348
1403
// Show Home in the menu
1349
if ( ! empty($args['show_home']) ) {
1350
if ( true === $args['show_home'] || '1' === $args['show_home'] || 1 === $args['show_home'] )
1404
if ( ! empty( $args['show_home'] ) ) {
1405
if ( true === $args['show_home'] || '1' === $args['show_home'] || 1 === $args['show_home'] ) {
1406
$text = __( 'Home' );
1353
1408
$text = $args['show_home'];
1355
if ( is_front_page() && !is_paged() )
1411
if ( is_front_page() && ! is_paged() ) {
1356
1412
$class = 'class="current_page_item"';
1357
1414
$menu .= '<li ' . $class . '><a href="' . home_url( '/' ) . '">' . $args['link_before'] . $text . $args['link_after'] . '</a></li>';
1358
1415
// If the front page is a page, add it to the exclude list
1359
if (get_option('show_on_front') == 'page') {
1360
if ( !empty( $list_args['exclude'] ) ) {
1416
if ( get_option( 'show_on_front' ) == 'page' ) {
1417
if ( ! empty( $list_args['exclude'] ) ) {
1361
1418
$list_args['exclude'] .= ',';
1363
1420
$list_args['exclude'] = '';
1365
$list_args['exclude'] .= get_option('page_on_front');
1422
$list_args['exclude'] .= get_option( 'page_on_front' );
1369
$list_args['echo'] = false;
1426
$list_args['echo'] = false;
1370
1427
$list_args['title_li'] = '';
1371
$menu .= wp_list_pages( $list_args );
1428
$menu .= wp_list_pages( $list_args );
1373
1430
$container = sanitize_text_field( $args['container'] );
1384
1441
'wp_page_menu' === $args['fallback_cb'] &&
1385
1442
'ul' !== $container ) {
1386
1443
$args['before'] = "<ul>{$n}";
1387
$args['after'] = '</ul>';
1444
$args['after'] = '</ul>';
1390
1447
$menu = $args['before'] . $menu . $args['after'];
1435
1493
* @return string
1437
1495
function walk_page_tree( $pages, $depth, $current_page, $r ) {
1438
if ( empty($r['walker']) )
1496
if ( empty( $r['walker'] ) ) {
1439
1497
$walker = new Walker_Page;
1441
1499
$walker = $r['walker'];
1443
1502
foreach ( (array) $pages as $page ) {
1444
if ( $page->post_parent )
1503
if ( $page->post_parent ) {
1445
1504
$r['pages_with_children'][ $page->post_parent ] = true;
1448
$args = array($pages, $depth, $r, $current_page);
1449
return call_user_func_array(array($walker, 'walk'), $args);
1508
$args = array( $pages, $depth, $r, $current_page );
1509
return call_user_func_array( array( $walker, 'walk' ), $args );
1461
1521
function walk_page_dropdown_tree() {
1462
1522
$args = func_get_args();
1463
if ( empty($args[2]['walker']) ) // the user's options are the third parameter
1523
if ( empty( $args[2]['walker'] ) ) { // the user's options are the third parameter
1464
1524
$walker = new Walker_PageDropdown;
1466
1526
$walker = $args[2]['walker'];
1468
return call_user_func_array(array($walker, 'walk'), $args);
1529
return call_user_func_array( array( $walker, 'walk' ), $args );
1483
1544
* @param bool $permalink Optional, default is false. Whether to include permalink.
1485
1546
function the_attachment_link( $id = 0, $fullsize = false, $deprecated = false, $permalink = false ) {
1486
if ( !empty( $deprecated ) )
1547
if ( ! empty( $deprecated ) ) {
1487
1548
_deprecated_argument( __FUNCTION__, '2.5.0' );
1490
echo wp_get_attachment_link($id, 'full', $permalink);
1492
echo wp_get_attachment_link($id, 'thumbnail', $permalink);
1552
echo wp_get_attachment_link( $id, 'full', $permalink );
1554
echo wp_get_attachment_link( $id, 'thumbnail', $permalink );
1547
1611
* @param bool $permalink Whether to add permalink to image. Default false.
1548
1612
* @param bool $icon Whether to include an icon. Default false.
1549
1613
* @param string|bool $text If string, will be link text. Default false.
1614
* @param array|string $attr Array or string of attributes. Default empty.
1551
return apply_filters( 'wp_get_attachment_link', "<a href='" . esc_url( $url ) . "'>$link_text</a>", $id, $size, $permalink, $icon, $text );
1616
return apply_filters( 'wp_get_attachment_link', "<a href='" . esc_url( $url ) . "'>$link_text</a>", $id, $size, $permalink, $icon, $text, $attr );
1559
1624
* @param string $content
1560
1625
* @return string
1562
function prepend_attachment($content) {
1627
function prepend_attachment( $content ) {
1563
1628
$post = get_post();
1565
if ( empty($post->post_type) || $post->post_type != 'attachment' )
1630
if ( empty( $post->post_type ) || $post->post_type != 'attachment' ) {
1566
1631
return $content;
1568
1634
if ( wp_attachment_is( 'video', $post ) ) {
1569
1635
$meta = wp_get_attachment_metadata( get_the_ID() );
1570
1636
$atts = array( 'src' => wp_get_attachment_url() );
1571
1637
if ( ! empty( $meta['width'] ) && ! empty( $meta['height'] ) ) {
1572
$atts['width'] = (int) $meta['width'];
1638
$atts['width'] = (int) $meta['width'];
1573
1639
$atts['height'] = (int) $meta['height'];
1575
1641
if ( has_post_thumbnail() ) {
1582
1648
$p = '<p class="attachment">';
1583
1649
// show the medium sized image representation of the attachment if available, and link to the raw file
1584
$p .= wp_get_attachment_link(0, 'medium', false);
1650
$p .= wp_get_attachment_link( 0, 'medium', false );
1612
1678
* @return string HTML content for password form for password protected post.
1614
1680
function get_the_password_form( $post = 0 ) {
1615
$post = get_post( $post );
1616
$label = 'pwbox-' . ( empty($post->ID) ? rand() : $post->ID );
1681
$post = get_post( $post );
1682
$label = 'pwbox-' . ( empty( $post->ID ) ? rand() : $post->ID );
1617
1683
$output = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" class="post-password-form" method="post">
1618
1684
<p>' . __( 'This content is password protected. To view it please enter your password below:' ) . '</p>
1619
1685
<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>
1639
1705
* This template tag allows you to determine if you are in a page template.
1640
1706
* You can optionally provide a template name or array of template names
1641
1707
* and then the check will be specific to that template.
1643
1709
* For more information on this and similar theme functions, check out
1644
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
1710
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
1645
1711
* Conditional Tags} article in the Theme Developer Handbook.
1648
1714
* @since 4.2.0 The `$template` parameter was changed to also accept an array of page templates.
1649
1715
* @since 4.7.0 Now works with any post type, not just pages.
1659
1725
$page_template = get_page_template_slug( get_queried_object_id() );
1661
if ( empty( $template ) )
1727
if ( empty( $template ) ) {
1662
1728
return (bool) $page_template;
1664
if ( $template == $page_template )
1731
if ( $template == $page_template ) {
1667
1735
if ( is_array( $template ) ) {
1668
1736
if ( ( in_array( 'default', $template, true ) && ! $page_template )
1684
1752
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
1685
1753
* @return string|false Page template filename. Returns an empty string when the default page template
1686
* is in use. Returns false if the post does not exist.
1754
* is in use. Returns false if the post does not exist.
1688
1756
function get_page_template_slug( $post = null ) {
1689
1757
$post = get_post( $post );
1711
1779
* @return string|false i18n formatted datetimestamp or localized 'Current Revision'.
1713
1781
function wp_post_revision_title( $revision, $link = true ) {
1714
if ( !$revision = get_post( $revision ) )
1782
if ( ! $revision = get_post( $revision ) ) {
1715
1783
return $revision;
1717
if ( !in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) )
1786
if ( ! in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) ) {
1720
1790
/* translators: revision date format, see https://secure.php.net/date */
1721
1791
$datef = _x( 'F j, Y @ H:i:s', 'revision date format' );
1722
1792
/* translators: %s: revision date */
1723
1793
$autosavef = __( '%s [Autosave]' );
1724
1794
/* translators: %s: revision date */
1725
$currentf = __( '%s [Current Revision]' );
1795
$currentf = __( '%s [Current Revision]' );
1727
1797
$date = date_i18n( $datef, strtotime( $revision->post_modified ) );
1728
if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) )
1798
if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) ) {
1729
1799
$date = "<a href='$link'>$date</a>";
1731
if ( !wp_is_post_revision( $revision ) )
1802
if ( ! wp_is_post_revision( $revision ) ) {
1732
1803
$date = sprintf( $currentf, $date );
1733
elseif ( wp_is_post_autosave( $revision ) )
1804
} elseif ( wp_is_post_autosave( $revision ) ) {
1734
1805
$date = sprintf( $autosavef, $date );
1746
1818
* @return string|false gravatar, user, i18n formatted datetimestamp or localized 'Current Revision'.
1748
1820
function wp_post_revision_title_expanded( $revision, $link = true ) {
1749
if ( !$revision = get_post( $revision ) )
1821
if ( ! $revision = get_post( $revision ) ) {
1750
1822
return $revision;
1752
if ( !in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) )
1825
if ( ! in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) ) {
1755
1829
$author = get_the_author_meta( 'display_name', $revision->post_author );
1756
1830
/* translators: revision date format, see https://secure.php.net/date */
1759
1833
$gravatar = get_avatar( $revision->post_author, 24 );
1761
1835
$date = date_i18n( $datef, strtotime( $revision->post_modified ) );
1762
if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) )
1836
if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) ) {
1763
1837
$date = "<a href='$link'>$date</a>";
1765
1840
$revision_date_author = sprintf(
1766
1841
/* translators: post revision title: 1: author avatar, 2: author name, 3: time ago, 4: date */
1774
1849
/* translators: %s: revision date with author avatar */
1775
1850
$autosavef = __( '%s [Autosave]' );
1776
1851
/* translators: %s: revision date with author avatar */
1777
$currentf = __( '%s [Current Revision]' );
1852
$currentf = __( '%s [Current Revision]' );
1779
if ( !wp_is_post_revision( $revision ) )
1854
if ( ! wp_is_post_revision( $revision ) ) {
1780
1855
$revision_date_author = sprintf( $currentf, $revision_date_author );
1781
elseif ( wp_is_post_autosave( $revision ) )
1856
} elseif ( wp_is_post_autosave( $revision ) ) {
1782
1857
$revision_date_author = sprintf( $autosavef, $revision_date_author );
1785
1861
* Filters the formatted author and date for a revision.
1806
1882
* @param string $type 'all' (default), 'revision' or 'autosave'
1808
1884
function wp_list_post_revisions( $post_id = 0, $type = 'all' ) {
1809
if ( ! $post = get_post( $post_id ) )
1885
if ( ! $post = get_post( $post_id ) ) {
1812
1889
// $args array with (parent, format, right, left, type) deprecated since 3.6
1813
1890
if ( is_array( $type ) ) {
1814
$type = ! empty( $type['type'] ) ? $type['type'] : $type;
1891
$type = ! empty( $type['type'] ) ? $type['type'] : $type;
1815
1892
_deprecated_argument( __FUNCTION__, '3.6.0' );
1818
if ( ! $revisions = wp_get_post_revisions( $post->ID ) )
1895
if ( ! $revisions = wp_get_post_revisions( $post->ID ) ) {
1822
1900
foreach ( $revisions as $revision ) {
1823
if ( ! current_user_can( 'read_post', $revision->ID ) )
1901
if ( ! current_user_can( 'read_post', $revision->ID ) ) {
1826
1905
$is_autosave = wp_is_post_autosave( $revision );
1827
if ( ( 'revision' === $type && $is_autosave ) || ( 'autosave' === $type && ! $is_autosave ) )
1906
if ( ( 'revision' === $type && $is_autosave ) || ( 'autosave' === $type && ! $is_autosave ) ) {
1830
1910
$rows .= "\t<li>" . wp_post_revision_title_expanded( $revision ) . "</li>\n";