Ticket #10640: 10640.diff

File 10640.diff, 3.9 KB (added by ryan, 3 years ago)
  • 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 ) { 
  • 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        global $wp_query; 
     2073        $post_id = 0; 
     2074        if ( 'query' == $context && is_single() ) 
     2075                $post_id = $wp_query->get_queried_object_id(); 
     2076        elseif ( 'post' == $context ) 
     2077                $post_id = $id; 
     2078 
     2079        $shortlink = ''; 
     2080 
     2081        // Return p= link for posts. 
     2082        if ( !empty($post_id) ) { 
     2083                $post = get_post($post_id); 
     2084                if ( isset($post->post_type) && 'post' == $post->post_type ) 
     2085                        $shortlink = home_url('?p=' . $post->ID); 
     2086        } 
     2087 
     2088        return apply_filters('get_shortlink', $shortlink, $id, $context, $allow_slugs); 
     2089} 
     2090 
     2091function wp_shortlink_wp_head() { 
     2092        $shortlink = wp_get_shortlink(0, 'query'); 
     2093 
     2094        if ( empty($shortlink) ) 
     2095                return; 
     2096 
     2097        echo '<link rel="shortlink" href="' . $shortlink . '" />'; 
     2098} 
     2099 
     2100function wp_shortlink_header() { 
     2101    if ( headers_sent() ) 
     2102                return; 
     2103 
     2104        $shortlink = wp_get_shortlink(0, 'query'); 
     2105 
     2106        if ( empty($shortlink) ) 
     2107                return; 
     2108 
     2109        header('Link: <' . $shortlink . '>; rel=shortlink'); 
     2110} 
     2111 
    20532112?> 
  • wp-admin/edit-form-advanced.php

     
    192192<div class="inside"> 
    193193<?php 
    194194$sample_permalink_html = get_sample_permalink_html($post->ID); 
     195$shortlink = wp_get_shortlink($post->ID, 'post'); 
     196if ( !empty($shortlink) ) 
     197    $sample_permalink_html .= '<input id="shortlink" type="hidden" value="' . esc_attr($shortlink) . '" /><a href="#" class="button" onclick="prompt(&#39;URL:&#39;, jQuery(\'#shortlink\').val()); return false;">' . __('Get Shortlink') . '</a>'; 
     198 
    195199if ( !( 'pending' == $post->post_status && !current_user_can( $post_type_object->publish_cap ) ) ) { ?> 
    196200        <div id="edit-slug-box"> 
    197201<?php