Make WordPress Core

Ticket #18660: trunk.diff

File trunk.diff, 9.2 KB (added by joostdevalk, 14 years ago)

New approach, fixes several tickets at once.

  • wp-includes/default-filters.php

     
    203203add_action( 'wp_head',             'feed_links_extra',                3     );
    204204add_action( 'wp_head',             'rsd_link'                               );
    205205add_action( 'wp_head',             'wlwmanifest_link'                       );
    206 add_action( 'wp_head',             'adjacent_posts_rel_link_wp_head', 10, 0 );
     206add_action( 'wp_head',             'adjacent_rel_links',                          10, 0 );
    207207add_action( 'wp_head',             'locale_stylesheet'                      );
    208208add_action( 'publish_future_post', 'check_and_publish_future_post',   10, 1 );
    209209add_action( 'wp_head',             'noindex',                          1    );
  • wp-includes/link-template.php

     
    11631163}
    11641164
    11651165/**
    1166  * Get adjacent post relational link.
    1167  *
    1168  * Can either be next or previous post relational link.
    1169  *
    1170  * @since 2.8.0
    1171  *
    1172  * @param string $title Optional. Link title format.
    1173  * @param bool $in_same_cat Optional. Whether link should be in same category.
    1174  * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs.
    1175  * @param bool $previous Optional, default is true. Whether display link to previous post.
    1176  * @return string
    1177  */
    1178 function get_adjacent_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $previous = true) {
    1179         if ( $previous && is_attachment() && is_object( $GLOBALS['post'] ) )
    1180                 $post = & get_post($GLOBALS['post']->post_parent);
    1181         else
    1182                 $post = get_adjacent_post($in_same_cat,$excluded_categories,$previous);
    1183 
    1184         if ( empty($post) )
    1185                 return;
    1186 
    1187         if ( empty($post->post_title) )
    1188                 $post->post_title = $previous ? __('Previous Post') : __('Next Post');
    1189 
    1190         $date = mysql2date(get_option('date_format'), $post->post_date);
    1191 
    1192         $title = str_replace('%title', $post->post_title, $title);
    1193         $title = str_replace('%date', $date, $title);
    1194         $title = apply_filters('the_title', $title, $post->ID);
    1195 
    1196         $link = $previous ? "<link rel='prev' title='" : "<link rel='next' title='";
    1197         $link .= esc_attr( $title );
    1198         $link .= "' href='" . get_permalink($post) . "' />\n";
    1199 
    1200         $adjacent = $previous ? 'previous' : 'next';
    1201         return apply_filters( "{$adjacent}_post_rel_link", $link );
    1202 }
    1203 
    1204 /**
    1205  * Display relational links for the posts adjacent to the current post.
    1206  *
    1207  * @since 2.8.0
    1208  *
    1209  * @param string $title Optional. Link title format.
    1210  * @param bool $in_same_cat Optional. Whether link should be in same category.
    1211  * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs.
    1212  */
    1213 function adjacent_posts_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') {
    1214         echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', true);
    1215         echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', false);
    1216 }
    1217 
    1218 /**
    1219  * Display relational links for the posts adjacent to the current post for single post pages.
    1220  *
    1221  * This is meant to be attached to actions like 'wp_head'.  Do not call this directly in plugins or theme templates.
    1222  * @since 3.0.0
    1223  *
    1224  */
    1225 function adjacent_posts_rel_link_wp_head() {
    1226         if ( !is_singular() || is_attachment() )
    1227                 return;
    1228         adjacent_posts_rel_link();
    1229 }
    1230 
    1231 /**
    1232  * Display relational link for the next post adjacent to the current post.
    1233  *
    1234  * @since 2.8.0
    1235  *
    1236  * @param string $title Optional. Link title format.
    1237  * @param bool $in_same_cat Optional. Whether link should be in same category.
    1238  * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs.
    1239  */
    1240 function next_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') {
    1241         echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', false);
    1242 }
    1243 
    1244 /**
    1245  * Display relational link for the previous post adjacent to the current post.
    1246  *
    1247  * @since 2.8.0
    1248  *
    1249  * @param string $title Optional. Link title format.
    1250  * @param bool $in_same_cat Optional. Whether link should be in same category.
    1251  * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs.
    1252  */
    1253 function prev_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') {
    1254         echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', true);
    1255 }
    1256 
    1257 /**
    12581166 * Retrieve boundary post.
    12591167 *
    12601168 * Boundary being either the first or last post by publish date within the constraints specified
     
    22452153}
    22462154
    22472155/**
    2248  * Output rel=canonical for singular queries
     2156 * Get the current archive link
     2157 *
     2158 * @param $paged boolean whether or not to return a link with the current page in the archive, default true
     2159 * @since 3.3
     2160 */
     2161function get_current_archive_link( $paged = true ) {
     2162        if ( is_front_page() ) {
     2163                $link = home_url( '/' );
     2164        } else if ( is_home() && "page" == get_option('show_on_front') ) {
     2165                $link = get_permalink( get_option( 'page_for_posts' ) );
     2166        } else if ( is_tax() || is_tag() || is_category() ) {
     2167                $term = get_queried_object();
     2168                $link = get_term_link( $term, $term->taxonomy );
     2169        } else if ( is_post_type_archive() ) {
     2170                $link = get_post_type_archive_link( get_post_type() );
     2171        } else if ( is_author() ) {
     2172                $link = get_author_posts_url( get_query_var('author') );
     2173        } else if ( is_archive() ) {
     2174                if ( is_date() ) {
     2175                        if ( is_day() ) {
     2176                                $link = get_day_link( get_query_var('year'), get_query_var('monthnum'), get_query_var('day') );
     2177                        } else if ( is_month() ) {
     2178                                $link = get_month_link( get_query_var('year'), get_query_var('monthnum') );
     2179                        } else if ( is_year() ) {
     2180                                $link = get_year_link( get_query_var('year') );
     2181                        }                                               
     2182                }
     2183        }
     2184       
     2185        if ( $paged && $link && get_query_var('paged') > 1 ) {
     2186                global $wp_rewrite;
     2187                if ( !$wp_rewrite->using_permalinks() ) {
     2188                        $link = add_query_arg( 'paged', get_query_var('paged'), $link );
     2189                } else {
     2190                        $link = user_trailingslashit( trailingslashit( $link ) . trailingslashit( $wp_rewrite->pagination_base ) . get_query_var('paged'), 'archive' );
     2191                }
     2192        }
     2193        return $link;
     2194}
     2195
     2196/**
     2197 * Output rel=canonical
    22492198 *
    22502199 * @package WordPress
    22512200 * @since 2.9.0
    22522201*/
    22532202function rel_canonical() {
    2254         if ( !is_singular() )
    2255                 return;
     2203        $link = false;
     2204       
     2205        if ( is_singular() ) {
     2206                $link = get_permalink( get_queried_object() );
     2207                if ( get_query_var( 'page' ) > 1 ) {
     2208                        if ( !$wp_rewrite->using_permalinks() )
     2209                                $link = add_query_arg( 'page', get_query_var( 'page' ), $link );
     2210                        else
     2211                                $link = user_trailingslashit( trailingslashit( $link ) . get_query_var( 'page' ), 'single' );
     2212                }
     2213        } else {
     2214                $link = get_current_archive_link();
     2215        }
    22562216
    2257         global $wp_the_query;
    2258         if ( !$id = $wp_the_query->get_queried_object_id() )
    2259                 return;
     2217        $link = apply_filters( 'rel_canonical', $link );
     2218       
     2219        if ( $link )
     2220                echo "<link rel='canonical' href='" . esc_url( $link, 'canonical' ) . "' />\n";
     2221}
    22602222
    2261         $link = get_permalink( $id );
    2262         echo "<link rel='canonical' href='$link' />\n";
     2223/**
     2224 * Output rel=next and rel=prev links on archives and single pages
     2225 *
     2226 * @since 3.3
     2227 */
     2228function adjacent_rel_links() {
     2229        global $wp_query;
     2230
     2231        if ( !is_single() ) {
     2232                $url = get_current_archive_link( false );
     2233
     2234                if ( $url ) {
     2235                        $paged = get_query_var('paged');
     2236                       
     2237                        if ( 0 == $paged )
     2238                                $paged = 1;
     2239
     2240                        if ( $paged > 1 )
     2241                                echo get_adjacent_rel_link( "prev", $url, $paged-1, true );
     2242
     2243                        if ( $paged < $wp_query->max_num_pages )
     2244                                echo get_adjacent_rel_link( "next", $url, $paged+1, true );
     2245                }
     2246        } else {
     2247                global $page, $numpages, $multipage;
     2248                setup_postdata( $wp_query->post );
     2249                if ( !$multipage )
     2250                        return;
     2251
     2252                // Throw current page in another var to not screw up other functionality
     2253                $pg = $page;
     2254                if ( $pg == 0 )
     2255                        $pg = 1;
     2256
     2257                $url = get_permalink( $post->ID );
     2258
     2259                if ( $pg > 1 )
     2260                        echo get_adjacent_rel_link( "prev", $url, $pg-1, false );
     2261                if ( $pg < $numpages )
     2262                        echo get_adjacent_rel_link( "next", $url, $pg+1, false );
     2263        }       
    22632264}
    22642265
    22652266/**
     2267 * Get adjacent pages link for archives
     2268 *
     2269 * @param string $rel Link relationship, prev or next.
     2270 * @param string $url the unpaginated URL of the current archive.
     2271 * @param string $page the page number to add on to $url for the $link tag.
     2272 * @param boolean $incl_pagination_base whether or not to include /page/ or not.
     2273 * @return string $link link element
     2274 *
     2275 * @since 3.3
     2276 */
     2277function get_adjacent_rel_link( $rel, $url, $page, $incl_pagination_base ) {
     2278        global $wp_rewrite;
     2279        if ( !$wp_rewrite->using_permalinks() ) {
     2280                if ( $page > 1 )
     2281                        $url = add_query_arg( 'paged', $page, $url );
     2282        } else {
     2283                if ( $page > 1 ) {
     2284                        $base = '';
     2285                        if ( $incl_pagination_base )
     2286                                $base = trailingslashit( $wp_rewrite->pagination_base );
     2287                        $url = user_trailingslashit( trailingslashit( $url ) . $base . $page );
     2288                }
     2289        }
     2290        $link = "<link rel='$rel' href='$url' />\n";
     2291        return apply_filters( $rel."_rel_link", $link );       
     2292}
     2293
     2294/**
    22662295 * Return a shortlink for a post, page, attachment, or blog.
    22672296 *
    22682297 * This function exists to provide a shortlink tag that all themes and plugins can target.  A plugin must hook in to