Changes from branches/3.0/wp-includes/link-template.php at r15412 to trunk/wp-includes/link-template.php at r17228
- File:
-
- 1 edited
-
trunk/wp-includes/link-template.php (modified) (30 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/link-template.php
r15412 r17228 28 28 * @uses $wp_rewrite 29 29 * 30 * @param $string String aURL 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.30 * @param string $string URL 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. 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 42 // single, single_trackback, single_feed, single_paged, feed, category, page, year, month, day, paged, post_type_archive 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 n_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) );188 $draft_or_pending = isset($post->post_status) && 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) && ( ( isset($post->post_status) && !$draft_or_pending )|| $sample ) ) {192 if ( !empty($post_link) && ( !$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 274 276 $link = $wp_rewrite->get_page_permastruct(); 275 277 276 if ( '' != $link && ( ( isset($post->post_status) && 'draft' != $post->post_status && 'pending' != $post->post_status) || $sample ) ) {277 if ( ! $leavename ) 278 if ( !empty($link) && ( ( isset($post->post_status) && !$draft_or_pending ) || $sample ) ) { 279 if ( ! $leavename ) { 278 280 $link = str_replace('%pagename%', get_page_uri($id), $link); 281 } 282 279 283 $link = home_url($link); 280 284 $link = user_trailingslashit($link, 'page'); … … 462 466 * @return string 463 467 */ 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) )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 ) ) 471 475 $feed = get_default_feed(); 472 476 … … 650 654 * 651 655 * @param int $tag_id Tag ID 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 ); 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 ) ); 664 661 } 665 662 … … 673 670 * @param string $after Optional. Display after edit link. 674 671 * @param int|object $tag Tag object or ID 675 * @return string |null HTML content, if $echo is set to false.672 * @return string HTML content. 676 673 */ 677 674 function edit_tag_link( $link = '', $before = '', $after = '', $tag = null ) { 678 $tax = get_taxonomy('post_tag'); 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 ); 679 727 if ( !current_user_can($tax->cap->edit_terms) ) 680 728 return; 681 729 682 $tag = get_term($tag, 'post_tag'); 683 684 if ( empty($link) ) 730 if ( empty( $link ) ) 685 731 $link = __('Edit This'); 686 732 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; 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; 689 740 } 690 741 … … 778 829 779 830 /** 831 * Retrieve the permalink for a post type archive. 832 * 833 * @since 3.1.0 834 * 835 * @param string $post_type Post type 836 * @return string 837 */ 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.0 862 * 863 * @param string $post_type Post type 864 * @param string $feed Optional. Feed type 865 * @return string 866 */ 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 /** 780 888 * Retrieve edit posts link for post. 781 889 * … … 847 955 function get_delete_post_link( $id = 0, $deprecated = '', $force_delete = false ) { 848 956 if ( ! empty( $deprecated ) ) 849 _deprecated_argument( __FUNCTION__, '3.0 .0' );957 _deprecated_argument( __FUNCTION__, '3.0' ); 850 958 851 959 if ( !$post = &get_post( $id ) ) … … 876 984 function get_edit_comment_link( $comment_id = 0 ) { 877 985 $comment = &get_comment( $comment_id ); 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 } 986 987 if ( !current_user_can( 'edit_comment', $comment->comment_ID ) ) 988 return; 887 989 888 990 $location = admin_url('comment.php?action=editcomment&c=') . $comment->comment_ID; … … 901 1003 */ 902 1004 function edit_comment_link( $link = null, $before = '', $after = '' ) { 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 } 1005 global $comment; 1006 1007 if ( !current_user_can( 'edit_comment', $comment->comment_ID ) ) 1008 return; 912 1009 913 1010 if ( null === $link ) 914 1011 $link = __('Edit This'); 915 1012 916 $link = '<a class="comment-edit-link" href="' . get_edit_comment_link( $comment->comment_ID ) . '" title="' . __( 'Edit comment' ) . '">' . $link . '</a>';1013 $link = '<a class="comment-edit-link" href="' . get_edit_comment_link( $comment->comment_ID ) . '" title="' . esc_attr__( 'Edit comment' ) . '">' . $link . '</a>'; 917 1014 echo $before . apply_filters( 'edit_comment_link', $link, $comment->comment_ID ) . $after; 918 1015 } … … 955 1052 $link = __('Edit This'); 956 1053 957 $link = '<a href="' . get_edit_bookmark_link( $ link ) . '" title="' .__( 'Edit Link' ) . '">' . $link . '</a>';1054 $link = '<a href="' . get_edit_bookmark_link( $bookmark ) . '" title="' . esc_attr__( 'Edit Link' ) . '">' . $link . '</a>'; 958 1055 echo $before . apply_filters( 'edit_bookmark_link', $link, $bookmark->link_id ) . $after; 959 1056 } … … 962 1059 963 1060 /** 964 * Retrieve previous post linkthat is adjacent to current post.1061 * Retrieve previous post that is adjacent to current post. 965 1062 * 966 1063 * @since 1.5.0 967 1064 * 968 * @param bool $in_same_cat Optional. Whether linkshould be in same category.1065 * @param bool $in_same_cat Optional. Whether post should be in same category. 969 1066 * @param string $excluded_categories Optional. Excluded categories IDs. 970 * @return string1067 * @return mixed Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists. 971 1068 */ 972 1069 function get_previous_post($in_same_cat = false, $excluded_categories = '') { … … 975 1072 976 1073 /** 977 * Retrieve next post linkthat is adjacent to current post.1074 * Retrieve next post that is adjacent to current post. 978 1075 * 979 1076 * @since 1.5.0 980 1077 * 981 * @param bool $in_same_cat Optional. Whether linkshould be in same category.1078 * @param bool $in_same_cat Optional. Whether post should be in same category. 982 1079 * @param string $excluded_categories Optional. Excluded categories IDs. 983 * @return string1080 * @return mixed Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists. 984 1081 */ 985 1082 function get_next_post($in_same_cat = false, $excluded_categories = '') { … … 988 1085 989 1086 /** 990 * Retrieve adjacent post link.991 * 992 * Can either be next or previous post link.1087 * Retrieve adjacent post. 1088 * 1089 * Can either be next or previous post. 993 1090 * 994 1091 * @since 2.5.0 995 1092 * 996 * @param bool $in_same_cat Optional. Whether linkshould be in same category.1093 * @param bool $in_same_cat Optional. Whether post should be in same category. 997 1094 * @param string $excluded_categories Optional. Excluded categories IDs. 998 1095 * @param bool $previous Optional. Whether to retrieve previous post. 999 * @return string1096 * @return mixed Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists. 1000 1097 */ 1001 1098 function get_adjacent_post($in_same_cat = false, $excluded_categories = '', $previous = true) { … … 1148 1245 * Retrieve boundary post. 1149 1246 * 1150 * Boundary being either the first or last post by publish date within the con traitns specified1247 * Boundary being either the first or last post by publish date within the constraints specified 1151 1248 * by in same category or excluded categories. 1152 1249 * … … 1155 1252 * @param bool $in_same_cat Optional. Whether returned post should be in same category. 1156 1253 * @param string $excluded_categories Optional. Excluded categories IDs. 1157 * @param bool $ previous Optional. Whether to retrieve first post.1254 * @param bool $start Optional. Whether to retrieve first or last post. 1158 1255 * @return object 1159 1256 */ … … 1188 1285 $order = $start ? 'ASC' : 'DESC'; 1189 1286 1190 return get_posts( array('numberposts' => 1, ' no_found_rows' => true, 'order' => $order, 'orderby' => 'ID', 'category' => $categories) );1287 return get_posts( array('numberposts' => 1, 'category' => $categories, 'order' => $order, 'update_post_term_cache' => false, 'update_post_meta_cache' => false) ); 1191 1288 } 1192 1289 … … 1201 1298 * @param bool $in_same_cat Optional. Whether link should be in same category. 1202 1299 * @param string $excluded_categories Optional. Excluded categories IDs. 1203 * @param bool $start Optional, default is true. Whether display link to first post.1300 * @param bool $start Optional, default is true. Whether display link to first or last post. 1204 1301 * @return string 1205 1302 */ 1206 1303 function get_boundary_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $start = true) { 1207 $posts = get_boundary_post($in_same_cat, $excluded_categories,$start);1304 $posts = get_boundary_post($in_same_cat, $excluded_categories, $start); 1208 1305 // If there is no post stop. 1209 1306 if ( empty($posts) ) … … 1412 1509 } 1413 1510 1414 $request = preg_replace( '|page/\d+/?$|', '', $request);1511 $request = preg_replace( "|$wp_rewrite->pagination_base/\d+/?$|", '', $request); 1415 1512 $request = preg_replace( '|^index\.php|', '', $request); 1416 1513 $request = ltrim($request, '/'); … … 1422 1519 1423 1520 if ( $pagenum > 1 ) { 1424 $request = ( ( !empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( 'page/'. $pagenum, 'paged' );1521 $request = ( ( !empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( $wp_rewrite->pagination_base . "/" . $pagenum, 'paged' ); 1425 1522 } 1426 1523 … … 1492 1589 $nextpage = intval($paged) + 1; 1493 1590 1494 if ( !is_single() && ( empty($paged) || $nextpage <= $max_page) ) {1591 if ( !is_single() && ( $nextpage <= $max_page ) ) { 1495 1592 $attr = apply_filters( 'next_posts_link_attributes', '' ); 1496 1593 return '<a href="' . next_posts( $max_page, false ) . "\" $attr>" . preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&$1', $label) . '</a>'; … … 1860 1957 1861 1958 if ( empty( $blog_id ) || !is_multisite() ) 1862 $ home= get_option( 'home' );1959 $url = get_option( 'home' ); 1863 1960 else 1864 $home = get_blog_option( $blog_id, 'home' ); 1865 1866 $url = str_replace( 'http://', "$scheme://", $home ); 1961 $url = get_blog_option( $blog_id, 'home' ); 1962 1963 if ( 'http' != $scheme ) 1964 $url = str_replace( 'http://', "$scheme://", $url ); 1867 1965 1868 1966 if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false ) … … 1926 2024 $url = get_blog_option( $blog_id, 'siteurl' ); 1927 2025 1928 $url = str_replace( 'http://', "{$scheme}://", $url ); 2026 if ( 'http' != $scheme ) 2027 $url = str_replace( 'http://', "{$scheme}://", $url ); 1929 2028 1930 2029 if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false ) … … 2077 2176 } 2078 2177 2079 $url = 'http://' . $current_site->domain . $current_site->path; 2080 2081 $url = str_replace( 'http://', "{$scheme}://", $url ); 2178 $url = $scheme . '://' . $current_site->domain . $current_site->path; 2082 2179 2083 2180 if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) … … 2112 2209 $scheme = is_ssl() && !is_admin() ? 'https' : 'http'; 2113 2210 2114 $url = 'http://' . $current_site->domain . $current_site->path; 2115 2116 $url = str_replace( 'http://', "$scheme://", $url ); 2211 $url = $scheme . '://' . $current_site->domain . $current_site->path; 2117 2212 2118 2213 if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false ) … … 2133 2228 */ 2134 2229 function network_admin_url( $path = '', $scheme = 'admin' ) { 2135 $url = network_site_url('wp-admin/', $scheme); 2230 if ( ! is_multisite() ) 2231 return admin_url( $path, $scheme ); 2232 2233 $url = network_site_url('wp-admin/network/', $scheme); 2136 2234 2137 2235 if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) … … 2139 2237 2140 2238 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 WordPress 2245 * @since 3.0.0 2246 * 2247 * @param string $path Optional path relative to the admin url 2248 * @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 appended 2250 */ 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 WordPress 2264 * @since 3.1.0 2265 * 2266 * @param string $path Optional path relative to the admin url 2267 * @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 appended 2269 */ 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 else 2276 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's 2284 * primary blog is returned. 2285 * 2286 * @since 3.1.0 2287 * 2288 * @param int $user_id User ID 2289 * @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 appended 2292 */ 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 else 2310 $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.0 2321 * 2322 * @param int $user User ID 2323 * @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 appended 2325 */ 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 else 2334 $url = get_dashboard_url( $user, 'profile.php', $scheme ); 2335 2336 return apply_filters( 'edit_profile_url', $url, $user, $scheme); 2141 2337 } 2142 2338 … … 2170 2366 * 2171 2367 * @param int $id A post or blog id. Default is 0, which means the current post or blog. 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'.2368 * @param string $context 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'. 2173 2369 * @param bool $allow_slugs Whether to allow post slugs in the shortlink. It is up to the plugin how and whether to honor this. 2174 2370 * @return string A shortlink or an empty string if no shortlink exists for the requested resource or if shortlinks are not enabled. … … 2229 2425 */ 2230 2426 function wp_shortlink_header() { 2231 if ( headers_sent() )2427 if ( headers_sent() ) 2232 2428 return; 2233 2429
Note: See TracChangeset
for help on using the changeset viewer.