Make WordPress Core

Ticket #10640: 10640.2.diff

File 10640.2.diff, 2.7 KB (added by ryan, 15 years ago)
  • wp-includes/link-template.php

     
    20502050        add_action('wp_head', '_wp_ajaxurl', 1);
    20512051}
    20522052
     2053/**
     2054 * Return a shortlink for a post, page, attachment, or blog.
     2055 *
     2056 * Shortlinks are not supported by default. A plugin is required to get shortlink support.
     2057 * This function exists to provide a shortlink tag that all themes and plugins can target.  A plugin must hook in to
     2058 * provide the actual shortlinks.
     2059 *
     2060 * @param int $id A post or blog id.  Default is 0, which means the current post or blog.
     2061 * @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 determin the id and context. Default is 'post'.
     2062 * @param bool $allow_slugs Whether to allow post slugs in the shortlink. It is up to the plugin how and whether to honor this.
     2063 * @return string A shortlink or an empty string if no shortlink exists for the requested resource or if shortlinks are not enabled.
     2064 * @since 3.0.0.
     2065 */
     2066function wp_get_shortlink($id = 0, $context = 'post', $allow_slugs = true) {
     2067        // Allow plugins to short-circuit this function.
     2068        $shortlink = apply_filters('pre_get_shortlink', false, $id, $context, $allow_slugs);
     2069        if ( false !== $shortlink )
     2070                return $shortlink;
     2071
     2072        return apply_filters('get_shortlink', '', $id, $context, $allow_slugs);
     2073}
     2074
     2075function wp_shortlink_wp_head() {
     2076        $shortlink = get_shortlink(0, 'query');
     2077
     2078        if ( empty($shortlink) )
     2079                return;
     2080
     2081        echo '<link rel="shortlink" href="' . $shortlink . '" />';
     2082}
     2083
     2084function wp_shortlink_header() {
     2085    if ( headers_sent() )
     2086                return;
     2087
     2088        $shortlink = get_shortlink(0, 'query');
     2089
     2090        if ( empty($shortlink) )
     2091                return;
     2092
     2093        header('Link: <' . $shortlink . '>; rel=shortlink');
     2094}
     2095
    20532096?>
  • wp-includes/default-filters.php

     
    191191add_action( 'wp_head',             'wp_generator'                         );
    192192add_action( 'wp_head',             'rel_canonical'                        );
    193193add_action( 'wp_footer',           'wp_print_footer_scripts'              );
     194add_action( 'wp_head',             'wp_shortlink_wp_head'                 );
     195add_action( 'wp',                  'wp_shortlink_header'                  );
    194196
    195197// Feed Generator Tags
    196198foreach ( array( 'rss2_head', 'commentsrss2_head', 'rss_head', 'rdf_header', 'atom_head', 'comments_atom_head', 'opml_head', 'app_head' ) as $action ) {