Changeset 42343 for trunk/src/wp-includes/post-template.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/post-template.php
r42225 r42343 43 43 $title = get_the_title(); 44 44 45 if ( strlen( $title) == 0 )45 if ( strlen( $title ) == 0 ) { 46 46 return; 47 } 47 48 48 49 $title = $before . $title . $after; 49 50 50 if ( $echo ) 51 if ( $echo ) { 51 52 echo $title; 52 else53 } else { 53 54 return $title; 55 } 54 56 } 55 57 … … 77 79 */ 78 80 function the_title_attribute( $args = '' ) { 79 $defaults = array( 'before' => '', 'after' => '', 'echo' => true, 'post' => get_post() ); 80 $r = wp_parse_args( $args, $defaults ); 81 $defaults = array( 82 'before' => '', 83 'after' => '', 84 'echo' => true, 85 'post' => get_post(), 86 ); 87 $r = wp_parse_args( $args, $defaults ); 81 88 82 89 $title = get_the_title( $r['post'] ); … … 112 119 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; 115 122 116 123 if ( ! is_admin() ) { … … 129 136 */ 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 ) { 133 140 … … 144 151 */ 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 ); 147 154 } 148 155 } … … 228 235 * @param bool $strip_teaser Optional. Strip teaser content before the more text. Default is false. 229 236 */ 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 ); 232 239 … … 275 282 } 276 283 277 $output = '';284 $output = ''; 278 285 $has_teaser = false; 279 286 280 287 // If post password required and it doesn't match the cookie. 281 if ( post_password_required( $post ) ) 288 if ( post_password_required( $post ) ) { 282 289 return get_the_password_form( $post ); 283 284 if ( $page > count( $pages ) ) // if the requested page doesn't exist 290 } 291 292 if ( $page > count( $pages ) ) { // if the requested page doesn't exist 285 293 $page = count( $pages ); // give them the highest numbered page that DOES exist 286 287 $content = $pages[$page - 1]; 294 } 295 296 $content = $pages[ $page - 1 ]; 288 297 if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) { 289 298 $content = explode( $matches[0], $content, 2 ); 290 if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) ) 299 if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) ) { 291 300 $more_link_text = strip_tags( wp_kses_no_null( trim( $matches[1] ) ) ); 301 } 292 302 293 303 $has_teaser = true; … … 296 306 } 297 307 298 if ( false !== strpos( $post->post_content, '<!--noteaser-->' ) && ( ! $multipage || $page == 1 ) ) 308 if ( false !== strpos( $post->post_content, '<!--noteaser-->' ) && ( ! $multipage || $page == 1 ) ) { 299 309 $strip_teaser = true; 310 } 300 311 301 312 $teaser = $content[0]; 302 313 303 if ( $more && $strip_teaser && $has_teaser ) 314 if ( $more && $strip_teaser && $has_teaser ) { 304 315 $teaser = ''; 316 } 305 317 306 318 $output .= $teaser; … … 310 322 $output .= '<span id="more-' . $post->ID . '"></span>' . $content[1]; 311 323 } else { 312 if ( ! empty( $more_link_text ) ) 324 if ( ! empty( $more_link_text ) ) { 313 325 314 326 /** … … 321 333 */ 322 334 $output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink() . "#more-{$post->ID}\" class=\"more-link\">$more_link_text</a>", $more_link_text ); 335 } 323 336 $output = force_balance_tags( $output ); 324 337 } 325 338 } 326 339 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 ); 340 if ( $preview ) { // Preview fix for JavaScript bug with foreign languages. 341 $output = preg_replace_callback( '/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output ); 342 } 329 343 330 344 return $output; … … 408 422 function has_excerpt( $post = 0 ) { 409 423 $post = get_post( $post ); 410 return ( ! empty( $post->post_excerpt ) );424 return ( ! empty( $post->post_excerpt ) ); 411 425 } 412 426 … … 465 479 466 480 $classes[] = 'post-' . $post->ID; 467 if ( ! is_admin() ) 481 if ( ! is_admin() ) { 468 482 $classes[] = $post->post_type; 483 } 469 484 $classes[] = 'type-' . $post->post_type; 470 485 $classes[] = 'status-' . $post->post_status; … … 474 489 $post_format = get_post_format( $post->ID ); 475 490 476 if ( $post_format && ! is_wp_error($post_format) )491 if ( $post_format && ! is_wp_error( $post_format ) ) { 477 492 $classes[] = 'format-' . sanitize_html_class( $post_format ); 478 else493 } else { 479 494 $classes[] = 'format-standard'; 495 } 480 496 } 481 497 … … 573 589 $classes = array(); 574 590 575 if ( is_rtl() ) 591 if ( is_rtl() ) { 576 592 $classes[] = 'rtl'; 577 578 if ( is_front_page() ) 593 } 594 595 if ( is_front_page() ) { 579 596 $classes[] = 'home'; 580 if ( is_home() ) 597 } 598 if ( is_home() ) { 581 599 $classes[] = 'blog'; 582 if ( is_archive() ) 600 } 601 if ( is_archive() ) { 583 602 $classes[] = 'archive'; 584 if ( is_date() ) 603 } 604 if ( is_date() ) { 585 605 $classes[] = 'date'; 606 } 586 607 if ( is_search() ) { 587 608 $classes[] = 'search'; 588 609 $classes[] = $wp_query->posts ? 'search-results' : 'search-no-results'; 589 610 } 590 if ( is_paged() ) 611 if ( is_paged() ) { 591 612 $classes[] = 'paged'; 592 if ( is_attachment() ) 613 } 614 if ( is_attachment() ) { 593 615 $classes[] = 'attachment'; 594 if ( is_404() ) 616 } 617 if ( is_404() ) { 595 618 $classes[] = 'error404'; 619 } 596 620 597 621 if ( is_singular() ) { 598 $post_id = $wp_query->get_queried_object_id();599 $post = $wp_query->get_queried_object();622 $post_id = $wp_query->get_queried_object_id(); 623 $post = $wp_query->get_queried_object(); 600 624 $post_type = $post->post_type; 601 625 … … 624 648 $post_format = get_post_format( $post->ID ); 625 649 626 if ( $post_format && ! is_wp_error($post_format) )650 if ( $post_format && ! is_wp_error( $post_format ) ) { 627 651 $classes[] = 'single-format-' . sanitize_html_class( $post_format ); 628 else652 } else { 629 653 $classes[] = 'single-format-standard'; 654 } 630 655 } 631 656 } … … 633 658 634 659 if ( is_attachment() ) { 635 $mime_type = get_post_mime_type($post_id);660 $mime_type = get_post_mime_type( $post_id ); 636 661 $mime_prefix = array( 'application/', 'image/', 'text/', 'audio/', 'video/', 'music/' ); 637 $classes[] = 'attachmentid-' . $post_id;638 $classes[] = 'attachment-' . str_replace( $mime_prefix, '', $mime_type );662 $classes[] = 'attachmentid-' . $post_id; 663 $classes[] = 'attachment-' . str_replace( $mime_prefix, '', $mime_type ); 639 664 } elseif ( is_page() ) { 640 665 $classes[] = 'page'; … … 642 667 $page_id = $wp_query->get_queried_object_id(); 643 668 644 $post = get_post( $page_id);669 $post = get_post( $page_id ); 645 670 646 671 $classes[] = 'page-id-' . $page_id; 647 672 648 if ( get_pages( array( 'parent' => $page_id, 'number' => 1 ) ) ) { 673 if ( get_pages( 674 array( 675 'parent' => $page_id, 676 'number' => 1, 677 ) 678 ) ) { 649 679 $classes[] = 'page-parent'; 650 680 } … … 659 689 $classes[] = 'post-type-archive'; 660 690 $post_type = get_query_var( 'post_type' ); 661 if ( is_array( $post_type ) ) 691 if ( is_array( $post_type ) ) { 662 692 $post_type = reset( $post_type ); 693 } 663 694 $classes[] = 'post-type-archive-' . sanitize_html_class( $post_type ); 664 695 } elseif ( is_author() ) { 665 $author = $wp_query->get_queried_object();696 $author = $wp_query->get_queried_object(); 666 697 $classes[] = 'author'; 667 698 if ( isset( $author->user_nicename ) ) { … … 670 701 } 671 702 } elseif ( is_category() ) { 672 $cat = $wp_query->get_queried_object();703 $cat = $wp_query->get_queried_object(); 673 704 $classes[] = 'category'; 674 705 if ( isset( $cat->term_id ) ) { … … 682 713 } 683 714 } elseif ( is_tag() ) { 684 $tag = $wp_query->get_queried_object();715 $tag = $wp_query->get_queried_object(); 685 716 $classes[] = 'tag'; 686 717 if ( isset( $tag->term_id ) ) { … … 708 739 } 709 740 710 if ( is_user_logged_in() ) 741 if ( is_user_logged_in() ) { 711 742 $classes[] = 'logged-in'; 743 } 712 744 713 745 if ( is_admin_bar_showing() ) { … … 716 748 } 717 749 718 if ( get_background_color() !== get_theme_support( 'custom-background', 'default-color' ) || get_background_image() ) 750 if ( get_background_color() !== get_theme_support( 'custom-background', 'default-color' ) || get_background_image() ) { 719 751 $classes[] = 'custom-background'; 752 } 720 753 721 754 if ( has_custom_logo() ) { … … 725 758 $page = $wp_query->get( 'page' ); 726 759 727 if ( ! $page || $page < 2 ) 760 if ( ! $page || $page < 2 ) { 728 761 $page = $wp_query->get( 'paged' ); 762 } 729 763 730 764 if ( $page && $page > 1 && ! is_404() ) { 731 765 $classes[] = 'paged-' . $page; 732 766 733 if ( is_single() ) 767 if ( is_single() ) { 734 768 $classes[] = 'single-paged-' . $page; 735 elseif ( is_page() )769 } elseif ( is_page() ) { 736 770 $classes[] = 'page-paged-' . $page; 737 elseif ( is_category() )771 } elseif ( is_category() ) { 738 772 $classes[] = 'category-paged-' . $page; 739 elseif ( is_tag() )773 } elseif ( is_tag() ) { 740 774 $classes[] = 'tag-paged-' . $page; 741 elseif ( is_date() )775 } elseif ( is_date() ) { 742 776 $classes[] = 'date-paged-' . $page; 743 elseif ( is_author() )777 } elseif ( is_author() ) { 744 778 $classes[] = 'author-paged-' . $page; 745 elseif ( is_search() )779 } elseif ( is_search() ) { 746 780 $classes[] = 'search-paged-' . $page; 747 elseif ( is_post_type_archive() )781 } elseif ( is_post_type_archive() ) { 748 782 $classes[] = 'post-type-paged-' . $page; 783 } 749 784 } 750 785 751 786 if ( ! empty( $class ) ) { 752 if ( ! is_array( $class ) )787 if ( ! is_array( $class ) ) { 753 788 $class = preg_split( '#\s+#', $class ); 789 } 754 790 $classes = array_merge( $classes, $class ); 755 791 } else { … … 782 818 */ 783 819 function post_password_required( $post = null ) { 784 $post = get_post( $post);820 $post = get_post( $post ); 785 821 786 822 if ( empty( $post->post_password ) ) { … … 867 903 'previouspagelink' => __( 'Previous page' ), 868 904 'pagelink' => '%', 869 'echo' => 1 905 'echo' => 1, 870 906 ); 871 907 … … 907 943 } elseif ( $more ) { 908 944 $output .= $r['before']; 909 $prev = $page - 1;945 $prev = $page - 1; 910 946 if ( $prev > 0 ) { 911 947 $link = _wp_link_page( $prev ) . $r['link_before'] . $r['previouspagelink'] . $r['link_after'] . '</a>'; … … 957 993 function _wp_link_page( $i ) { 958 994 global $wp_rewrite; 959 $post = get_post();995 $post = get_post(); 960 996 $query_args = array(); 961 997 … … 963 999 $url = get_permalink(); 964 1000 } else { 965 if ( '' == get_option( 'permalink_structure') || in_array($post->post_status, array('draft', 'pending')) )1001 if ( '' == get_option( 'permalink_structure' ) || in_array( $post->post_status, array( 'draft', 'pending' ) ) ) { 966 1002 $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'); 1003 } elseif ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $post->ID ) { 1004 $url = trailingslashit( get_permalink() ) . user_trailingslashit( "$wp_rewrite->pagination_base/" . $i, 'single_paged' ); 1005 } else { 1006 $url = trailingslashit( get_permalink() ) . user_trailingslashit( $i, 'single_paged' ); 1007 } 971 1008 } 972 1009 … … 974 1011 975 1012 if ( ( 'draft' !== $post->post_status ) && isset( $_GET['preview_id'], $_GET['preview_nonce'] ) ) { 976 $query_args['preview_id'] = wp_unslash( $_GET['preview_id'] );1013 $query_args['preview_id'] = wp_unslash( $_GET['preview_id'] ); 977 1014 $query_args['preview_nonce'] = wp_unslash( $_GET['preview_nonce'] ); 978 1015 } … … 999 1036 $custom = get_post_custom(); 1000 1037 1001 if ( ! isset( $custom[$key] ) )1038 if ( ! isset( $custom[ $key ] ) ) { 1002 1039 return false; 1003 elseif ( 1 == count($custom[$key]) ) 1004 return $custom[$key][0]; 1005 else 1006 return $custom[$key]; 1040 } elseif ( 1 == count( $custom[ $key ] ) ) { 1041 return $custom[ $key ][0]; 1042 } else { 1043 return $custom[ $key ]; 1044 } 1007 1045 } 1008 1046 … … 1013 1051 * 1014 1052 * @internal This will probably change at some point... 1015 *1016 1053 */ 1017 1054 function the_meta() { … … 1025 1062 1026 1063 $values = array_map( 'trim', get_post_custom_values( $key ) ); 1027 $value = implode( $values, ', ' ); 1028 1029 $html = sprintf( "<li><span class='post-meta-key'>%s</span> %s</li>\n", 1064 $value = implode( $values, ', ' ); 1065 1066 $html = sprintf( 1067 "<li><span class='post-meta-key'>%s</span> %s</li>\n", 1030 1068 /* translators: %s: Post custom field name */ 1031 1069 sprintf( _x( '%s:', 'Post custom field name' ), $key ), … … 1085 1123 function wp_dropdown_pages( $args = '' ) { 1086 1124 $defaults = array( 1087 'depth' => 0, 'child_of' => 0, 1088 'selected' => 0, 'echo' => 1, 1089 'name' => 'page_id', 'id' => '', 1090 'class' => '', 1091 'show_option_none' => '', 'show_option_no_change' => '', 1092 'option_none_value' => '', 1093 'value_field' => 'ID', 1125 'depth' => 0, 1126 'child_of' => 0, 1127 'selected' => 0, 1128 'echo' => 1, 1129 'name' => 'page_id', 1130 'id' => '', 1131 'class' => '', 1132 'show_option_none' => '', 1133 'show_option_no_change' => '', 1134 'option_none_value' => '', 1135 'value_field' => 'ID', 1094 1136 ); 1095 1137 1096 1138 $r = wp_parse_args( $args, $defaults ); 1097 1139 1098 $pages = get_pages( $r );1140 $pages = get_pages( $r ); 1099 1141 $output = ''; 1100 1142 // Back-compat with old system where both id and name were based on $name argument … … 1129 1171 * @param array $r The parsed arguments array. 1130 1172 * @param array $pages List of WP_Post objects returned by `get_pages()` 1131 1173 */ 1132 1174 $html = apply_filters( 'wp_dropdown_pages', $output, $r, $pages ); 1133 1175 … … 1202 1244 } 1203 1245 1204 $output = '';1246 $output = ''; 1205 1247 $current_page = 0; 1206 1248 … … 1222 1264 // Query pages. 1223 1265 $r['hierarchical'] = 0; 1224 $pages = get_pages( $r );1266 $pages = get_pages( $r ); 1225 1267 1226 1268 if ( ! empty( $pages ) ) { … … 1311 1353 'walker' => '', 1312 1354 ); 1313 $args = wp_parse_args( $args, $defaults );1355 $args = wp_parse_args( $args, $defaults ); 1314 1356 1315 1357 if ( ! in_array( $args['item_spacing'], array( 'preserve', 'discard' ) ) ) { … … 1342 1384 1343 1385 // Show Home in the menu 1344 if ( ! empty( $args['show_home']) ) {1345 if ( true === $args['show_home'] || '1' === $args['show_home'] || 1 === $args['show_home'] ) 1346 $text = __( 'Home');1347 else1386 if ( ! empty( $args['show_home'] ) ) { 1387 if ( true === $args['show_home'] || '1' === $args['show_home'] || 1 === $args['show_home'] ) { 1388 $text = __( 'Home' ); 1389 } else { 1348 1390 $text = $args['show_home']; 1391 } 1349 1392 $class = ''; 1350 if ( is_front_page() && ! is_paged() )1393 if ( is_front_page() && ! is_paged() ) { 1351 1394 $class = 'class="current_page_item"'; 1395 } 1352 1396 $menu .= '<li ' . $class . '><a href="' . home_url( '/' ) . '">' . $args['link_before'] . $text . $args['link_after'] . '</a></li>'; 1353 1397 // If the front page is a page, add it to the exclude list 1354 if ( get_option('show_on_front') == 'page') {1355 if ( ! empty( $list_args['exclude'] ) ) {1398 if ( get_option( 'show_on_front' ) == 'page' ) { 1399 if ( ! empty( $list_args['exclude'] ) ) { 1356 1400 $list_args['exclude'] .= ','; 1357 1401 } else { 1358 1402 $list_args['exclude'] = ''; 1359 1403 } 1360 $list_args['exclude'] .= get_option( 'page_on_front');1361 } 1362 } 1363 1364 $list_args['echo'] = false;1404 $list_args['exclude'] .= get_option( 'page_on_front' ); 1405 } 1406 } 1407 1408 $list_args['echo'] = false; 1365 1409 $list_args['title_li'] = ''; 1366 $menu .= wp_list_pages( $list_args );1410 $menu .= wp_list_pages( $list_args ); 1367 1411 1368 1412 $container = sanitize_text_field( $args['container'] ); … … 1380 1424 'ul' !== $container ) { 1381 1425 $args['before'] = "<ul>{$n}"; 1382 $args['after'] = '</ul>';1426 $args['after'] = '</ul>'; 1383 1427 } 1384 1428 … … 1408 1452 */ 1409 1453 $menu = apply_filters( 'wp_page_menu', $menu, $args ); 1410 if ( $args['echo'] ) 1454 if ( $args['echo'] ) { 1411 1455 echo $menu; 1412 else1456 } else { 1413 1457 return $menu; 1458 } 1414 1459 } 1415 1460 … … 1431 1476 */ 1432 1477 function walk_page_tree( $pages, $depth, $current_page, $r ) { 1433 if ( empty( $r['walker']) )1478 if ( empty( $r['walker'] ) ) { 1434 1479 $walker = new Walker_Page; 1435 else1480 } else { 1436 1481 $walker = $r['walker']; 1482 } 1437 1483 1438 1484 foreach ( (array) $pages as $page ) { 1439 if ( $page->post_parent ) 1485 if ( $page->post_parent ) { 1440 1486 $r['pages_with_children'][ $page->post_parent ] = true; 1441 } 1442 1443 $args = array($pages, $depth, $r, $current_page); 1444 return call_user_func_array(array($walker, 'walk'), $args); 1487 } 1488 } 1489 1490 $args = array( $pages, $depth, $r, $current_page ); 1491 return call_user_func_array( array( $walker, 'walk' ), $args ); 1445 1492 } 1446 1493 … … 1456 1503 function walk_page_dropdown_tree() { 1457 1504 $args = func_get_args(); 1458 if ( empty( $args[2]['walker']) )// the user's options are the third parameter1505 if ( empty( $args[2]['walker'] ) ) { // the user's options are the third parameter 1459 1506 $walker = new Walker_PageDropdown; 1460 else1507 } else { 1461 1508 $walker = $args[2]['walker']; 1462 1463 return call_user_func_array(array($walker, 'walk'), $args); 1509 } 1510 1511 return call_user_func_array( array( $walker, 'walk' ), $args ); 1464 1512 } 1465 1513 … … 1479 1527 */ 1480 1528 function the_attachment_link( $id = 0, $fullsize = false, $deprecated = false, $permalink = false ) { 1481 if ( ! empty( $deprecated ) )1529 if ( ! empty( $deprecated ) ) { 1482 1530 _deprecated_argument( __FUNCTION__, '2.5.0' ); 1483 1484 if ( $fullsize ) 1485 echo wp_get_attachment_link($id, 'full', $permalink); 1486 else 1487 echo wp_get_attachment_link($id, 'thumbnail', $permalink); 1531 } 1532 1533 if ( $fullsize ) { 1534 echo wp_get_attachment_link( $id, 'full', $permalink ); 1535 } else { 1536 echo wp_get_attachment_link( $id, 'thumbnail', $permalink ); 1537 } 1488 1538 } 1489 1539 … … 1555 1605 * @return string 1556 1606 */ 1557 function prepend_attachment( $content) {1607 function prepend_attachment( $content ) { 1558 1608 $post = get_post(); 1559 1609 1560 if ( empty( $post->post_type) || $post->post_type != 'attachment' )1610 if ( empty( $post->post_type ) || $post->post_type != 'attachment' ) { 1561 1611 return $content; 1612 } 1562 1613 1563 1614 if ( wp_attachment_is( 'video', $post ) ) { … … 1565 1616 $atts = array( 'src' => wp_get_attachment_url() ); 1566 1617 if ( ! empty( $meta['width'] ) && ! empty( $meta['height'] ) ) { 1567 $atts['width'] = (int) $meta['width'];1618 $atts['width'] = (int) $meta['width']; 1568 1619 $atts['height'] = (int) $meta['height']; 1569 1620 } … … 1577 1628 $p = '<p class="attachment">'; 1578 1629 // show the medium sized image representation of the attachment if available, and link to the raw file 1579 $p .= wp_get_attachment_link( 0, 'medium', false);1630 $p .= wp_get_attachment_link( 0, 'medium', false ); 1580 1631 $p .= '</p>'; 1581 1632 } … … 1608 1659 */ 1609 1660 function get_the_password_form( $post = 0 ) { 1610 $post = get_post( $post );1611 $label = 'pwbox-' . ( empty($post->ID) ? rand() : $post->ID );1661 $post = get_post( $post ); 1662 $label = 'pwbox-' . ( empty( $post->ID ) ? rand() : $post->ID ); 1612 1663 $output = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" class="post-password-form" method="post"> 1613 1664 <p>' . __( 'This content is password protected. To view it please enter your password below:' ) . '</p> … … 1650 1701 $page_template = get_page_template_slug( get_queried_object_id() ); 1651 1702 1652 if ( empty( $template ) ) 1703 if ( empty( $template ) ) { 1653 1704 return (bool) $page_template; 1654 1655 if ( $template == $page_template ) 1705 } 1706 1707 if ( $template == $page_template ) { 1656 1708 return true; 1709 } 1657 1710 1658 1711 if ( is_array( $template ) ) { … … 1675 1728 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post. 1676 1729 * @return string|false Page template filename. Returns an empty string when the default page template 1677 * 1730 * is in use. Returns false if the post does not exist. 1678 1731 */ 1679 1732 function get_page_template_slug( $post = null ) { … … 1703 1756 */ 1704 1757 function wp_post_revision_title( $revision, $link = true ) { 1705 if ( ! $revision = get_post( $revision ) )1758 if ( ! $revision = get_post( $revision ) ) { 1706 1759 return $revision; 1707 1708 if ( !in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) ) 1760 } 1761 1762 if ( ! in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) ) { 1709 1763 return false; 1764 } 1710 1765 1711 1766 /* translators: revision date format, see https://secure.php.net/date */ … … 1714 1769 $autosavef = __( '%s [Autosave]' ); 1715 1770 /* translators: %s: revision date */ 1716 $currentf 1771 $currentf = __( '%s [Current Revision]' ); 1717 1772 1718 1773 $date = date_i18n( $datef, strtotime( $revision->post_modified ) ); 1719 if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) ) 1774 if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) ) { 1720 1775 $date = "<a href='$link'>$date</a>"; 1721 1722 if ( !wp_is_post_revision( $revision ) ) 1776 } 1777 1778 if ( ! wp_is_post_revision( $revision ) ) { 1723 1779 $date = sprintf( $currentf, $date ); 1724 elseif ( wp_is_post_autosave( $revision ) )1780 } elseif ( wp_is_post_autosave( $revision ) ) { 1725 1781 $date = sprintf( $autosavef, $date ); 1782 } 1726 1783 1727 1784 return $date; … … 1738 1795 */ 1739 1796 function wp_post_revision_title_expanded( $revision, $link = true ) { 1740 if ( ! $revision = get_post( $revision ) )1797 if ( ! $revision = get_post( $revision ) ) { 1741 1798 return $revision; 1742 1743 if ( !in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) ) 1799 } 1800 1801 if ( ! in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) ) { 1744 1802 return false; 1803 } 1745 1804 1746 1805 $author = get_the_author_meta( 'display_name', $revision->post_author ); … … 1751 1810 1752 1811 $date = date_i18n( $datef, strtotime( $revision->post_modified ) ); 1753 if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) ) 1812 if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) ) { 1754 1813 $date = "<a href='$link'>$date</a>"; 1814 } 1755 1815 1756 1816 $revision_date_author = sprintf( … … 1766 1826 $autosavef = __( '%s [Autosave]' ); 1767 1827 /* translators: %s: revision date with author avatar */ 1768 $currentf 1769 1770 if ( ! wp_is_post_revision( $revision ) )1828 $currentf = __( '%s [Current Revision]' ); 1829 1830 if ( ! wp_is_post_revision( $revision ) ) { 1771 1831 $revision_date_author = sprintf( $currentf, $revision_date_author ); 1772 elseif ( wp_is_post_autosave( $revision ) )1832 } elseif ( wp_is_post_autosave( $revision ) ) { 1773 1833 $revision_date_author = sprintf( $autosavef, $revision_date_author ); 1834 } 1774 1835 1775 1836 /** … … 1798 1859 */ 1799 1860 function wp_list_post_revisions( $post_id = 0, $type = 'all' ) { 1800 if ( ! $post = get_post( $post_id ) ) 1861 if ( ! $post = get_post( $post_id ) ) { 1801 1862 return; 1863 } 1802 1864 1803 1865 // $args array with (parent, format, right, left, type) deprecated since 3.6 1804 1866 if ( is_array( $type ) ) { 1805 $type = ! empty( $type['type'] ) ? $type['type'] 1867 $type = ! empty( $type['type'] ) ? $type['type'] : $type; 1806 1868 _deprecated_argument( __FUNCTION__, '3.6.0' ); 1807 1869 } 1808 1870 1809 if ( ! $revisions = wp_get_post_revisions( $post->ID ) ) 1871 if ( ! $revisions = wp_get_post_revisions( $post->ID ) ) { 1810 1872 return; 1873 } 1811 1874 1812 1875 $rows = ''; 1813 1876 foreach ( $revisions as $revision ) { 1814 if ( ! current_user_can( 'read_post', $revision->ID ) ) 1877 if ( ! current_user_can( 'read_post', $revision->ID ) ) { 1815 1878 continue; 1879 } 1816 1880 1817 1881 $is_autosave = wp_is_post_autosave( $revision ); 1818 if ( ( 'revision' === $type && $is_autosave ) || ( 'autosave' === $type && ! $is_autosave ) ) 1882 if ( ( 'revision' === $type && $is_autosave ) || ( 'autosave' === $type && ! $is_autosave ) ) { 1819 1883 continue; 1884 } 1820 1885 1821 1886 $rows .= "\t<li>" . wp_post_revision_title_expanded( $revision ) . "</li>\n"; … … 1826 1891 echo "<ul class='post-revisions hide-if-no-js'>\n"; 1827 1892 echo $rows; 1828 echo "</ul>";1829 } 1893 echo '</ul>'; 1894 }
Note: See TracChangeset
for help on using the changeset viewer.