From 9490539e89a8c0e227ff841f469e598432c5e219 Mon Sep 17 00:00:00 2001 From: Helen Hou-Sandi Date: Fri, 25 Sep 2015 19:53:28 +0000 Subject: [PATCH] Shortlinks: Hide the Get Shortlink button by default. Shortlinks had their day in the popular usage sun before all these services moved to their own shorteners and running your own custom one became a lot easier. Shortlinks are still useful in some contexts, such as analytics or when links need to be shared verbally or copied down by hand. If any filters are hooked onto `pre_get_shortlink` or `get_shortlink` and produce a non-empty value (with an exception described below), the button will magically reappear. This allows any custom shortlinks to keep the button without hiccups. If you're in need of the default shortlinks, the fastest way to reenable them is `add_filter( 'pre_get_shortlink', '__return_false' )`. Note that it must return false in order to continue on to the rest of `wp_get_shortlink()`. props grvrulz for the initial patch. fixes #33495. git-svn-id: https://develop.svn.wordpress.org/trunk@34556 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/edit-form-advanced.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/wp-admin/edit-form-advanced.php b/src/wp-admin/edit-form-advanced.php index 419b66c6df..b14049f8db 100644 --- a/src/wp-admin/edit-form-advanced.php +++ b/src/wp-admin/edit-form-advanced.php @@ -569,10 +569,15 @@ do_action( 'edit_form_before_permalink', $post ); public ? get_sample_permalink_html($post->ID) : ''; -$shortlink = wp_get_shortlink($post->ID, 'post'); -if ( !empty( $shortlink ) && $shortlink !== $permalink && $permalink !== home_url('?page_id=' . $post->ID) ) - $sample_permalink_html .= '' . __('Get Shortlink') . ''; +// As of 4.4, the Get Shortlink button is hidden by default. +if ( has_filter( 'pre_get_shortlink' ) || has_filter( 'get_shortlink' ) ) { + $shortlink = wp_get_shortlink($post->ID, 'post'); + + if ( !empty( $shortlink ) && $shortlink !== $permalink && $permalink !== home_url('?page_id=' . $post->ID) ) { + $sample_permalink_html .= '' . __('Get Shortlink') . ''; + } +} if ( $post_type_object->public && ! ( 'pending' == get_post_status( $post ) && !current_user_can( $post_type_object->cap->publish_posts ) ) ) { $has_sample_permalink = $sample_permalink_html && 'auto-draft' != $post->post_status;