Changes from trunk/wp-includes/link-template.php at r17228 to branches/3.0/wp-includes/link-template.php at r15412
- File:
-
- 1 edited
-
branches/3.0/wp-includes/link-template.php (modified) (30 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/3.0/wp-includes/link-template.php
r17228 r15412 28 28 * @uses $wp_rewrite 29 29 * 30 * @param string $stringURL with or without a trailing slash.31 * @param string $type_of_url The type of URL being considered (e.g. single, category, etc) for use in the filter.30 * @param $string String a URL with or without a trailing slash. 31 * @param $type_of_url String the type of URL being considered (e.g. single, category, etc) for use in the filter. 32 32 * @return string 33 33 */ … … 40 40 41 41 // Note that $type_of_url can be one of following: 42 // single, single_trackback, single_feed, single_paged, feed, category, page, year, month, day, paged , post_type_archive42 // single, single_trackback, single_feed, single_paged, feed, category, page, year, month, day, paged 43 43 $string = apply_filters('user_trailingslashit', $string, $type_of_url); 44 44 return $string; … … 186 186 $slug = $post->post_name; 187 187 188 $draft_or_pending = i sset($post->post_status) && in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) );188 $draft_or_pending = in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) ); 189 189 190 190 $post_type = get_post_type_object($post->post_type); 191 191 192 if ( !empty($post_link) && ( !$draft_or_pending|| $sample ) ) {192 if ( !empty($post_link) && ( ( isset($post->post_status) && !$draft_or_pending ) || $sample ) ) { 193 193 if ( ! $leavename ) { 194 194 if ( $post_type->hierarchical ) … … 272 272 $post = &get_post($id); 273 273 274 $draft_or_pending = in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) );275 276 274 $link = $wp_rewrite->get_page_permastruct(); 277 275 278 if ( !empty($link) && ( ( isset($post->post_status) && !$draft_or_pending) || $sample ) ) {279 if ( ! $leavename ) {276 if ( '' != $link && ( ( isset($post->post_status) && 'draft' != $post->post_status && 'pending' != $post->post_status ) || $sample ) ) { 277 if ( ! $leavename ) 280 278 $link = str_replace('%pagename%', get_page_uri($id), $link); 281 }282 283 279 $link = home_url($link); 284 280 $link = user_trailingslashit($link, 'page'); … … 466 462 * @return string 467 463 */ 468 function get_post_comments_feed_link($post_id = 0, $feed = '') {469 $post_id = absint( $post_id );470 471 if ( ! $post_id)472 $post_id = get_the_ID();473 474 if ( empty( $feed) )464 function get_post_comments_feed_link($post_id = '', $feed = '') { 465 global $id; 466 467 if ( empty($post_id) ) 468 $post_id = (int) $id; 469 470 if ( empty($feed) ) 475 471 $feed = get_default_feed(); 476 472 … … 654 650 * 655 651 * @param int $tag_id Tag ID 656 * @param string $taxonomy Taxonomy 657 * @return string 658 */ 659 function get_edit_tag_link( $tag_id, $taxonomy = 'post_tag' ) { 660 return apply_filters( 'get_edit_tag_link', get_edit_term_link( $tag_id, $taxonomy ) ); 652 * @return string 653 */ 654 function get_edit_tag_link( $tag_id = 0, $taxonomy = 'post_tag' ) { 655 global $post_type; 656 $tax = get_taxonomy($taxonomy); 657 if ( !current_user_can($tax->cap->edit_terms) ) 658 return; 659 660 $tag = get_term($tag_id, $taxonomy); 661 662 $location = admin_url('edit-tags.php?action=edit&taxonomy=' . $taxonomy . '&' . (!empty($post_type) ? 'post_type=' . $post_type .'&' : '') .'tag_ID=' . $tag->term_id); 663 return apply_filters( 'get_edit_tag_link', $location ); 661 664 } 662 665 … … 670 673 * @param string $after Optional. Display after edit link. 671 674 * @param int|object $tag Tag object or ID 672 * @return string HTML content.675 * @return string|null HTML content, if $echo is set to false. 673 676 */ 674 677 function edit_tag_link( $link = '', $before = '', $after = '', $tag = null ) { 675 $link = edit_term_link( $link, '', '', false, $tag ); 676 echo $before . apply_filters( 'edit_tag_link', $link ) . $after; 677 } 678 679 /** 680 * Retrieve edit term url. 681 * 682 * @since 3.1.0 683 * 684 * @param int $term_id Term ID 685 * @param string $taxonomy Taxonomy 686 * @param string $object_type The object type 687 * @return string 688 */ 689 function get_edit_term_link( $term_id, $taxonomy, $object_type = '' ) { 690 $tax = get_taxonomy( $taxonomy ); 691 if ( !current_user_can( $tax->cap->edit_terms ) ) 692 return; 693 694 $term = get_term( $term_id, $taxonomy ); 695 696 $args = array( 697 'action' => 'edit', 698 'taxonomy' => $taxonomy, 699 'tag_ID' => $term->term_id, 700 ); 701 702 if ( $object_type ) 703 $args['post_type'] = $object_type; 704 705 $location = add_query_arg( $args, admin_url( 'edit-tags.php' ) ); 706 707 return apply_filters( 'get_edit_term_link', $location, $term_id, $taxonomy, $object_type ); 708 } 709 710 /** 711 * Display or retrieve edit term link with formatting. 712 * 713 * @since 3.1.0 714 * 715 * @param string $link Optional. Anchor text. 716 * @param string $before Optional. Display before edit link. 717 * @param string $after Optional. Display after edit link. 718 * @param object $term Term object 719 * @return string HTML content. 720 */ 721 function edit_term_link( $link = '', $before = '', $after = '', $term = null, $echo = true ) { 722 if ( is_null( $term ) ) { 723 $term = get_queried_object(); 724 } 725 726 $tax = get_taxonomy( $term->taxonomy ); 678 $tax = get_taxonomy('post_tag'); 727 679 if ( !current_user_can($tax->cap->edit_terms) ) 728 680 return; 729 681 730 if ( empty( $link ) ) 682 $tag = get_term($tag, 'post_tag'); 683 684 if ( empty($link) ) 731 685 $link = __('Edit This'); 732 686 733 $link = '<a href="' . get_edit_term_link( $term->term_id, $term->taxonomy ) . '" title="' . $link . '">' . $link . '</a>'; 734 $link = $before . apply_filters( 'edit_term_link', $link, $term->term_id ) . $after; 735 736 if ( $echo ) 737 echo $link; 738 else 739 return $link; 687 $link = '<a href="' . get_edit_tag_link( $tag->term_id ) . '" title="' . __( 'Edit Tag' ) . '">' . $link . '</a>'; 688 echo $before . apply_filters( 'edit_tag_link', $link, $tag->term_id ) . $after; 740 689 } 741 690 … … 829 778 830 779 /** 831 * Retrieve the permalink for a post type archive.832 *833 * @since 3.1.0834 *835 * @param string $post_type Post type836 * @return string837 */838 function get_post_type_archive_link( $post_type ) {839 global $wp_rewrite;840 if ( ! $post_type_obj = get_post_type_object( $post_type ) )841 return false;842 843 if ( ! $post_type_obj->has_archive )844 return false;845 846 if ( get_option( 'permalink_structure' ) && is_array( $post_type_obj->rewrite ) ) {847 $struct = ( true === $post_type_obj->has_archive ) ? $post_type_obj->rewrite['slug'] : $post_type_obj->has_archive;848 if ( $post_type_obj->rewrite['with_front'] )849 $struct = $wp_rewrite->front . $struct;850 $link = home_url( user_trailingslashit( $struct, 'post_type_archive' ) );851 } else {852 $link = home_url( '?post_type=' . $post_type );853 }854 855 return apply_filters( 'post_type_archive_link', $link, $post_type );856 }857 858 /**859 * Retrieve the permalink for a post type archive feed.860 *861 * @since 3.1.0862 *863 * @param string $post_type Post type864 * @param string $feed Optional. Feed type865 * @return string866 */867 function get_post_type_archive_feed_link( $post_type, $feed = '' ) {868 $default_feed = get_default_feed();869 if ( empty( $feed ) )870 $feed = $default_feed;871 872 if ( ! $link = get_post_type_archive_link( $post_type ) )873 return false;874 $post_type_obj = get_post_type_object( $post_type );875 if ( $post_type_obj->rewrite['feeds'] && get_option( 'permalink_structure' ) ) {876 $link = trailingslashit($link);877 $link .= 'feed/';878 if ( $feed != $default_feed )879 $link .= "$feed/";880 } else {881 $link = add_query_arg( 'feed', $feed, $link );882 }883 884 return apply_filters( 'post_type_archive_feed_link', $link, $feed );885 }886 887 /**888 780 * Retrieve edit posts link for post. 889 781 * … … 955 847 function get_delete_post_link( $id = 0, $deprecated = '', $force_delete = false ) { 956 848 if ( ! empty( $deprecated ) ) 957 _deprecated_argument( __FUNCTION__, '3.0 ' );849 _deprecated_argument( __FUNCTION__, '3.0.0' ); 958 850 959 851 if ( !$post = &get_post( $id ) ) … … 984 876 function get_edit_comment_link( $comment_id = 0 ) { 985 877 $comment = &get_comment( $comment_id ); 986 987 if ( !current_user_can( 'edit_comment', $comment->comment_ID ) ) 988 return; 878 $post = &get_post( $comment->comment_post_ID ); 879 880 if ( $post->post_type == 'page' ) { 881 if ( !current_user_can( 'edit_page', $post->ID ) ) 882 return; 883 } else { 884 if ( !current_user_can( 'edit_post', $post->ID ) ) 885 return; 886 } 989 887 990 888 $location = admin_url('comment.php?action=editcomment&c=') . $comment->comment_ID; … … 1003 901 */ 1004 902 function edit_comment_link( $link = null, $before = '', $after = '' ) { 1005 global $comment; 1006 1007 if ( !current_user_can( 'edit_comment', $comment->comment_ID ) ) 1008 return; 903 global $comment, $post; 904 905 if ( $post->post_type == 'page' ) { 906 if ( !current_user_can( 'edit_page', $post->ID ) ) 907 return; 908 } else { 909 if ( !current_user_can( 'edit_post', $post->ID ) ) 910 return; 911 } 1009 912 1010 913 if ( null === $link ) 1011 914 $link = __('Edit This'); 1012 915 1013 $link = '<a class="comment-edit-link" href="' . get_edit_comment_link( $comment->comment_ID ) . '" title="' . esc_attr__( 'Edit comment' ) . '">' . $link . '</a>';916 $link = '<a class="comment-edit-link" href="' . get_edit_comment_link( $comment->comment_ID ) . '" title="' . __( 'Edit comment' ) . '">' . $link . '</a>'; 1014 917 echo $before . apply_filters( 'edit_comment_link', $link, $comment->comment_ID ) . $after; 1015 918 } … … 1052 955 $link = __('Edit This'); 1053 956 1054 $link = '<a href="' . get_edit_bookmark_link( $ bookmark ) . '" title="' . esc_attr__( 'Edit Link' ) . '">' . $link . '</a>';957 $link = '<a href="' . get_edit_bookmark_link( $link ) . '" title="' . __( 'Edit Link' ) . '">' . $link . '</a>'; 1055 958 echo $before . apply_filters( 'edit_bookmark_link', $link, $bookmark->link_id ) . $after; 1056 959 } … … 1059 962 1060 963 /** 1061 * Retrieve previous post that is adjacent to current post.964 * Retrieve previous post link that is adjacent to current post. 1062 965 * 1063 966 * @since 1.5.0 1064 967 * 1065 * @param bool $in_same_cat Optional. Whether postshould be in same category.968 * @param bool $in_same_cat Optional. Whether link should be in same category. 1066 969 * @param string $excluded_categories Optional. Excluded categories IDs. 1067 * @return mixed Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists.970 * @return string 1068 971 */ 1069 972 function get_previous_post($in_same_cat = false, $excluded_categories = '') { … … 1072 975 1073 976 /** 1074 * Retrieve next post that is adjacent to current post.977 * Retrieve next post link that is adjacent to current post. 1075 978 * 1076 979 * @since 1.5.0 1077 980 * 1078 * @param bool $in_same_cat Optional. Whether postshould be in same category.981 * @param bool $in_same_cat Optional. Whether link should be in same category. 1079 982 * @param string $excluded_categories Optional. Excluded categories IDs. 1080 * @return mixed Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists.983 * @return string 1081 984 */ 1082 985 function get_next_post($in_same_cat = false, $excluded_categories = '') { … … 1085 988 1086 989 /** 1087 * Retrieve adjacent post .1088 * 1089 * Can either be next or previous post .990 * Retrieve adjacent post link. 991 * 992 * Can either be next or previous post link. 1090 993 * 1091 994 * @since 2.5.0 1092 995 * 1093 * @param bool $in_same_cat Optional. Whether postshould be in same category.996 * @param bool $in_same_cat Optional. Whether link should be in same category. 1094 997 * @param string $excluded_categories Optional. Excluded categories IDs. 1095 998 * @param bool $previous Optional. Whether to retrieve previous post. 1096 * @return mixed Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists.999 * @return string 1097 1000 */ 1098 1001 function get_adjacent_post($in_same_cat = false, $excluded_categories = '', $previous = true) { … … 1245 1148 * Retrieve boundary post. 1246 1149 * 1247 * Boundary being either the first or last post by publish date within the con straints specified1150 * Boundary being either the first or last post by publish date within the contraitns specified 1248 1151 * by in same category or excluded categories. 1249 1152 * … … 1252 1155 * @param bool $in_same_cat Optional. Whether returned post should be in same category. 1253 1156 * @param string $excluded_categories Optional. Excluded categories IDs. 1254 * @param bool $ start Optional. Whether to retrieve first or last post.1157 * @param bool $previous Optional. Whether to retrieve first post. 1255 1158 * @return object 1256 1159 */ … … 1285 1188 $order = $start ? 'ASC' : 'DESC'; 1286 1189 1287 return get_posts( array('numberposts' => 1, ' category' => $categories, 'order' => $order, 'update_post_term_cache' => false, 'update_post_meta_cache' => false) );1190 return get_posts( array('numberposts' => 1, 'no_found_rows' => true, 'order' => $order, 'orderby' => 'ID', 'category' => $categories) ); 1288 1191 } 1289 1192 … … 1298 1201 * @param bool $in_same_cat Optional. Whether link should be in same category. 1299 1202 * @param string $excluded_categories Optional. Excluded categories IDs. 1300 * @param bool $start Optional, default is true. Whether display link to first or lastpost.1203 * @param bool $start Optional, default is true. Whether display link to first post. 1301 1204 * @return string 1302 1205 */ 1303 1206 function get_boundary_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $start = true) { 1304 $posts = get_boundary_post($in_same_cat, $excluded_categories,$start);1207 $posts = get_boundary_post($in_same_cat,$excluded_categories,$start); 1305 1208 // If there is no post stop. 1306 1209 if ( empty($posts) ) … … 1509 1412 } 1510 1413 1511 $request = preg_replace( "|$wp_rewrite->pagination_base/\d+/?$|", '', $request);1414 $request = preg_replace( '|page/\d+/?$|', '', $request); 1512 1415 $request = preg_replace( '|^index\.php|', '', $request); 1513 1416 $request = ltrim($request, '/'); … … 1519 1422 1520 1423 if ( $pagenum > 1 ) { 1521 $request = ( ( !empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( $wp_rewrite->pagination_base . "/". $pagenum, 'paged' );1424 $request = ( ( !empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( 'page/' . $pagenum, 'paged' ); 1522 1425 } 1523 1426 … … 1589 1492 $nextpage = intval($paged) + 1; 1590 1493 1591 if ( !is_single() && ( $nextpage <= $max_page) ) {1494 if ( !is_single() && ( empty($paged) || $nextpage <= $max_page) ) { 1592 1495 $attr = apply_filters( 'next_posts_link_attributes', '' ); 1593 1496 return '<a href="' . next_posts( $max_page, false ) . "\" $attr>" . preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&$1', $label) . '</a>'; … … 1957 1860 1958 1861 if ( empty( $blog_id ) || !is_multisite() ) 1959 $ url= get_option( 'home' );1862 $home = get_option( 'home' ); 1960 1863 else 1961 $url = get_blog_option( $blog_id, 'home' ); 1962 1963 if ( 'http' != $scheme ) 1964 $url = str_replace( 'http://', "$scheme://", $url ); 1864 $home = get_blog_option( $blog_id, 'home' ); 1865 1866 $url = str_replace( 'http://', "$scheme://", $home ); 1965 1867 1966 1868 if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false ) … … 2024 1926 $url = get_blog_option( $blog_id, 'siteurl' ); 2025 1927 2026 if ( 'http' != $scheme ) 2027 $url = str_replace( 'http://', "{$scheme}://", $url ); 1928 $url = str_replace( 'http://', "{$scheme}://", $url ); 2028 1929 2029 1930 if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false ) … … 2176 2077 } 2177 2078 2178 $url = $scheme . '://' . $current_site->domain . $current_site->path; 2079 $url = 'http://' . $current_site->domain . $current_site->path; 2080 2081 $url = str_replace( 'http://', "{$scheme}://", $url ); 2179 2082 2180 2083 if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) … … 2209 2112 $scheme = is_ssl() && !is_admin() ? 'https' : 'http'; 2210 2113 2211 $url = $scheme . '://' . $current_site->domain . $current_site->path; 2114 $url = 'http://' . $current_site->domain . $current_site->path; 2115 2116 $url = str_replace( 'http://', "$scheme://", $url ); 2212 2117 2213 2118 if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false ) … … 2228 2133 */ 2229 2134 function network_admin_url( $path = '', $scheme = 'admin' ) { 2230 if ( ! is_multisite() ) 2231 return admin_url( $path, $scheme ); 2232 2233 $url = network_site_url('wp-admin/network/', $scheme); 2135 $url = network_site_url('wp-admin/', $scheme); 2234 2136 2235 2137 if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) … … 2237 2139 2238 2140 return apply_filters('network_admin_url', $url, $path); 2239 }2240 2241 /**2242 * Retrieve the url to the admin area for the current user.2243 *2244 * @package WordPress2245 * @since 3.0.02246 *2247 * @param string $path Optional path relative to the admin url2248 * @param string $scheme The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). 'http' or 'https' can be passed to force those schemes.2249 * @return string Admin url link with optional path appended2250 */2251 function user_admin_url( $path = '', $scheme = 'admin' ) {2252 $url = network_site_url('wp-admin/user/', $scheme);2253 2254 if ( !empty($path) && is_string($path) && strpos($path, '..') === false )2255 $url .= ltrim($path, '/');2256 2257 return apply_filters('user_admin_url', $url, $path);2258 }2259 2260 /**2261 * Retrieve the url to the admin area for either the current blog or the network depending on context.2262 *2263 * @package WordPress2264 * @since 3.1.02265 *2266 * @param string $path Optional path relative to the admin url2267 * @param string $scheme The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). 'http' or 'https' can be passed to force those schemes.2268 * @return string Admin url link with optional path appended2269 */2270 function self_admin_url($path = '', $scheme = 'admin') {2271 if ( is_network_admin() )2272 return network_admin_url($path, $scheme);2273 elseif ( is_user_admin() )2274 return user_admin_url($path, $scheme);2275 else2276 return admin_url($path, $scheme);2277 }2278 2279 /**2280 * Get the URL to the user's dashboard.2281 *2282 * If a user does not belong to any sites, the global user dashboard is used. If the user belongs to the current site,2283 * the dashboard for the current site is returned. If the user cannot edit the current site, the dashboard to the user's2284 * primary blog is returned.2285 *2286 * @since 3.1.02287 *2288 * @param int $user_id User ID2289 * @param string $path Optional path relative to the dashboard. Use only paths known to both blog and user admins.2290 * @param string $scheme The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). 'http' or 'https' can be passed to force those schemes.2291 * @return string Dashboard url link with optional path appended2292 */2293 function get_dashboard_url( $user_id, $path = '', $scheme = 'admin' ) {2294 $user_id = (int) $user_id;2295 2296 $blogs = get_blogs_of_user( $user_id );2297 if ( empty($blogs) ) {2298 $url = user_admin_url( $path, $scheme );2299 } elseif ( ! is_multisite() ) {2300 $url = admin_url( $path, $scheme );2301 } else {2302 $current_blog = get_current_blog_id();2303 if ( $current_blog && in_array($current_blog, array_keys($blogs)) ) {2304 $url = admin_url( $path, $scheme );2305 } else {2306 $active = get_active_blog_for_user( $user_id );2307 if ( $active )2308 $url = get_admin_url( $active->blog_id, $path, $scheme );2309 else2310 $url = user_admin_url( $path, $scheme );2311 }2312 }2313 2314 return apply_filters( 'user_dashboard_url', $url, $user_id, $path, $scheme);2315 }2316 2317 /**2318 * Get the URL to the user's profile editor.2319 *2320 * @since 3.1.02321 *2322 * @param int $user User ID2323 * @param string $scheme The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). 'http' or 'https' can be passed to force those schemes.2324 * @return string Dashboard url link with optional path appended2325 */2326 function get_edit_profile_url( $user, $scheme = 'admin' ) {2327 $user = (int) $user;2328 2329 if ( is_user_admin() )2330 $url = user_admin_url( 'profile.php', $scheme );2331 elseif ( is_network_admin() )2332 $url = network_admin_url( 'profile.php', $scheme );2333 else2334 $url = get_dashboard_url( $user, 'profile.php', $scheme );2335 2336 return apply_filters( 'edit_profile_url', $url, $user, $scheme);2337 2141 } 2338 2142 … … 2366 2170 * 2367 2171 * @param int $id A post or blog id. Default is 0, which means the current post or blog. 2368 * @param string $contex t Whether the id is a 'blog' id, 'post' id, or 'media' id. If 'post', the post_type of the post is consulted.If 'query', the current query is consulted to determine the id and context. Default is 'post'.2172 * @param string $contex Whether the id is a 'blog' id, 'post' id, or 'media' id. If 'post', the post_type of the post is consulted. If 'query', the current query is consulted to determine the id and context. Default is 'post'. 2369 2173 * @param bool $allow_slugs Whether to allow post slugs in the shortlink. It is up to the plugin how and whether to honor this. 2370 2174 * @return string A shortlink or an empty string if no shortlink exists for the requested resource or if shortlinks are not enabled. … … 2425 2229 */ 2426 2230 function wp_shortlink_header() { 2427 if ( headers_sent() )2231 if ( headers_sent() ) 2428 2232 return; 2429 2233
Note: See TracChangeset
for help on using the changeset viewer.