From fcbca58853d33f6d79091383fb3fd552f4ceeabf Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 9 Mar 2010 19:36:38 +0000 Subject: [PATCH] wp_get_shortlink() and pluggable shortlink generation. fixes #10640 git-svn-id: http://svn.automattic.com/wordpress/trunk@13635 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/edit-form-advanced.php | 4 ++ wp-includes/default-filters.php | 2 + wp-includes/link-template.php | 79 +++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) diff --git a/wp-admin/edit-form-advanced.php b/wp-admin/edit-form-advanced.php index cdec03a0c5..7d539ba615 100644 --- a/wp-admin/edit-form-advanced.php +++ b/wp-admin/edit-form-advanced.php @@ -192,6 +192,10 @@ $side_meta_boxes = do_meta_boxes($post_type, 'side', $post);
ID); +$shortlink = wp_get_shortlink($post->ID, 'post'); +if ( !empty($shortlink) ) + $sample_permalink_html .= '' . __('Get Shortlink') . ''; + if ( !( 'pending' == $post->post_status && !current_user_can( $post_type_object->publish_cap ) ) ) { ?>
get_queried_object_id(); + elseif ( 'post' == $context ) + $post_id = $id; + + $shortlink = ''; + + // Return p= link for posts. + if ( !empty($post_id) ) { + $post = get_post($post_id); + if ( isset($post->post_type) && 'post' == $post->post_type ) + $shortlink = home_url('?p=' . $post->ID); + } + + return apply_filters('get_shortlink', $shortlink, $id, $context, $allow_slugs); +} + +/** + * Inject rel=sortlink into head if a shortlink is defined for the current page. + * + * Attached to the wp_head action. + * + * @since 3.0.0 + * + * @uses wp_get_shortlink() + */ +function wp_shortlink_wp_head() { + $shortlink = wp_get_shortlink(0, 'query'); + + if ( empty($shortlink) ) + return; + + echo ''; +} + +/** + * Send a Link: rel=shortlink header if a shortlink is defined for the current page. + * + * Attached to the wp action. + * + * @since 3.0.0 + * + * @uses wp_get_shortlink() + */ +function wp_shortlink_header() { + if ( headers_sent() ) + return; + + $shortlink = wp_get_shortlink(0, 'query'); + + if ( empty($shortlink) ) + return; + + header('Link: <' . $shortlink . '>; rel=shortlink'); +} + ?>