Changeset 42343 for trunk/src/wp-includes/link-template.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/link-template.php (modified) (108 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/link-template.php
r42228 r42343 45 45 * @return string The URL with the trailing slash appended or stripped. 46 46 */ 47 function user_trailingslashit( $string, $type_of_url = '') {47 function user_trailingslashit( $string, $type_of_url = '' ) { 48 48 global $wp_rewrite; 49 if ( $wp_rewrite->use_trailing_slashes ) 50 $string = trailingslashit($string); 51 else 52 $string = untrailingslashit($string); 49 if ( $wp_rewrite->use_trailing_slashes ) { 50 $string = trailingslashit( $string ); 51 } else { 52 $string = untrailingslashit( $string ); 53 } 53 54 54 55 /** … … 80 81 case 'title': 81 82 $title = sanitize_title( $post->post_title ) . '-' . $post->ID; 82 echo '<a id="' .$title.'"></a>';83 echo '<a id="' . $title . '"></a>'; 83 84 break; 84 85 case 'id': … … 124 125 '%minute%', 125 126 '%second%', 126 $leavename ? '' : '%postname%',127 $leavename ? '' : '%postname%', 127 128 '%post_id%', 128 129 '%category%', 129 130 '%author%', 130 $leavename ? '' : '%pagename%',131 $leavename ? '' : '%pagename%', 131 132 ); 132 133 … … 134 135 $sample = true; 135 136 } else { 136 $post = get_post( $post );137 $post = get_post( $post ); 137 138 $sample = false; 138 139 } 139 140 140 if ( empty( $post->ID) )141 if ( empty( $post->ID ) ) { 141 142 return false; 142 143 if ( $post->post_type == 'page' ) 144 return get_page_link($post, $leavename, $sample); 145 elseif ( $post->post_type == 'attachment' ) 143 } 144 145 if ( $post->post_type == 'page' ) { 146 return get_page_link( $post, $leavename, $sample ); 147 } elseif ( $post->post_type == 'attachment' ) { 146 148 return get_attachment_link( $post, $leavename ); 147 elseif ( in_array($post->post_type, get_post_types( array('_builtin' => false) ) ) ) 148 return get_post_permalink($post, $leavename, $sample); 149 150 $permalink = get_option('permalink_structure'); 149 } elseif ( in_array( $post->post_type, get_post_types( array( '_builtin' => false ) ) ) ) { 150 return get_post_permalink( $post, $leavename, $sample ); 151 } 152 153 $permalink = get_option( 'permalink_structure' ); 151 154 152 155 /** … … 163 166 $permalink = apply_filters( 'pre_post_link', $permalink, $post, $leavename ); 164 167 165 if ( '' != $permalink && ! in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft', 'future' ) ) ) {166 $unixtime = strtotime( $post->post_date);168 if ( '' != $permalink && ! in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft', 'future' ) ) ) { 169 $unixtime = strtotime( $post->post_date ); 167 170 168 171 $category = ''; 169 if ( strpos( $permalink, '%category%') !== false ) {170 $cats = get_the_category( $post->ID);172 if ( strpos( $permalink, '%category%' ) !== false ) { 173 $cats = get_the_category( $post->ID ); 171 174 if ( $cats ) { 172 $cats = wp_list_sort( $cats, array( 173 'term_id' => 'ASC', 174 ) ); 175 $cats = wp_list_sort( 176 $cats, array( 177 'term_id' => 'ASC', 178 ) 179 ); 175 180 176 181 /** … … 186 191 187 192 $category_object = get_term( $category_object, 'category' ); 188 $category = $category_object->slug; 189 if ( $parent = $category_object->parent ) 190 $category = get_category_parents($parent, false, '/', true) . $category; 193 $category = $category_object->slug; 194 if ( $parent = $category_object->parent ) { 195 $category = get_category_parents( $parent, false, '/', true ) . $category; 196 } 191 197 } 192 198 // show default category in permalinks, without 193 199 // having to assign it explicitly 194 if ( empty( $category) ) {200 if ( empty( $category ) ) { 195 201 $default_category = get_term( get_option( 'default_category' ), 'category' ); 196 202 if ( $default_category && ! is_wp_error( $default_category ) ) { … … 201 207 202 208 $author = ''; 203 if ( strpos( $permalink, '%author%') !== false ) {204 $authordata = get_userdata( $post->post_author);205 $author = $authordata->user_nicename;206 } 207 208 $date = explode(" ",date('Y m d H i s', $unixtime));209 if ( strpos( $permalink, '%author%' ) !== false ) { 210 $authordata = get_userdata( $post->post_author ); 211 $author = $authordata->user_nicename; 212 } 213 214 $date = explode( ' ', date( 'Y m d H i s', $unixtime ) ); 209 215 $rewritereplace = 210 216 array( … … 221 227 $post->post_name, 222 228 ); 223 $permalink = home_url( str_replace($rewritecode, $rewritereplace, $permalink) );224 $permalink = user_trailingslashit($permalink, 'single');229 $permalink = home_url( str_replace( $rewritecode, $rewritereplace, $permalink ) ); 230 $permalink = user_trailingslashit( $permalink, 'single' ); 225 231 } else { // if they're not using the fancy permalink option 226 $permalink = home_url( '?p=' . $post->ID);232 $permalink = home_url( '?p=' . $post->ID ); 227 233 } 228 234 … … 256 262 global $wp_rewrite; 257 263 258 $post = get_post( $id);259 260 if ( is_wp_error( $post ) ) 264 $post = get_post( $id ); 265 266 if ( is_wp_error( $post ) ) { 261 267 return $post; 262 263 $post_link = $wp_rewrite->get_extra_permastruct($post->post_type); 268 } 269 270 $post_link = $wp_rewrite->get_extra_permastruct( $post->post_type ); 264 271 265 272 $slug = $post->post_name; … … 267 274 $draft_or_pending = get_post_status( $post ) && in_array( get_post_status( $post ), array( 'draft', 'pending', 'auto-draft', 'future' ) ); 268 275 269 $post_type = get_post_type_object( $post->post_type);276 $post_type = get_post_type_object( $post->post_type ); 270 277 271 278 if ( $post_type->hierarchical ) { … … 273 280 } 274 281 275 if ( ! empty($post_link) && ( !$draft_or_pending || $sample ) ) {282 if ( ! empty( $post_link ) && ( ! $draft_or_pending || $sample ) ) { 276 283 if ( ! $leavename ) { 277 $post_link = str_replace("%$post->post_type%", $slug, $post_link); 278 } 279 $post_link = home_url( user_trailingslashit($post_link) ); 280 } else { 281 if ( $post_type->query_var && ( isset($post->post_status) && !$draft_or_pending ) ) 282 $post_link = add_query_arg($post_type->query_var, $slug, ''); 283 else 284 $post_link = add_query_arg(array('post_type' => $post->post_type, 'p' => $post->ID), ''); 285 $post_link = home_url($post_link); 284 $post_link = str_replace( "%$post->post_type%", $slug, $post_link ); 285 } 286 $post_link = home_url( user_trailingslashit( $post_link ) ); 287 } else { 288 if ( $post_type->query_var && ( isset( $post->post_status ) && ! $draft_or_pending ) ) { 289 $post_link = add_query_arg( $post_type->query_var, $slug, '' ); 290 } else { 291 $post_link = add_query_arg( 292 array( 293 'post_type' => $post->post_type, 294 'p' => $post->ID, 295 ), '' 296 ); 297 } 298 $post_link = home_url( $post_link ); 286 299 } 287 300 … … 315 328 $post = get_post( $post ); 316 329 317 if ( 'page' == get_option( 'show_on_front' ) && $post->ID == get_option( 'page_on_front' ) ) 318 $link = home_url( '/');319 else330 if ( 'page' == get_option( 'show_on_front' ) && $post->ID == get_option( 'page_on_front' ) ) { 331 $link = home_url( '/' ); 332 } else { 320 333 $link = _get_page_link( $post, $leavename, $sample ); 334 } 321 335 322 336 /** … … 357 371 $link = $wp_rewrite->get_page_permastruct(); 358 372 359 if ( ! empty($link) && ( ( isset($post->post_status) && !$draft_or_pending ) || $sample ) ) {373 if ( ! empty( $link ) && ( ( isset( $post->post_status ) && ! $draft_or_pending ) || $sample ) ) { 360 374 if ( ! $leavename ) { 361 $link = str_replace( '%pagename%', get_page_uri( $post ), $link);362 } 363 364 $link = home_url( $link);365 $link = user_trailingslashit( $link, 'page');375 $link = str_replace( '%pagename%', get_page_uri( $post ), $link ); 376 } 377 378 $link = home_url( $link ); 379 $link = user_trailingslashit( $link, 'page' ); 366 380 } else { 367 381 $link = home_url( '?page_id=' . $post->ID ); … … 397 411 $link = false; 398 412 399 $post = get_post( $post );413 $post = get_post( $post ); 400 414 $parent = ( $post->post_parent > 0 && $post->post_parent != $post->ID ) ? get_post( $post->post_parent ) : false; 401 415 if ( $parent && ! in_array( $parent->post_type, get_post_types() ) ) { … … 404 418 405 419 if ( $wp_rewrite->using_permalinks() && $parent ) { 406 if ( 'page' == $parent->post_type ) 420 if ( 'page' == $parent->post_type ) { 407 421 $parentlink = _get_page_link( $post->post_parent ); // Ignores page_on_front 408 else422 } else { 409 423 $parentlink = get_permalink( $post->post_parent ); 410 411 if ( is_numeric($post->post_name) || false !== strpos(get_option('permalink_structure'), '%category%') ) 424 } 425 426 if ( is_numeric( $post->post_name ) || false !== strpos( get_option( 'permalink_structure' ), '%category%' ) ) { 412 427 $name = 'attachment/' . $post->post_name; // <permalink>/<int>/ is paged so we use the explicit attachment marker 413 else428 } else { 414 429 $name = $post->post_name; 415 416 if ( strpos($parentlink, '?') === false ) 417 $link = user_trailingslashit( trailingslashit($parentlink) . '%postname%' ); 418 419 if ( ! $leavename ) 430 } 431 432 if ( strpos( $parentlink, '?' ) === false ) { 433 $link = user_trailingslashit( trailingslashit( $parentlink ) . '%postname%' ); 434 } 435 436 if ( ! $leavename ) { 420 437 $link = str_replace( '%postname%', $name, $link ); 438 } 421 439 } elseif ( $wp_rewrite->using_permalinks() && ! $leavename ) { 422 440 $link = home_url( user_trailingslashit( $post->post_name ) ); 423 441 } 424 442 425 if ( ! $link ) 443 if ( ! $link ) { 426 444 $link = home_url( '/?attachment_id=' . $post->ID ); 445 } 427 446 428 447 /** … … 449 468 function get_year_link( $year ) { 450 469 global $wp_rewrite; 451 if ( !$year ) 452 $year = gmdate('Y', current_time('timestamp')); 470 if ( ! $year ) { 471 $year = gmdate( 'Y', current_time( 'timestamp' ) ); 472 } 453 473 $yearlink = $wp_rewrite->get_year_permastruct(); 454 if ( ! empty($yearlink) ) {455 $yearlink = str_replace( '%year%', $year, $yearlink);474 if ( ! empty( $yearlink ) ) { 475 $yearlink = str_replace( '%year%', $year, $yearlink ); 456 476 $yearlink = home_url( user_trailingslashit( $yearlink, 'year' ) ); 457 477 } else { … … 481 501 * @return string The permalink for the specified month and year archive. 482 502 */ 483 function get_month_link( $year, $month) {503 function get_month_link( $year, $month ) { 484 504 global $wp_rewrite; 485 if ( !$year ) 486 $year = gmdate('Y', current_time('timestamp')); 487 if ( !$month ) 488 $month = gmdate('m', current_time('timestamp')); 505 if ( ! $year ) { 506 $year = gmdate( 'Y', current_time( 'timestamp' ) ); 507 } 508 if ( ! $month ) { 509 $month = gmdate( 'm', current_time( 'timestamp' ) ); 510 } 489 511 $monthlink = $wp_rewrite->get_month_permastruct(); 490 if ( ! empty($monthlink) ) {491 $monthlink = str_replace( '%year%', $year, $monthlink);492 $monthlink = str_replace( '%monthnum%', zeroise(intval($month), 2), $monthlink);512 if ( ! empty( $monthlink ) ) { 513 $monthlink = str_replace( '%year%', $year, $monthlink ); 514 $monthlink = str_replace( '%monthnum%', zeroise( intval( $month ), 2 ), $monthlink ); 493 515 $monthlink = home_url( user_trailingslashit( $monthlink, 'month' ) ); 494 516 } else { … … 520 542 * @return string The permalink for the specified day, month, and year archive. 521 543 */ 522 function get_day_link( $year, $month, $day) {544 function get_day_link( $year, $month, $day ) { 523 545 global $wp_rewrite; 524 if ( !$year ) 525 $year = gmdate('Y', current_time('timestamp')); 526 if ( !$month ) 527 $month = gmdate('m', current_time('timestamp')); 528 if ( !$day ) 529 $day = gmdate('j', current_time('timestamp')); 546 if ( ! $year ) { 547 $year = gmdate( 'Y', current_time( 'timestamp' ) ); 548 } 549 if ( ! $month ) { 550 $month = gmdate( 'm', current_time( 'timestamp' ) ); 551 } 552 if ( ! $day ) { 553 $day = gmdate( 'j', current_time( 'timestamp' ) ); 554 } 530 555 531 556 $daylink = $wp_rewrite->get_day_permastruct(); 532 if ( ! empty($daylink) ) {533 $daylink = str_replace( '%year%', $year, $daylink);534 $daylink = str_replace( '%monthnum%', zeroise(intval($month), 2), $daylink);535 $daylink = str_replace( '%day%', zeroise(intval($day), 2), $daylink);557 if ( ! empty( $daylink ) ) { 558 $daylink = str_replace( '%year%', $year, $daylink ); 559 $daylink = str_replace( '%monthnum%', zeroise( intval( $month ), 2 ), $daylink ); 560 $daylink = str_replace( '%day%', zeroise( intval( $day ), 2 ), $daylink ); 536 561 $daylink = home_url( user_trailingslashit( $daylink, 'day' ) ); 537 562 } else { … … 590 615 $permalink = $wp_rewrite->get_feed_permastruct(); 591 616 if ( '' != $permalink ) { 592 if ( false !== strpos( $feed, 'comments_') ) {593 $feed = str_replace('comments_', '', $feed);617 if ( false !== strpos( $feed, 'comments_' ) ) { 618 $feed = str_replace( 'comments_', '', $feed ); 594 619 $permalink = $wp_rewrite->get_comment_feed_permastruct(); 595 620 } 596 621 597 if ( get_default_feed() == $feed ) 622 if ( get_default_feed() == $feed ) { 598 623 $feed = ''; 599 600 $permalink = str_replace('%feed%', $feed, $permalink); 601 $permalink = preg_replace('#/+#', '/', "/$permalink"); 602 $output = home_url( user_trailingslashit($permalink, 'feed') ); 603 } else { 604 if ( empty($feed) ) 624 } 625 626 $permalink = str_replace( '%feed%', $feed, $permalink ); 627 $permalink = preg_replace( '#/+#', '/', "/$permalink" ); 628 $output = home_url( user_trailingslashit( $permalink, 'feed' ) ); 629 } else { 630 if ( empty( $feed ) ) { 605 631 $feed = get_default_feed(); 606 607 if ( false !== strpos($feed, 'comments_') ) 608 $feed = str_replace('comments_', 'comments-', $feed); 609 610 $output = home_url("?feed={$feed}"); 632 } 633 634 if ( false !== strpos( $feed, 'comments_' ) ) { 635 $feed = str_replace( 'comments_', 'comments-', $feed ); 636 } 637 638 $output = home_url( "?feed={$feed}" ); 611 639 } 612 640 … … 634 662 $post_id = absint( $post_id ); 635 663 636 if ( ! $post_id ) 664 if ( ! $post_id ) { 637 665 $post_id = get_the_ID(); 638 639 if ( empty( $feed ) ) 666 } 667 668 if ( empty( $feed ) ) { 640 669 $feed = get_default_feed(); 641 642 $post = get_post( $post_id ); 670 } 671 672 $post = get_post( $post_id ); 643 673 $unattached = 'attachment' === $post->post_type && 0 === (int) $post->post_parent; 644 674 645 if ( '' != get_option( 'permalink_structure') ) {646 if ( 'page' == get_option( 'show_on_front') && $post_id == get_option('page_on_front') )675 if ( '' != get_option( 'permalink_structure' ) ) { 676 if ( 'page' == get_option( 'show_on_front' ) && $post_id == get_option( 'page_on_front' ) ) { 647 677 $url = _get_page_link( $post_id ); 648 else 649 $url = get_permalink($post_id); 678 } else { 679 $url = get_permalink( $post_id ); 680 } 650 681 651 682 if ( $unattached ) { 652 $url = home_url( '/feed/' );683 $url = home_url( '/feed/' ); 653 684 if ( $feed !== get_default_feed() ) { 654 685 $url .= "$feed/"; … … 656 687 $url = add_query_arg( 'attachment_id', $post_id, $url ); 657 688 } else { 658 $url = trailingslashit( $url) . 'feed';659 if ( $feed != get_default_feed() ) 689 $url = trailingslashit( $url ) . 'feed'; 690 if ( $feed != get_default_feed() ) { 660 691 $url .= "/$feed"; 661 $url = user_trailingslashit($url, 'single_feed'); 692 } 693 $url = user_trailingslashit( $url, 'single_feed' ); 662 694 } 663 695 } else { 664 696 if ( $unattached ) { 665 $url = add_query_arg( array( 'feed' => $feed, 'attachment_id' => $post_id ), home_url( '/' ) ); 697 $url = add_query_arg( 698 array( 699 'feed' => $feed, 700 'attachment_id' => $post_id, 701 ), home_url( '/' ) 702 ); 666 703 } elseif ( 'page' == $post->post_type ) { 667 $url = add_query_arg( array( 'feed' => $feed, 'page_id' => $post_id ), home_url( '/' ) ); 704 $url = add_query_arg( 705 array( 706 'feed' => $feed, 707 'page_id' => $post_id, 708 ), home_url( '/' ) 709 ); 668 710 } else { 669 $url = add_query_arg( array( 'feed' => $feed, 'p' => $post_id ), home_url( '/' ) ); 711 $url = add_query_arg( 712 array( 713 'feed' => $feed, 714 'p' => $post_id, 715 ), home_url( '/' ) 716 ); 670 717 } 671 718 } … … 697 744 $url = get_post_comments_feed_link( $post_id, $feed ); 698 745 if ( empty( $link_text ) ) { 699 $link_text = __( 'Comments Feed');746 $link_text = __( 'Comments Feed' ); 700 747 } 701 748 … … 726 773 */ 727 774 function get_author_feed_link( $author_id, $feed = '' ) { 728 $author_id = (int) $author_id;729 $permalink_structure = get_option( 'permalink_structure');730 731 if ( empty( $feed) )775 $author_id = (int) $author_id; 776 $permalink_structure = get_option( 'permalink_structure' ); 777 778 if ( empty( $feed ) ) { 732 779 $feed = get_default_feed(); 780 } 733 781 734 782 if ( '' == $permalink_structure ) { 735 $link = home_url( "?feed=$feed&author=" . $author_id);736 } else { 737 $link = get_author_posts_url( $author_id);738 if ( $feed == get_default_feed() ) 783 $link = home_url( "?feed=$feed&author=" . $author_id ); 784 } else { 785 $link = get_author_posts_url( $author_id ); 786 if ( $feed == get_default_feed() ) { 739 787 $feed_link = 'feed'; 740 else788 } else { 741 789 $feed_link = "feed/$feed"; 742 743 $link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed'); 790 } 791 792 $link = trailingslashit( $link ) . user_trailingslashit( $feed_link, 'feed' ); 744 793 } 745 794 … … 787 836 */ 788 837 function get_term_feed_link( $term_id, $taxonomy = 'category', $feed = '' ) { 789 $term_id = ( int) $term_id;790 791 $term = get_term( $term_id, $taxonomy );792 793 if ( empty( $term ) || is_wp_error( $term ) ) 838 $term_id = (int) $term_id; 839 840 $term = get_term( $term_id, $taxonomy ); 841 842 if ( empty( $term ) || is_wp_error( $term ) ) { 794 843 return false; 795 796 if ( empty( $feed ) ) 844 } 845 846 if ( empty( $feed ) ) { 797 847 $feed = get_default_feed(); 848 } 798 849 799 850 $permalink_structure = get_option( 'permalink_structure' ); … … 801 852 if ( '' == $permalink_structure ) { 802 853 if ( 'category' == $taxonomy ) { 803 $link = home_url("?feed=$feed&cat=$term_id"); 804 } 805 elseif ( 'post_tag' == $taxonomy ) { 806 $link = home_url("?feed=$feed&tag=$term->slug"); 854 $link = home_url( "?feed=$feed&cat=$term_id" ); 855 } elseif ( 'post_tag' == $taxonomy ) { 856 $link = home_url( "?feed=$feed&tag=$term->slug" ); 807 857 } else { 808 $t = get_taxonomy( $taxonomy );809 $link = home_url( "?feed=$feed&$t->query_var=$term->slug");858 $t = get_taxonomy( $taxonomy ); 859 $link = home_url( "?feed=$feed&$t->query_var=$term->slug" ); 810 860 } 811 861 } else { 812 862 $link = get_term_link( $term_id, $term->taxonomy ); 813 if ( $feed == get_default_feed() ) 863 if ( $feed == get_default_feed() ) { 814 864 $feed_link = 'feed'; 815 else865 } else { 816 866 $feed_link = "feed/$feed"; 867 } 817 868 818 869 $link = trailingslashit( $link ) . user_trailingslashit( $feed_link, 'feed' ); … … 980 1031 */ 981 1032 function edit_term_link( $link = '', $before = '', $after = '', $term = null, $echo = true ) { 982 if ( is_null( $term ) ) 1033 if ( is_null( $term ) ) { 983 1034 $term = get_queried_object(); 984 985 if ( ! $term ) 1035 } 1036 1037 if ( ! $term ) { 986 1038 return; 1039 } 987 1040 988 1041 $tax = get_taxonomy( $term->taxonomy ); … … 991 1044 } 992 1045 993 if ( empty( $link ) ) 994 $link = __('Edit This'); 1046 if ( empty( $link ) ) { 1047 $link = __( 'Edit This' ); 1048 } 995 1049 996 1050 $link = '<a href="' . get_edit_term_link( $term->term_id, $term->taxonomy ) . '">' . $link . '</a>'; … … 1006 1060 $link = $before . apply_filters( 'edit_term_link', $link, $term->term_id ) . $after; 1007 1061 1008 if ( $echo ) 1062 if ( $echo ) { 1009 1063 echo $link; 1010 else1064 } else { 1011 1065 return $link; 1066 } 1012 1067 } 1013 1068 … … 1025 1080 global $wp_rewrite; 1026 1081 1027 if ( empty( $query) )1082 if ( empty( $query ) ) { 1028 1083 $search = get_search_query( false ); 1029 else 1030 $search = stripslashes($query); 1084 } else { 1085 $search = stripslashes( $query ); 1086 } 1031 1087 1032 1088 $permastruct = $wp_rewrite->get_search_permastruct(); 1033 1089 1034 1090 if ( empty( $permastruct ) ) { 1035 $link = home_url( '?s=' . urlencode($search) );1036 } else { 1037 $search = urlencode( $search);1038 $search = str_replace( '%2F', '/', $search); // %2F(/) is not valid within a URL, send it un-encoded.1039 $link = str_replace( '%search%', $search, $permastruct );1040 $link = home_url( user_trailingslashit( $link, 'search' ) );1091 $link = home_url( '?s=' . urlencode( $search ) ); 1092 } else { 1093 $search = urlencode( $search ); 1094 $search = str_replace( '%2F', '/', $search ); // %2F(/) is not valid within a URL, send it un-encoded. 1095 $link = str_replace( '%search%', $search, $permastruct ); 1096 $link = home_url( user_trailingslashit( $link, 'search' ) ); 1041 1097 } 1042 1098 … … 1063 1119 * @return string The search results feed permalink. 1064 1120 */ 1065 function get_search_feed_link( $search_query = '', $feed = '') {1121 function get_search_feed_link( $search_query = '', $feed = '' ) { 1066 1122 global $wp_rewrite; 1067 $link = get_search_link( $search_query);1068 1069 if ( empty( $feed) )1123 $link = get_search_link( $search_query ); 1124 1125 if ( empty( $feed ) ) { 1070 1126 $feed = get_default_feed(); 1127 } 1071 1128 1072 1129 $permastruct = $wp_rewrite->get_search_permastruct(); 1073 1130 1074 if ( empty( $permastruct) ) {1075 $link = add_query_arg( 'feed', $feed, $link);1076 } else { 1077 $link = trailingslashit($link);1131 if ( empty( $permastruct ) ) { 1132 $link = add_query_arg( 'feed', $feed, $link ); 1133 } else { 1134 $link = trailingslashit( $link ); 1078 1135 $link .= "feed/$feed/"; 1079 1136 } … … 1102 1159 * @return string The comments feed search results permalink. 1103 1160 */ 1104 function get_search_comments_feed_link( $search_query = '', $feed = '') {1161 function get_search_comments_feed_link( $search_query = '', $feed = '' ) { 1105 1162 global $wp_rewrite; 1106 1163 1107 if ( empty( $feed) )1164 if ( empty( $feed ) ) { 1108 1165 $feed = get_default_feed(); 1109 1110 $link = get_search_feed_link($search_query, $feed); 1166 } 1167 1168 $link = get_search_feed_link( $search_query, $feed ); 1111 1169 1112 1170 $permastruct = $wp_rewrite->get_search_permastruct(); 1113 1171 1114 if ( empty($permastruct) ) 1115 $link = add_query_arg('feed', 'comments-' . $feed, $link); 1116 else 1117 $link = add_query_arg('withcomments', 1, $link); 1172 if ( empty( $permastruct ) ) { 1173 $link = add_query_arg( 'feed', 'comments-' . $feed, $link ); 1174 } else { 1175 $link = add_query_arg( 'withcomments', 1, $link ); 1176 } 1118 1177 1119 1178 /** This filter is documented in wp-includes/link-template.php */ … … 1134 1193 function get_post_type_archive_link( $post_type ) { 1135 1194 global $wp_rewrite; 1136 if ( ! $post_type_obj = get_post_type_object( $post_type ) ) 1195 if ( ! $post_type_obj = get_post_type_object( $post_type ) ) { 1137 1196 return false; 1197 } 1138 1198 1139 1199 if ( 'post' === $post_type ) { 1140 $show_on_front = get_option( 'show_on_front' );1141 $page_for_posts = get_option( 'page_for_posts' );1200 $show_on_front = get_option( 'show_on_front' ); 1201 $page_for_posts = get_option( 'page_for_posts' ); 1142 1202 1143 1203 if ( 'page' == $show_on_front && $page_for_posts ) { … … 1150 1210 } 1151 1211 1152 if ( ! $post_type_obj->has_archive ) 1212 if ( ! $post_type_obj->has_archive ) { 1153 1213 return false; 1214 } 1154 1215 1155 1216 if ( get_option( 'permalink_structure' ) && is_array( $post_type_obj->rewrite ) ) { 1156 1217 $struct = ( true === $post_type_obj->has_archive ) ? $post_type_obj->rewrite['slug'] : $post_type_obj->has_archive; 1157 if ( $post_type_obj->rewrite['with_front'] ) 1218 if ( $post_type_obj->rewrite['with_front'] ) { 1158 1219 $struct = $wp_rewrite->front . $struct; 1159 else1220 } else { 1160 1221 $struct = $wp_rewrite->root . $struct; 1222 } 1161 1223 $link = home_url( user_trailingslashit( $struct, 'post_type_archive' ) ); 1162 1224 } else { … … 1186 1248 function get_post_type_archive_feed_link( $post_type, $feed = '' ) { 1187 1249 $default_feed = get_default_feed(); 1188 if ( empty( $feed ) ) 1250 if ( empty( $feed ) ) { 1189 1251 $feed = $default_feed; 1190 1191 if ( ! $link = get_post_type_archive_link( $post_type ) ) 1252 } 1253 1254 if ( ! $link = get_post_type_archive_link( $post_type ) ) { 1192 1255 return false; 1256 } 1193 1257 1194 1258 $post_type_obj = get_post_type_object( $post_type ); 1195 1259 if ( get_option( 'permalink_structure' ) && is_array( $post_type_obj->rewrite ) && $post_type_obj->rewrite['feeds'] ) { 1196 $link = trailingslashit( $link );1260 $link = trailingslashit( $link ); 1197 1261 $link .= 'feed/'; 1198 if ( $feed != $default_feed ) 1262 if ( $feed != $default_feed ) { 1199 1263 $link .= "$feed/"; 1264 } 1200 1265 } else { 1201 1266 $link = add_query_arg( 'feed', $feed, $link ); … … 1240 1305 1241 1306 $query_args['preview'] = 'true'; 1242 $preview_link = add_query_arg( $query_args, $preview_link );1307 $preview_link = add_query_arg( $query_args, $preview_link ); 1243 1308 } 1244 1309 … … 1269 1334 */ 1270 1335 function get_edit_post_link( $id = 0, $context = 'display' ) { 1271 if ( ! $post = get_post( $id ) ) 1336 if ( ! $post = get_post( $id ) ) { 1272 1337 return; 1273 1274 if ( 'revision' === $post->post_type ) 1338 } 1339 1340 if ( 'revision' === $post->post_type ) { 1275 1341 $action = ''; 1276 elseif ( 'display' == $context )1342 } elseif ( 'display' == $context ) { 1277 1343 $action = '&action=edit'; 1278 else1344 } else { 1279 1345 $action = '&action=edit'; 1346 } 1280 1347 1281 1348 $post_type_object = get_post_type_object( $post->post_type ); 1282 if ( ! $post_type_object )1349 if ( ! $post_type_object ) { 1283 1350 return; 1284 1285 if ( !current_user_can( 'edit_post', $post->ID ) ) 1351 } 1352 1353 if ( ! current_user_can( 'edit_post', $post->ID ) ) { 1286 1354 return; 1355 } 1287 1356 1288 1357 if ( $post_type_object->_edit_link ) { … … 1357 1426 */ 1358 1427 function get_delete_post_link( $id = 0, $deprecated = '', $force_delete = false ) { 1359 if ( ! empty( $deprecated ) ) 1428 if ( ! empty( $deprecated ) ) { 1360 1429 _deprecated_argument( __FUNCTION__, '3.0.0' ); 1361 1362 if ( !$post = get_post( $id ) ) 1430 } 1431 1432 if ( ! $post = get_post( $id ) ) { 1363 1433 return; 1434 } 1364 1435 1365 1436 $post_type_object = get_post_type_object( $post->post_type ); 1366 if ( ! $post_type_object )1437 if ( ! $post_type_object ) { 1367 1438 return; 1368 1369 if ( !current_user_can( 'delete_post', $post->ID ) ) 1439 } 1440 1441 if ( ! current_user_can( 'delete_post', $post->ID ) ) { 1370 1442 return; 1371 1372 $action = ( $force_delete || !EMPTY_TRASH_DAYS ) ? 'delete' : 'trash'; 1443 } 1444 1445 $action = ( $force_delete || ! EMPTY_TRASH_DAYS ) ? 'delete' : 'trash'; 1373 1446 1374 1447 $delete_link = add_query_arg( 'action', $action, admin_url( sprintf( $post_type_object->_edit_link, $post->ID ) ) ); … … 1397 1470 $comment = get_comment( $comment_id ); 1398 1471 1399 if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) )1472 if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) { 1400 1473 return; 1401 1402 $location = admin_url('comment.php?action=editcomment&c=') . $comment->comment_ID; 1474 } 1475 1476 $location = admin_url( 'comment.php?action=editcomment&c=' ) . $comment->comment_ID; 1403 1477 1404 1478 /** … … 1457 1531 $link = get_bookmark( $link ); 1458 1532 1459 if ( ! current_user_can('manage_links') )1533 if ( ! current_user_can( 'manage_links' ) ) { 1460 1534 return; 1461 1462 $location = admin_url('link.php?action=edit&link_id=') . $link->link_id; 1535 } 1536 1537 $location = admin_url( 'link.php?action=edit&link_id=' ) . $link->link_id; 1463 1538 1464 1539 /** … … 1484 1559 */ 1485 1560 function edit_bookmark_link( $link = '', $before = '', $after = '', $bookmark = null ) { 1486 $bookmark = get_bookmark( $bookmark);1487 1488 if ( ! current_user_can('manage_links') )1561 $bookmark = get_bookmark( $bookmark ); 1562 1563 if ( ! current_user_can( 'manage_links' ) ) { 1489 1564 return; 1490 1491 if ( empty($link) ) 1492 $link = __('Edit This'); 1565 } 1566 1567 if ( empty( $link ) ) { 1568 $link = __( 'Edit This' ); 1569 } 1493 1570 1494 1571 $link = '<a href="' . esc_url( get_edit_bookmark_link( $bookmark ) ) . '">' . $link . '</a>'; … … 1514 1591 */ 1515 1592 function get_edit_user_link( $user_id = null ) { 1516 if ( ! $user_id ) 1593 if ( ! $user_id ) { 1517 1594 $user_id = get_current_user_id(); 1518 1519 if ( empty( $user_id ) || ! current_user_can( 'edit_user', $user_id ) ) 1595 } 1596 1597 if ( empty( $user_id ) || ! current_user_can( 'edit_user', $user_id ) ) { 1520 1598 return ''; 1599 } 1521 1600 1522 1601 $user = get_userdata( $user_id ); 1523 1602 1524 if ( ! $user ) 1603 if ( ! $user ) { 1525 1604 return ''; 1526 1527 if ( get_current_user_id() == $user->ID ) 1605 } 1606 1607 if ( get_current_user_id() == $user->ID ) { 1528 1608 $link = get_edit_profile_url( $user->ID ); 1529 else1609 } else { 1530 1610 $link = add_query_arg( 'user_id', $user->ID, self_admin_url( 'user-edit.php' ) ); 1611 } 1531 1612 1532 1613 /** … … 1592 1673 global $wpdb; 1593 1674 1594 if ( ( ! $post = get_post() ) || ! taxonomy_exists( $taxonomy ) ) 1675 if ( ( ! $post = get_post() ) || ! taxonomy_exists( $taxonomy ) ) { 1595 1676 return null; 1677 } 1596 1678 1597 1679 $current_post_date = $post->post_date; 1598 1680 1599 $join = '';1600 $where = '';1681 $join = ''; 1682 $where = ''; 1601 1683 $adjacent = $previous ? 'previous' : 'next'; 1602 1684 … … 1615 1697 1616 1698 if ( $in_same_term ) { 1617 $join .= " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id";1618 $where .= $wpdb->prepare( "AND tt.taxonomy = %s", $taxonomy );1619 1620 if ( ! is_object_in_taxonomy( $post->post_type, $taxonomy ) ) 1699 $join .= " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id"; 1700 $where .= $wpdb->prepare( 'AND tt.taxonomy = %s', $taxonomy ); 1701 1702 if ( ! is_object_in_taxonomy( $post->post_type, $taxonomy ) ) { 1621 1703 return ''; 1704 } 1622 1705 $term_array = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) ); 1623 1706 … … 1626 1709 $term_array = array_map( 'intval', $term_array ); 1627 1710 1628 if ( ! $term_array || is_wp_error( $term_array ) ) 1711 if ( ! $term_array || is_wp_error( $term_array ) ) { 1629 1712 return ''; 1630 1631 $where .= " AND tt.term_id IN (" . implode( ',', $term_array ) . ")"; 1713 } 1714 1715 $where .= ' AND tt.term_id IN (' . implode( ',', $term_array ) . ')'; 1632 1716 } 1633 1717 … … 1666 1750 */ 1667 1751 $private_states = get_post_stati( array( 'private' => true ) ); 1668 $where .= " AND ( p.post_status = 'publish'";1752 $where .= " AND ( p.post_status = 'publish'"; 1669 1753 foreach ( (array) $private_states as $state ) { 1670 1754 if ( current_user_can( $read_private_cap ) ) { 1671 $where .= $wpdb->prepare( " OR p.post_status = %s", $state );1755 $where .= $wpdb->prepare( ' OR p.post_status = %s', $state ); 1672 1756 } else { 1673 $where .= $wpdb->prepare( " OR (p.post_author = %d AND p.post_status = %s)", $user_id, $state );1757 $where .= $wpdb->prepare( ' OR (p.post_author = %d AND p.post_status = %s)', $user_id, $state ); 1674 1758 } 1675 1759 } 1676 $where .= " )";1760 $where .= ' )'; 1677 1761 } else { 1678 1762 $where .= " AND p.post_status = 'publish'"; 1679 1763 } 1680 1764 1681 $op = $previous ? '<' : '>';1765 $op = $previous ? '<' : '>'; 1682 1766 $order = $previous ? 'DESC' : 'ASC'; 1683 1767 … … 1730 1814 * @param string $order Sort order. 'DESC' for previous post, 'ASC' for next. 1731 1815 */ 1732 $sort = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1", $post, $order );1733 1734 $query = "SELECT p.ID FROM $wpdb->posts AS p $join $where $sort";1816 $sort = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1", $post, $order ); 1817 1818 $query = "SELECT p.ID FROM $wpdb->posts AS p $join $where $sort"; 1735 1819 $query_key = 'adjacent_post_' . md5( $query ); 1736 $result = wp_cache_get( $query_key, 'counts' );1820 $result = wp_cache_get( $query_key, 'counts' ); 1737 1821 if ( false !== $result ) { 1738 if ( $result ) 1822 if ( $result ) { 1739 1823 $result = get_post( $result ); 1824 } 1740 1825 return $result; 1741 1826 } 1742 1827 1743 1828 $result = $wpdb->get_var( $query ); 1744 if ( null === $result ) 1829 if ( null === $result ) { 1745 1830 $result = ''; 1831 } 1746 1832 1747 1833 wp_cache_set( $query_key, $result, 'counts' ); 1748 1834 1749 if ( $result ) 1835 if ( $result ) { 1750 1836 $result = get_post( $result ); 1837 } 1751 1838 1752 1839 return $result; … … 1768 1855 */ 1769 1856 function get_adjacent_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) { 1770 if ( $previous && is_attachment() && $post = get_post() ) 1857 if ( $previous && is_attachment() && $post = get_post() ) { 1771 1858 $post = get_post( $post->post_parent ); 1772 else1859 } else { 1773 1860 $post = get_adjacent_post( $in_same_term, $excluded_terms, $previous, $taxonomy ); 1774 1775 if ( empty( $post ) ) 1861 } 1862 1863 if ( empty( $post ) ) { 1776 1864 return; 1777 1778 $post_title = the_title_attribute( array( 'echo' => false, 'post' => $post ) ); 1779 1780 if ( empty( $post_title ) ) 1865 } 1866 1867 $post_title = the_title_attribute( 1868 array( 1869 'echo' => false, 1870 'post' => $post, 1871 ) 1872 ); 1873 1874 if ( empty( $post_title ) ) { 1781 1875 $post_title = $previous ? __( 'Previous Post' ) : __( 'Next Post' ); 1876 } 1782 1877 1783 1878 $date = mysql2date( get_option( 'date_format' ), $post->post_date ); … … 1786 1881 $title = str_replace( '%date', $date, $title ); 1787 1882 1788 $link = $previous ? "<link rel='prev' title='" : "<link rel='next' title='";1883 $link = $previous ? "<link rel='prev' title='" : "<link rel='next' title='"; 1789 1884 $link .= esc_attr( $title ); 1790 1885 $link .= "' href='" . get_permalink( $post ) . "' />\n"; … … 1887 1982 function get_boundary_post( $in_same_term = false, $excluded_terms = '', $start = true, $taxonomy = 'category' ) { 1888 1983 $post = get_post(); 1889 if ( ! $post || ! is_single() || is_attachment() || ! taxonomy_exists( $taxonomy ) ) 1984 if ( ! $post || ! is_single() || is_attachment() || ! taxonomy_exists( $taxonomy ) ) { 1890 1985 return null; 1986 } 1891 1987 1892 1988 $query_args = array( 1893 'posts_per_page' => 1,1894 'order' => $start ? 'ASC' : 'DESC',1989 'posts_per_page' => 1, 1990 'order' => $start ? 'ASC' : 'DESC', 1895 1991 'update_post_term_cache' => false, 1896 'update_post_meta_cache' => false 1992 'update_post_meta_cache' => false, 1897 1993 ); 1898 1994 … … 1900 1996 1901 1997 if ( ! is_array( $excluded_terms ) ) { 1902 if ( ! empty( $excluded_terms ) ) 1998 if ( ! empty( $excluded_terms ) ) { 1903 1999 $excluded_terms = explode( ',', $excluded_terms ); 1904 else2000 } else { 1905 2001 $excluded_terms = array(); 2002 } 1906 2003 } 1907 2004 1908 2005 if ( $in_same_term || ! empty( $excluded_terms ) ) { 1909 if ( $in_same_term ) 2006 if ( $in_same_term ) { 1910 2007 $term_array = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) ); 2008 } 1911 2009 1912 2010 if ( ! empty( $excluded_terms ) ) { … … 1915 2013 1916 2014 $inverse_terms = array(); 1917 foreach ( $excluded_terms as $excluded_term ) 2015 foreach ( $excluded_terms as $excluded_term ) { 1918 2016 $inverse_terms[] = $excluded_term * -1; 2017 } 1919 2018 $excluded_terms = $inverse_terms; 1920 2019 } 1921 2020 1922 $query_args[ 'tax_query' ] = array( array( 1923 'taxonomy' => $taxonomy, 1924 'terms' => array_merge( $term_array, $excluded_terms ) 1925 ) ); 2021 $query_args['tax_query'] = array( 2022 array( 2023 'taxonomy' => $taxonomy, 2024 'terms' => array_merge( $term_array, $excluded_terms ), 2025 ), 2026 ); 1926 2027 } 1927 2028 … … 2010 2111 */ 2011 2112 function get_adjacent_post_link( $format, $link, $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) { 2012 if ( $previous && is_attachment() ) 2113 if ( $previous && is_attachment() ) { 2013 2114 $post = get_post( get_post()->post_parent ); 2014 else2115 } else { 2015 2116 $post = get_adjacent_post( $in_same_term, $excluded_terms, $previous, $taxonomy ); 2117 } 2016 2118 2017 2119 if ( ! $post ) { … … 2020 2122 $title = $post->post_title; 2021 2123 2022 if ( empty( $post->post_title ) ) 2124 if ( empty( $post->post_title ) ) { 2023 2125 $title = $previous ? __( 'Previous Post' ) : __( 'Next Post' ); 2126 } 2024 2127 2025 2128 /** This filter is documented in wp-includes/post-template.php */ … … 2027 2130 2028 2131 $date = mysql2date( get_option( 'date_format' ), $post->post_date ); 2029 $rel = $previous ? 'prev' : 'next';2030 2031 $string = '<a href="' . get_permalink( $post ) . '" rel="' .$rel.'">';2132 $rel = $previous ? 'prev' : 'next'; 2133 2134 $string = '<a href="' . get_permalink( $post ) . '" rel="' . $rel . '">'; 2032 2135 $inlink = str_replace( '%title', $title, $link ); 2033 2136 $inlink = str_replace( '%date', $date, $inlink ); … … 2084 2187 * @param int $pagenum Optional. Page ID. Default 1. 2085 2188 * @param bool $escape Optional. Whether to escape the URL for display, with esc_url(). Defaults to true. 2086 * Otherwise, prepares the URL with esc_url_raw().2189 * Otherwise, prepares the URL with esc_url_raw(). 2087 2190 * @return string The link URL for the given page number. 2088 2191 */ 2089 function get_pagenum_link( $pagenum = 1, $escape = true ) {2192 function get_pagenum_link( $pagenum = 1, $escape = true ) { 2090 2193 global $wp_rewrite; 2091 2194 … … 2094 2197 $request = remove_query_arg( 'paged' ); 2095 2198 2096 $home_root = parse_url( home_url());2097 $home_root = ( isset( $home_root['path']) ) ? $home_root['path'] : '';2199 $home_root = parse_url( home_url() ); 2200 $home_root = ( isset( $home_root['path'] ) ) ? $home_root['path'] : ''; 2098 2201 $home_root = preg_quote( $home_root, '|' ); 2099 2202 2100 $request = preg_replace( '|^'. $home_root . '|i', '', $request);2101 $request = preg_replace( '|^/+|', '', $request);2102 2103 if ( ! $wp_rewrite->using_permalinks() || is_admin() ) {2203 $request = preg_replace( '|^' . $home_root . '|i', '', $request ); 2204 $request = preg_replace( '|^/+|', '', $request ); 2205 2206 if ( ! $wp_rewrite->using_permalinks() || is_admin() ) { 2104 2207 $base = trailingslashit( get_bloginfo( 'url' ) ); 2105 2208 … … 2113 2216 preg_match( $qs_regex, $request, $qs_match ); 2114 2217 2115 if ( ! empty( $qs_match[0] ) ) {2218 if ( ! empty( $qs_match[0] ) ) { 2116 2219 $query_string = $qs_match[0]; 2117 $request = preg_replace( $qs_regex, '', $request );2220 $request = preg_replace( $qs_regex, '', $request ); 2118 2221 } else { 2119 2222 $query_string = ''; 2120 2223 } 2121 2224 2122 $request = preg_replace( "|$wp_rewrite->pagination_base/\d+/?$|", '', $request );2123 $request = preg_replace( '|^' . preg_quote( $wp_rewrite->index, '|' ) . '|i', '', $request );2124 $request = ltrim( $request, '/');2225 $request = preg_replace( "|$wp_rewrite->pagination_base/\d+/?$|", '', $request ); 2226 $request = preg_replace( '|^' . preg_quote( $wp_rewrite->index, '|' ) . '|i', '', $request ); 2227 $request = ltrim( $request, '/' ); 2125 2228 2126 2229 $base = trailingslashit( get_bloginfo( 'url' ) ); 2127 2230 2128 if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' != $request ) ) 2231 if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' != $request ) ) { 2129 2232 $base .= $wp_rewrite->index . '/'; 2233 } 2130 2234 2131 2235 if ( $pagenum > 1 ) { 2132 $request = ( ( ! empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( $wp_rewrite->pagination_base . "/". $pagenum, 'paged' );2236 $request = ( ( ! empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( $wp_rewrite->pagination_base . '/' . $pagenum, 'paged' ); 2133 2237 } 2134 2238 … … 2145 2249 $result = apply_filters( 'get_pagenum_link', $result ); 2146 2250 2147 if ( $escape ) 2251 if ( $escape ) { 2148 2252 return esc_url( $result ); 2149 else2253 } else { 2150 2254 return esc_url_raw( $result ); 2255 } 2151 2256 } 2152 2257 … … 2163 2268 * @return string|void The link URL for next posts page. 2164 2269 */ 2165 function get_next_posts_page_link( $max_page = 0) {2270 function get_next_posts_page_link( $max_page = 0 ) { 2166 2271 global $paged; 2167 2272 2168 if ( ! is_single() ) {2169 if ( ! $paged )2273 if ( ! is_single() ) { 2274 if ( ! $paged ) { 2170 2275 $paged = 1; 2171 $nextpage = intval($paged) + 1; 2172 if ( !$max_page || $max_page >= $nextpage ) 2173 return get_pagenum_link($nextpage); 2276 } 2277 $nextpage = intval( $paged ) + 1; 2278 if ( ! $max_page || $max_page >= $nextpage ) { 2279 return get_pagenum_link( $nextpage ); 2280 } 2174 2281 } 2175 2282 } … … 2187 2294 $output = esc_url( get_next_posts_page_link( $max_page ) ); 2188 2295 2189 if ( $echo ) 2296 if ( $echo ) { 2190 2297 echo $output; 2191 else2298 } else { 2192 2299 return $output; 2300 } 2193 2301 } 2194 2302 … … 2208 2316 global $paged, $wp_query; 2209 2317 2210 if ( ! $max_page )2318 if ( ! $max_page ) { 2211 2319 $max_page = $wp_query->max_num_pages; 2212 2213 if ( !$paged ) 2320 } 2321 2322 if ( ! $paged ) { 2214 2323 $paged = 1; 2215 2216 $nextpage = intval($paged) + 1; 2217 2218 if ( null === $label ) 2324 } 2325 2326 $nextpage = intval( $paged ) + 1; 2327 2328 if ( null === $label ) { 2219 2329 $label = __( 'Next Page »' ); 2220 2221 if ( !is_single() && ( $nextpage <= $max_page ) ) { 2330 } 2331 2332 if ( ! is_single() && ( $nextpage <= $max_page ) ) { 2222 2333 /** 2223 2334 * Filters the anchor tag attributes for the next posts page link. … … 2229 2340 $attr = apply_filters( 'next_posts_link_attributes', '' ); 2230 2341 2231 return '<a href="' . next_posts( $max_page, false ) . "\" $attr>" . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $label) . '</a>';2342 return '<a href="' . next_posts( $max_page, false ) . "\" $attr>" . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $label ) . '</a>'; 2232 2343 } 2233 2344 } … … 2261 2372 global $paged; 2262 2373 2263 if ( ! is_single() ) {2264 $nextpage = intval( $paged) - 1;2265 if ( $nextpage < 1 ) 2374 if ( ! is_single() ) { 2375 $nextpage = intval( $paged ) - 1; 2376 if ( $nextpage < 1 ) { 2266 2377 $nextpage = 1; 2267 return get_pagenum_link($nextpage); 2378 } 2379 return get_pagenum_link( $nextpage ); 2268 2380 } 2269 2381 } … … 2280 2392 $output = esc_url( get_previous_posts_page_link() ); 2281 2393 2282 if ( $echo ) 2394 if ( $echo ) { 2283 2395 echo $output; 2284 else2396 } else { 2285 2397 return $output; 2398 } 2286 2399 } 2287 2400 … … 2299 2412 global $paged; 2300 2413 2301 if ( null === $label ) 2414 if ( null === $label ) { 2302 2415 $label = __( '« Previous Page' ); 2303 2304 if ( !is_single() && $paged > 1 ) { 2416 } 2417 2418 if ( ! is_single() && $paged > 1 ) { 2305 2419 /** 2306 2420 * Filters the anchor tag attributes for the previous posts page link. … … 2311 2425 */ 2312 2426 $attr = apply_filters( 'previous_posts_link_attributes', '' ); 2313 return '<a href="' . previous_posts( false ) . "\" $attr>" . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $label ) .'</a>';2427 return '<a href="' . previous_posts( false ) . "\" $attr>" . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $label ) . '</a>'; 2314 2428 } 2315 2429 } … … 2349 2463 $return = ''; 2350 2464 2351 if ( ! is_singular() ) {2465 if ( ! is_singular() ) { 2352 2466 $defaults = array( 2353 'sep' => ' — ',2354 'prelabel' => __( '« Previous Page'),2355 'nxtlabel' => __( 'Next Page »'),2467 'sep' => ' — ', 2468 'prelabel' => __( '« Previous Page' ), 2469 'nxtlabel' => __( 'Next Page »' ), 2356 2470 ); 2357 $args = wp_parse_args( $args, $defaults );2471 $args = wp_parse_args( $args, $defaults ); 2358 2472 2359 2473 $max_num_pages = $wp_query->max_num_pages; 2360 $paged = get_query_var('paged');2474 $paged = get_query_var( 'paged' ); 2361 2475 2362 2476 //only have sep if there's both prev and next results 2363 if ( $paged < 2 || $paged >= $max_num_pages) {2477 if ( $paged < 2 || $paged >= $max_num_pages ) { 2364 2478 $args['sep'] = ''; 2365 2479 } 2366 2480 2367 2481 if ( $max_num_pages > 1 ) { 2368 $return = get_previous_posts_link($args['prelabel']);2369 $return .= preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $args['sep']);2370 $return .= get_next_posts_link( $args['nxtlabel']);2482 $return = get_previous_posts_link( $args['prelabel'] ); 2483 $return .= preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $args['sep'] ); 2484 $return .= get_next_posts_link( $args['nxtlabel'] ); 2371 2485 } 2372 2486 } … … 2385 2499 */ 2386 2500 function posts_nav_link( $sep = '', $prelabel = '', $nxtlabel = '' ) { 2387 $args = array_filter( compact( 'sep', 'prelabel', 'nxtlabel') );2388 echo get_posts_nav_link( $args);2501 $args = array_filter( compact( 'sep', 'prelabel', 'nxtlabel' ) ); 2502 echo get_posts_nav_link( $args ); 2389 2503 } 2390 2504 … … 2408 2522 */ 2409 2523 function get_the_post_navigation( $args = array() ) { 2410 $args = wp_parse_args( $args, array( 2411 'prev_text' => '%title', 2412 'next_text' => '%title', 2413 'in_same_term' => false, 2414 'excluded_terms' => '', 2415 'taxonomy' => 'category', 2416 'screen_reader_text' => __( 'Post navigation' ), 2417 ) ); 2524 $args = wp_parse_args( 2525 $args, array( 2526 'prev_text' => '%title', 2527 'next_text' => '%title', 2528 'in_same_term' => false, 2529 'excluded_terms' => '', 2530 'taxonomy' => 'category', 2531 'screen_reader_text' => __( 'Post navigation' ), 2532 ) 2533 ); 2418 2534 2419 2535 $navigation = ''; … … 2479 2595 // Don't print empty markup if there's only one page. 2480 2596 if ( $GLOBALS['wp_query']->max_num_pages > 1 ) { 2481 $args = wp_parse_args( $args, array( 2482 'prev_text' => __( 'Older posts' ), 2483 'next_text' => __( 'Newer posts' ), 2484 'screen_reader_text' => __( 'Posts navigation' ), 2485 ) ); 2597 $args = wp_parse_args( 2598 $args, array( 2599 'prev_text' => __( 'Older posts' ), 2600 'next_text' => __( 'Newer posts' ), 2601 'screen_reader_text' => __( 'Posts navigation' ), 2602 ) 2603 ); 2486 2604 2487 2605 $next_link = get_previous_posts_link( $args['next_text'] ); … … 2532 2650 // Don't print empty markup if there's only one page. 2533 2651 if ( $GLOBALS['wp_query']->max_num_pages > 1 ) { 2534 $args = wp_parse_args( $args, array( 2535 'mid_size' => 1, 2536 'prev_text' => _x( 'Previous', 'previous set of posts' ), 2537 'next_text' => _x( 'Next', 'next set of posts' ), 2538 'screen_reader_text' => __( 'Posts navigation' ), 2539 ) ); 2652 $args = wp_parse_args( 2653 $args, array( 2654 'mid_size' => 1, 2655 'prev_text' => _x( 'Previous', 'previous set of posts' ), 2656 'next_text' => _x( 'Next', 'next set of posts' ), 2657 'screen_reader_text' => __( 'Posts navigation' ), 2658 ) 2659 ); 2540 2660 2541 2661 // Make sure we get a string back. Plain is the next best thing. … … 2630 2750 $result = get_permalink(); 2631 2751 2632 if ( 'newest' == get_option( 'default_comments_page') ) {2752 if ( 'newest' == get_option( 'default_comments_page' ) ) { 2633 2753 if ( $pagenum != $max_page ) { 2634 if ( $wp_rewrite->using_permalinks() ) 2635 $result = user_trailingslashit( trailingslashit( $result) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged');2636 else2754 if ( $wp_rewrite->using_permalinks() ) { 2755 $result = user_trailingslashit( trailingslashit( $result ) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged' ); 2756 } else { 2637 2757 $result = add_query_arg( 'cpage', $pagenum, $result ); 2758 } 2638 2759 } 2639 2760 } elseif ( $pagenum > 1 ) { 2640 if ( $wp_rewrite->using_permalinks() ) 2641 $result = user_trailingslashit( trailingslashit( $result) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged');2642 else2761 if ( $wp_rewrite->using_permalinks() ) { 2762 $result = user_trailingslashit( trailingslashit( $result ) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged' ); 2763 } else { 2643 2764 $result = add_query_arg( 'cpage', $pagenum, $result ); 2765 } 2644 2766 } 2645 2767 … … 2670 2792 global $wp_query; 2671 2793 2672 if ( ! is_singular() ) 2794 if ( ! is_singular() ) { 2673 2795 return; 2674 2675 $page = get_query_var('cpage'); 2796 } 2797 2798 $page = get_query_var( 'cpage' ); 2676 2799 2677 2800 if ( ! $page ) { … … 2679 2802 } 2680 2803 2681 $nextpage = intval( $page) + 1;2682 2683 if ( empty( $max_page) )2804 $nextpage = intval( $page ) + 1; 2805 2806 if ( empty( $max_page ) ) { 2684 2807 $max_page = $wp_query->max_num_comment_pages; 2685 2686 if ( empty($max_page) ) 2808 } 2809 2810 if ( empty( $max_page ) ) { 2687 2811 $max_page = get_comment_pages_count(); 2688 2689 if ( $nextpage > $max_page ) 2812 } 2813 2814 if ( $nextpage > $max_page ) { 2690 2815 return; 2691 2692 if ( empty($label) ) 2693 $label = __('Newer Comments »'); 2816 } 2817 2818 if ( empty( $label ) ) { 2819 $label = __( 'Newer Comments »' ); 2820 } 2694 2821 2695 2822 /** … … 2700 2827 * @param string $attributes Attributes for the anchor tag. 2701 2828 */ 2702 return '<a href="' . esc_url( get_comments_pagenum_link( $nextpage, $max_page ) ) . '" ' . apply_filters( 'next_comments_link_attributes', '' ) . '>' . preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&$1', $label) .'</a>';2829 return '<a href="' . esc_url( get_comments_pagenum_link( $nextpage, $max_page ) ) . '" ' . apply_filters( 'next_comments_link_attributes', '' ) . '>' . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $label ) . '</a>'; 2703 2830 } 2704 2831 … … 2724 2851 */ 2725 2852 function get_previous_comments_link( $label = '' ) { 2726 if ( ! is_singular() ) 2853 if ( ! is_singular() ) { 2727 2854 return; 2728 2729 $page = get_query_var('cpage'); 2730 2731 if ( intval($page) <= 1 ) 2855 } 2856 2857 $page = get_query_var( 'cpage' ); 2858 2859 if ( intval( $page ) <= 1 ) { 2732 2860 return; 2733 2734 $prevpage = intval($page) - 1; 2735 2736 if ( empty($label) ) 2737 $label = __('« Older Comments'); 2861 } 2862 2863 $prevpage = intval( $page ) - 1; 2864 2865 if ( empty( $label ) ) { 2866 $label = __( '« Older Comments' ); 2867 } 2738 2868 2739 2869 /** … … 2744 2874 * @param string $attributes Attributes for the anchor tag. 2745 2875 */ 2746 return '<a href="' . esc_url( get_comments_pagenum_link( $prevpage ) ) . '" ' . apply_filters( 'previous_comments_link_attributes', '' ) . '>' . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $label) .'</a>';2876 return '<a href="' . esc_url( get_comments_pagenum_link( $prevpage ) ) . '" ' . apply_filters( 'previous_comments_link_attributes', '' ) . '>' . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $label ) . '</a>'; 2747 2877 } 2748 2878 … … 2772 2902 global $wp_rewrite; 2773 2903 2774 if ( ! is_singular() ) 2904 if ( ! is_singular() ) { 2775 2905 return; 2776 2777 $page = get_query_var('cpage'); 2778 if ( !$page ) 2906 } 2907 2908 $page = get_query_var( 'cpage' ); 2909 if ( ! $page ) { 2779 2910 $page = 1; 2911 } 2780 2912 $max_page = get_comment_pages_count(); 2781 2913 $defaults = array( 2782 'base' => add_query_arg( 'cpage', '%#%' ),2783 'format' => '',2784 'total' => $max_page,2785 'current' => $page,2786 'echo' => true,2787 'add_fragment' => '#comments' 2914 'base' => add_query_arg( 'cpage', '%#%' ), 2915 'format' => '', 2916 'total' => $max_page, 2917 'current' => $page, 2918 'echo' => true, 2919 'add_fragment' => '#comments', 2788 2920 ); 2789 if ( $wp_rewrite->using_permalinks() ) 2790 $defaults['base'] = user_trailingslashit(trailingslashit(get_permalink()) . $wp_rewrite->comments_pagination_base . '-%#%', 'commentpaged'); 2791 2792 $args = wp_parse_args( $args, $defaults ); 2921 if ( $wp_rewrite->using_permalinks() ) { 2922 $defaults['base'] = user_trailingslashit( trailingslashit( get_permalink() ) . $wp_rewrite->comments_pagination_base . '-%#%', 'commentpaged' ); 2923 } 2924 2925 $args = wp_parse_args( $args, $defaults ); 2793 2926 $page_links = paginate_links( $args ); 2794 2927 2795 if ( $args['echo'] ) 2928 if ( $args['echo'] ) { 2796 2929 echo $page_links; 2797 else2930 } else { 2798 2931 return $page_links; 2932 } 2799 2933 } 2800 2934 … … 2820 2954 // Are there comments to navigate through? 2821 2955 if ( get_comment_pages_count() > 1 ) { 2822 $args = wp_parse_args( $args, array( 2823 'prev_text' => __( 'Older comments' ), 2824 'next_text' => __( 'Newer comments' ), 2825 'screen_reader_text' => __( 'Comments navigation' ), 2826 ) ); 2956 $args = wp_parse_args( 2957 $args, array( 2958 'prev_text' => __( 'Older comments' ), 2959 'next_text' => __( 'Newer comments' ), 2960 'screen_reader_text' => __( 'Comments navigation' ), 2961 ) 2962 ); 2827 2963 2828 2964 $prev_link = get_previous_comments_link( $args['prev_text'] ); … … 2869 3005 */ 2870 3006 function get_the_comments_pagination( $args = array() ) { 2871 $navigation = ''; 2872 $args = wp_parse_args( $args, array( 2873 'screen_reader_text' => __( 'Comments navigation' ), 2874 ) ); 3007 $navigation = ''; 3008 $args = wp_parse_args( 3009 $args, array( 3010 'screen_reader_text' => __( 'Comments navigation' ), 3011 ) 3012 ); 2875 3013 $args['echo'] = false; 2876 3014 … … 2940 3078 $orig_scheme = $scheme; 2941 3079 2942 if ( empty( $blog_id ) || ! is_multisite() ) {3080 if ( empty( $blog_id ) || ! is_multisite() ) { 2943 3081 $url = get_option( 'home' ); 2944 3082 } else { … … 2949 3087 2950 3088 if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) { 2951 if ( is_ssl() && ! is_admin() && 'wp-login.php' !== $pagenow ) 3089 if ( is_ssl() && ! is_admin() && 'wp-login.php' !== $pagenow ) { 2952 3090 $scheme = 'https'; 2953 else3091 } else { 2954 3092 $scheme = parse_url( $url, PHP_URL_SCHEME ); 3093 } 2955 3094 } 2956 3095 2957 3096 $url = set_url_scheme( $url, $scheme ); 2958 3097 2959 if ( $path && is_string( $path ) ) 3098 if ( $path && is_string( $path ) ) { 2960 3099 $url .= '/' . ltrim( $path, '/' ); 3100 } 2961 3101 2962 3102 /** … … 3010 3150 */ 3011 3151 function get_site_url( $blog_id = null, $path = '', $scheme = null ) { 3012 if ( empty( $blog_id ) || ! is_multisite() ) {3152 if ( empty( $blog_id ) || ! is_multisite() ) { 3013 3153 $url = get_option( 'siteurl' ); 3014 3154 } else { … … 3020 3160 $url = set_url_scheme( $url, $scheme ); 3021 3161 3022 if ( $path && is_string( $path ) ) 3162 if ( $path && is_string( $path ) ) { 3023 3163 $url .= '/' . ltrim( $path, '/' ); 3164 } 3024 3165 3025 3166 /** … … 3064 3205 */ 3065 3206 function get_admin_url( $blog_id = null, $path = '', $scheme = 'admin' ) { 3066 $url = get_site_url( $blog_id, 'wp-admin/', $scheme);3067 3068 if ( $path && is_string( $path ) ) 3207 $url = get_site_url( $blog_id, 'wp-admin/', $scheme ); 3208 3209 if ( $path && is_string( $path ) ) { 3069 3210 $url .= ltrim( $path, '/' ); 3211 } 3070 3212 3071 3213 /** … … 3094 3236 $url = site_url( '/' . WPINC . '/', $scheme ); 3095 3237 3096 if ( $path && is_string( $path ) ) 3097 $url .= ltrim($path, '/'); 3238 if ( $path && is_string( $path ) ) { 3239 $url .= ltrim( $path, '/' ); 3240 } 3098 3241 3099 3242 /** … … 3120 3263 $url = set_url_scheme( WP_CONTENT_URL ); 3121 3264 3122 if ( $path && is_string( $path ) ) 3123 $url .= '/' . ltrim($path, '/'); 3265 if ( $path && is_string( $path ) ) { 3266 $url .= '/' . ltrim( $path, '/' ); 3267 } 3124 3268 3125 3269 /** … … 3132 3276 * if no path is specified. 3133 3277 */ 3134 return apply_filters( 'content_url', $url, $path );3278 return apply_filters( 'content_url', $url, $path ); 3135 3279 } 3136 3280 … … 3151 3295 function plugins_url( $path = '', $plugin = '' ) { 3152 3296 3153 $path = wp_normalize_path( $path );3154 $plugin = wp_normalize_path( $plugin );3297 $path = wp_normalize_path( $path ); 3298 $plugin = wp_normalize_path( $plugin ); 3155 3299 $mu_plugin_dir = wp_normalize_path( WPMU_PLUGIN_DIR ); 3156 3300 3157 if ( ! empty($plugin) && 0 === strpos($plugin, $mu_plugin_dir) )3301 if ( ! empty( $plugin ) && 0 === strpos( $plugin, $mu_plugin_dir ) ) { 3158 3302 $url = WPMU_PLUGIN_URL; 3159 else3303 } else { 3160 3304 $url = WP_PLUGIN_URL; 3161 3305 } 3162 3306 3163 3307 $url = set_url_scheme( $url ); 3164 3308 3165 if ( !empty($plugin) && is_string($plugin) ) { 3166 $folder = dirname(plugin_basename($plugin)); 3167 if ( '.' != $folder ) 3168 $url .= '/' . ltrim($folder, '/'); 3169 } 3170 3171 if ( $path && is_string( $path ) ) 3172 $url .= '/' . ltrim($path, '/'); 3309 if ( ! empty( $plugin ) && is_string( $plugin ) ) { 3310 $folder = dirname( plugin_basename( $plugin ) ); 3311 if ( '.' != $folder ) { 3312 $url .= '/' . ltrim( $folder, '/' ); 3313 } 3314 } 3315 3316 if ( $path && is_string( $path ) ) { 3317 $url .= '/' . ltrim( $path, '/' ); 3318 } 3173 3319 3174 3320 /** … … 3203 3349 */ 3204 3350 function network_site_url( $path = '', $scheme = null ) { 3205 if ( ! is_multisite() ) 3206 return site_url($path, $scheme); 3351 if ( ! is_multisite() ) { 3352 return site_url( $path, $scheme ); 3353 } 3207 3354 3208 3355 $current_network = get_network(); 3209 3356 3210 if ( 'relative' == $scheme ) 3357 if ( 'relative' == $scheme ) { 3211 3358 $url = $current_network->path; 3212 else3359 } else { 3213 3360 $url = set_url_scheme( 'http://' . $current_network->domain . $current_network->path, $scheme ); 3214 3215 if ( $path && is_string( $path ) ) 3361 } 3362 3363 if ( $path && is_string( $path ) ) { 3216 3364 $url .= ltrim( $path, '/' ); 3365 } 3217 3366 3218 3367 /** … … 3245 3394 */ 3246 3395 function network_home_url( $path = '', $scheme = null ) { 3247 if ( ! is_multisite() ) 3248 return home_url($path, $scheme); 3396 if ( ! is_multisite() ) { 3397 return home_url( $path, $scheme ); 3398 } 3249 3399 3250 3400 $current_network = get_network(); 3251 $orig_scheme = $scheme;3252 3253 if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) 3401 $orig_scheme = $scheme; 3402 3403 if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) { 3254 3404 $scheme = is_ssl() && ! is_admin() ? 'https' : 'http'; 3255 3256 if ( 'relative' == $scheme ) 3405 } 3406 3407 if ( 'relative' == $scheme ) { 3257 3408 $url = $current_network->path; 3258 else3409 } else { 3259 3410 $url = set_url_scheme( 'http://' . $current_network->domain . $current_network->path, $scheme ); 3260 3261 if ( $path && is_string( $path ) ) 3411 } 3412 3413 if ( $path && is_string( $path ) ) { 3262 3414 $url .= ltrim( $path, '/' ); 3415 } 3263 3416 3264 3417 /** … … 3273 3426 * 'relative' or null. 3274 3427 */ 3275 return apply_filters( 'network_home_url', $url, $path, $orig_scheme );3428 return apply_filters( 'network_home_url', $url, $path, $orig_scheme ); 3276 3429 } 3277 3430 … … 3287 3440 */ 3288 3441 function network_admin_url( $path = '', $scheme = 'admin' ) { 3289 if ( ! is_multisite() ) 3442 if ( ! is_multisite() ) { 3290 3443 return admin_url( $path, $scheme ); 3291 3292 $url = network_site_url('wp-admin/network/', $scheme); 3293 3294 if ( $path && is_string( $path ) ) 3295 $url .= ltrim($path, '/'); 3444 } 3445 3446 $url = network_site_url( 'wp-admin/network/', $scheme ); 3447 3448 if ( $path && is_string( $path ) ) { 3449 $url .= ltrim( $path, '/' ); 3450 } 3296 3451 3297 3452 /** … … 3318 3473 */ 3319 3474 function user_admin_url( $path = '', $scheme = 'admin' ) { 3320 $url = network_site_url('wp-admin/user/', $scheme); 3321 3322 if ( $path && is_string( $path ) ) 3323 $url .= ltrim($path, '/'); 3475 $url = network_site_url( 'wp-admin/user/', $scheme ); 3476 3477 if ( $path && is_string( $path ) ) { 3478 $url .= ltrim( $path, '/' ); 3479 } 3324 3480 3325 3481 /** … … 3389 3545 3390 3546 $url = trim( $url ); 3391 if ( substr( $url, 0, 2 ) === '//' ) 3547 if ( substr( $url, 0, 2 ) === '//' ) { 3392 3548 $url = 'http:' . $url; 3549 } 3393 3550 3394 3551 if ( 'relative' == $scheme ) { 3395 3552 $url = ltrim( preg_replace( '#^\w+://[^/]*#', '', $url ) ); 3396 if ( $url !== '' && $url[0] === '/' ) 3397 $url = '/' . ltrim($url , "/ \t\n\r\0\x0B" ); 3553 if ( $url !== '' && $url[0] === '/' ) { 3554 $url = '/' . ltrim( $url, "/ \t\n\r\0\x0B" ); 3555 } 3398 3556 } else { 3399 3557 $url = preg_replace( '#^\w+://#', $scheme . '://', $url ); … … 3433 3591 3434 3592 $blogs = get_blogs_of_user( $user_id ); 3435 if ( is_multisite() && ! user_can( $user_id, 'manage_network' ) && empty( $blogs) ) {3593 if ( is_multisite() && ! user_can( $user_id, 'manage_network' ) && empty( $blogs ) ) { 3436 3594 $url = user_admin_url( $path, $scheme ); 3437 3595 } elseif ( ! is_multisite() ) { … … 3439 3597 } else { 3440 3598 $current_blog = get_current_blog_id(); 3441 if ( $current_blog && ( user_can( $user_id, 'manage_network' ) || in_array( $current_blog, array_keys( $blogs ) ) ) ) {3599 if ( $current_blog && ( user_can( $user_id, 'manage_network' ) || in_array( $current_blog, array_keys( $blogs ) ) ) ) { 3442 3600 $url = admin_url( $path, $scheme ); 3443 3601 } else { 3444 3602 $active = get_active_blog_for_user( $user_id ); 3445 if ( $active ) 3603 if ( $active ) { 3446 3604 $url = get_admin_url( $active->blog_id, $path, $scheme ); 3447 else3605 } else { 3448 3606 $url = user_admin_url( $path, $scheme ); 3607 } 3449 3608 } 3450 3609 } … … 3461 3620 * 'login_post', 'admin', 'relative' or null. 3462 3621 */ 3463 return apply_filters( 'user_dashboard_url', $url, $user_id, $path, $scheme );3622 return apply_filters( 'user_dashboard_url', $url, $user_id, $path, $scheme ); 3464 3623 } 3465 3624 … … 3477 3636 $user_id = $user_id ? (int) $user_id : get_current_user_id(); 3478 3637 3479 if ( is_user_admin() ) 3638 if ( is_user_admin() ) { 3480 3639 $url = user_admin_url( 'profile.php', $scheme ); 3481 elseif ( is_network_admin() )3640 } elseif ( is_network_admin() ) { 3482 3641 $url = network_admin_url( 'profile.php', $scheme ); 3483 else3642 } else { 3484 3643 $url = get_dashboard_url( $user_id, 'profile.php', $scheme ); 3644 } 3485 3645 3486 3646 /** … … 3494 3654 * 'login_post', 'admin', 'relative' or null. 3495 3655 */ 3496 return apply_filters( 'edit_profile_url', $url, $user_id, $scheme );3656 return apply_filters( 'edit_profile_url', $url, $user_id, $scheme ); 3497 3657 } 3498 3658 … … 3617 3777 if ( 'query' == $context && is_singular() ) { 3618 3778 $post_id = get_queried_object_id(); 3619 $post = get_post( $post_id );3779 $post = get_post( $post_id ); 3620 3780 } elseif ( 'post' == $context ) { 3621 3781 $post = get_post( $id ); 3622 if ( ! empty( $post->ID ) ) 3782 if ( ! empty( $post->ID ) ) { 3623 3783 $post_id = $post->ID; 3784 } 3624 3785 } 3625 3786 … … 3660 3821 $shortlink = wp_get_shortlink( 0, 'query' ); 3661 3822 3662 if ( empty( $shortlink ) ) 3823 if ( empty( $shortlink ) ) { 3663 3824 return; 3825 } 3664 3826 3665 3827 echo "<link rel='shortlink' href='" . esc_url( $shortlink ) . "' />\n"; … … 3674 3836 */ 3675 3837 function wp_shortlink_header() { 3676 if ( headers_sent() ) 3838 if ( headers_sent() ) { 3677 3839 return; 3678 3679 $shortlink = wp_get_shortlink(0, 'query'); 3680 3681 if ( empty($shortlink) ) 3840 } 3841 3842 $shortlink = wp_get_shortlink( 0, 'query' ); 3843 3844 if ( empty( $shortlink ) ) { 3682 3845 return; 3683 3684 header('Link: <' . $shortlink . '>; rel=shortlink', false); 3846 } 3847 3848 header( 'Link: <' . $shortlink . '>; rel=shortlink', false ); 3685 3849 } 3686 3850 … … 3702 3866 $post = get_post(); 3703 3867 3704 if ( empty( $text ) ) 3705 $text = __('This is the short link.'); 3706 3707 if ( empty( $title ) ) 3868 if ( empty( $text ) ) { 3869 $text = __( 'This is the short link.' ); 3870 } 3871 3872 if ( empty( $title ) ) { 3708 3873 $title = the_title_attribute( array( 'echo' => false ) ); 3874 } 3709 3875 3710 3876 $shortlink = wp_get_shortlink( $post->ID ); 3711 3877 3712 if ( ! empty( $shortlink ) ) {3878 if ( ! empty( $shortlink ) ) { 3713 3879 $link = '<a rel="shortlink" href="' . esc_url( $shortlink ) . '" title="' . $title . '">' . $text . '</a>'; 3714 3880 … … 3798 3964 */ 3799 3965 function get_avatar_data( $id_or_email, $args = null ) { 3800 $args = wp_parse_args( $args, array( 3801 'size' => 96, 3802 'height' => null, 3803 'width' => null, 3804 'default' => get_option( 'avatar_default', 'mystery' ), 3805 'force_default' => false, 3806 'rating' => get_option( 'avatar_rating' ), 3807 'scheme' => null, 3808 'processed_args' => null, // if used, should be a reference 3809 'extra_attr' => '', 3810 ) ); 3966 $args = wp_parse_args( 3967 $args, array( 3968 'size' => 96, 3969 'height' => null, 3970 'width' => null, 3971 'default' => get_option( 'avatar_default', 'mystery' ), 3972 'force_default' => false, 3973 'rating' => get_option( 'avatar_rating' ), 3974 'scheme' => null, 3975 'processed_args' => null, // if used, should be a reference 3976 'extra_attr' => '', 3977 ) 3978 ); 3811 3979 3812 3980 if ( is_numeric( $args['size'] ) ) { … … 3842 4010 3843 4011 switch ( $args['default'] ) { 3844 case 'mm' :3845 case 'mystery' :3846 case 'mysteryman' :4012 case 'mm': 4013 case 'mystery': 4014 case 'mysteryman': 3847 4015 $args['default'] = 'mm'; 3848 4016 break; 3849 case 'gravatar_default' :4017 case 'gravatar_default': 3850 4018 $args['default'] = false; 3851 4019 break; … … 3879 4047 3880 4048 $email_hash = ''; 3881 $user = $email = false;4049 $user = $email = false; 3882 4050 3883 4051 if ( is_object( $id_or_email ) && isset( $id_or_email->comment_ID ) ) { … … 3937 4105 if ( $email_hash ) { 3938 4106 $args['found_avatar'] = true; 3939 $gravatar_server = hexdec( $email_hash[0] ) % 3;4107 $gravatar_server = hexdec( $email_hash[0] ) % 3; 3940 4108 } else { 3941 4109 $gravatar_server = rand( 0, 2 );
Note: See TracChangeset
for help on using the changeset viewer.