Ticket #14760: wp_get_shortlink.diff

File wp_get_shortlink.diff, 1.3 KB (added by sillybean, 2 years ago)

Generates p= shortlinks for all content types, not just posts.

Line 
1Index: wp-includes/link-template.php
2===================================================================
3--- wp-includes/link-template.php       (revision 17220)
4+++ wp-includes/link-template.php       (working copy)
5@@ -2358,7 +2358,7 @@
6  * Return a shortlink for a post, page, attachment, or blog.
7  *
8  * This function exists to provide a shortlink tag that all themes and plugins can target.  A plugin must hook in to
9- * provide the actual shortlinks.  Default shortlink support is limited to providing ?p= style links for posts.
10+ * provide the actual shortlinks.  Default shortlink support is limited to providing ?p= style links.
11  * Plugins can short circuit this function via the pre_get_shortlink filter or filter the output
12  * via the get_shortlink filter.
13  *
14@@ -2377,7 +2377,7 @@
15 
16        global $wp_query;
17        $post_id = 0;
18-       if ( 'query' == $context && is_single() ) {
19+       if ( 'query' == $context && (is_single() || is_page()) ) {
20                $post_id = $wp_query->get_queried_object_id();
21        } elseif ( 'post' == $context ) {
22                $post = get_post($id);
23@@ -2389,7 +2389,7 @@
24        // Return p= link for posts.
25        if ( !empty($post_id) && '' != get_option('permalink_structure') ) {
26                $post = get_post($post_id);
27-               if ( isset($post->post_type) && 'post' == $post->post_type )
28+               if ( isset($post->post_type) )
29                        $shortlink = home_url('?p=' . $post->ID);
30        }
31