Skip to content

Commit

Permalink
Shortlinks: Hide the Get Shortlink button by default.
Browse files Browse the repository at this point in the history
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.

Built from https://develop.svn.wordpress.org/trunk@34556


git-svn-id: http://core.svn.wordpress.org/trunk@34520 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
helen committed Sep 25, 2015
1 parent a6fecf0 commit e3dd4b7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions wp-admin/edit-form-advanced.php
Expand Up @@ -569,10 +569,15 @@
<?php
if ( $viewable ) :
$sample_permalink_html = $post_type_object->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 .= '<input id="shortlink" type="hidden" value="' . esc_attr($shortlink) . '" /><a href="#" class="button button-small" onclick="prompt(&#39;URL:&#39;, jQuery(\'#shortlink\').val()); return false;">' . __('Get Shortlink') . '</a>';
// 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 .= '<input id="shortlink" type="hidden" value="' . esc_attr($shortlink) . '" /><a href="#" class="button button-small" onclick="prompt(&#39;URL:&#39;, jQuery(\'#shortlink\').val()); return false;">' . __('Get Shortlink') . '</a>';
}
}

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;
Expand Down
2 changes: 1 addition & 1 deletion wp-includes/version.php
Expand Up @@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.4-alpha-34555';
$wp_version = '4.4-alpha-34556';

/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
Expand Down

0 comments on commit e3dd4b7

Please sign in to comment.