Make WordPress Core


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.0/wp-includes/link-template.php

    r17228 r15412  
    2828 * @uses $wp_rewrite
    2929 *
    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.
     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.
    3232 * @return string
    3333 */
     
    4040
    4141    // 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_archive
     42    // single, single_trackback, single_feed, single_paged, feed, category, page, year, month, day, paged
    4343    $string = apply_filters('user_trailingslashit', $string, $type_of_url);
    4444    return $string;
     
    186186    $slug = $post->post_name;
    187187
    188     $draft_or_pending = isset($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' ) );
    189189
    190190    $post_type = get_post_type_object($post->post_type);
    191191
    192     if ( !empty($post_link) && ( !$draft_or_pending || $sample ) ) {
     192    if ( !empty($post_link) && ( ( isset($post->post_status) && !$draft_or_pending ) || $sample ) ) {
    193193        if ( ! $leavename ) {
    194194            if ( $post_type->hierarchical )
     
    272272        $post = &get_post($id);
    273273
    274     $draft_or_pending = in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) );
    275 
    276274    $link = $wp_rewrite->get_page_permastruct();
    277275
    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 )
    280278            $link = str_replace('%pagename%', get_page_uri($id), $link);
    281         }
    282 
    283279        $link = home_url($link);
    284280        $link = user_trailingslashit($link, 'page');
     
    466462 * @return string
    467463 */
    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 ) )
     464function 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) )
    475471        $feed = get_default_feed();
    476472
     
    654650 *
    655651 * @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 */
     654function 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 );
    661664}
    662665
     
    670673 * @param string $after Optional. Display after edit link.
    671674 * @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.
    673676 */
    674677function 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');
    727679    if ( !current_user_can($tax->cap->edit_terms) )
    728680        return;
    729681
    730     if ( empty( $link ) )
     682    $tag = get_term($tag, 'post_tag');
     683
     684    if ( empty($link) )
    731685        $link = __('Edit This');
    732686
    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;
    740689}
    741690
     
    829778
    830779/**
    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 /**
    888780 * Retrieve edit posts link for post.
    889781 *
     
    955847function get_delete_post_link( $id = 0, $deprecated = '', $force_delete = false ) {
    956848    if ( ! empty( $deprecated ) )
    957         _deprecated_argument( __FUNCTION__, '3.0' );
     849        _deprecated_argument( __FUNCTION__, '3.0.0' );
    958850
    959851    if ( !$post = &get_post( $id ) )
     
    984876function get_edit_comment_link( $comment_id = 0 ) {
    985877    $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    }
    989887
    990888    $location = admin_url('comment.php?action=editcomment&amp;c=') . $comment->comment_ID;
     
    1003901 */
    1004902function 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    }
    1009912
    1010913    if ( null === $link )
    1011914        $link = __('Edit This');
    1012915
    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>';
    1014917    echo $before . apply_filters( 'edit_comment_link', $link, $comment->comment_ID ) . $after;
    1015918}
     
    1052955        $link = __('Edit This');
    1053956
    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>';
    1055958    echo $before . apply_filters( 'edit_bookmark_link', $link, $bookmark->link_id ) . $after;
    1056959}
     
    1059962
    1060963/**
    1061  * Retrieve previous post that is adjacent to current post.
     964 * Retrieve previous post link that is adjacent to current post.
    1062965 *
    1063966 * @since 1.5.0
    1064967 *
    1065  * @param bool $in_same_cat Optional. Whether post should be in same category.
     968 * @param bool $in_same_cat Optional. Whether link should be in same category.
    1066969 * @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
    1068971 */
    1069972function get_previous_post($in_same_cat = false, $excluded_categories = '') {
     
    1072975
    1073976/**
    1074  * Retrieve next post that is adjacent to current post.
     977 * Retrieve next post link that is adjacent to current post.
    1075978 *
    1076979 * @since 1.5.0
    1077980 *
    1078  * @param bool $in_same_cat Optional. Whether post should be in same category.
     981 * @param bool $in_same_cat Optional. Whether link should be in same category.
    1079982 * @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
    1081984 */
    1082985function get_next_post($in_same_cat = false, $excluded_categories = '') {
     
    1085988
    1086989/**
    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.
    1090993 *
    1091994 * @since 2.5.0
    1092995 *
    1093  * @param bool $in_same_cat Optional. Whether post should be in same category.
     996 * @param bool $in_same_cat Optional. Whether link should be in same category.
    1094997 * @param string $excluded_categories Optional. Excluded categories IDs.
    1095998 * @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
    10971000 */
    10981001function get_adjacent_post($in_same_cat = false, $excluded_categories = '', $previous = true) {
     
    12451148 * Retrieve boundary post.
    12461149 *
    1247  * Boundary being either the first or last post by publish date within the constraints specified
     1150 * Boundary being either the first or last post by publish date within the contraitns specified
    12481151 * by in same category or excluded categories.
    12491152 *
     
    12521155 * @param bool $in_same_cat Optional. Whether returned post should be in same category.
    12531156 * @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.
    12551158 * @return object
    12561159 */
     
    12851188    $order = $start ? 'ASC' : 'DESC';
    12861189
    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) );
    12881191}
    12891192
     
    12981201 * @param bool $in_same_cat Optional. Whether link should be in same category.
    12991202 * @param string $excluded_categories Optional. Excluded categories IDs.
    1300  * @param bool $start Optional, default is true. Whether display link to first or last post.
     1203 * @param bool $start Optional, default is true. Whether display link to first post.
    13011204 * @return string
    13021205 */
    13031206function 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);
    13051208    // If there is no post stop.
    13061209    if ( empty($posts) )
     
    15091412        }
    15101413
    1511         $request = preg_replace( "|$wp_rewrite->pagination_base/\d+/?$|", '', $request);
     1414        $request = preg_replace( '|page/\d+/?$|', '', $request);
    15121415        $request = preg_replace( '|^index\.php|', '', $request);
    15131416        $request = ltrim($request, '/');
     
    15191422
    15201423        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' );
    15221425        }
    15231426
     
    15891492    $nextpage = intval($paged) + 1;
    15901493
    1591     if ( !is_single() && ( $nextpage <= $max_page ) ) {
     1494    if ( !is_single() && ( empty($paged) || $nextpage <= $max_page) ) {
    15921495        $attr = apply_filters( 'next_posts_link_attributes', '' );
    15931496        return '<a href="' . next_posts( $max_page, false ) . "\" $attr>" . preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $label) . '</a>';
     
    19571860
    19581861    if ( empty( $blog_id ) || !is_multisite() )
    1959         $url = get_option( 'home' );
     1862        $home = get_option( 'home' );
    19601863    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 );
    19651867
    19661868    if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
     
    20241926        $url = get_blog_option( $blog_id, 'siteurl' );
    20251927
    2026     if ( 'http' != $scheme )
    2027         $url = str_replace( 'http://', "{$scheme}://", $url );
     1928    $url = str_replace( 'http://', "{$scheme}://", $url );
    20281929
    20291930    if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
     
    21762077    }
    21772078
    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 );
    21792082
    21802083    if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
     
    22092112        $scheme = is_ssl() && !is_admin() ? 'https' : 'http';
    22102113
    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 );
    22122117
    22132118    if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
     
    22282133*/
    22292134function 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);
    22342136
    22352137    if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
     
    22372139
    22382140    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);
    23372141}
    23382142
     
    23662170 *
    23672171 * @param int $id A post or blog id.  Default is 0, which means the current post or blog.
    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'.
     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'.
    23692173 * @param bool $allow_slugs Whether to allow post slugs in the shortlink. It is up to the plugin how and whether to honor this.
    23702174 * @return string A shortlink or an empty string if no shortlink exists for the requested resource or if shortlinks are not enabled.
     
    24252229 */
    24262230function wp_shortlink_header() {
    2427     if ( headers_sent() )
     2231    if ( headers_sent() )
    24282232        return;
    24292233
Note: See TracChangeset for help on using the changeset viewer.