WordPress.org

Make WordPress Core

Changeset 34556


Ignore:
Timestamp:
09/25/15 19:53:28 (2 years ago)
Author:
helen
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/edit-form-advanced.php

    r34515 r34556  
    570570if ( $viewable ) : 
    571571$sample_permalink_html = $post_type_object->public ? get_sample_permalink_html($post->ID) : ''; 
    572 $shortlink = wp_get_shortlink($post->ID, 'post'); 
    573  
    574 if ( !empty( $shortlink ) && $shortlink !== $permalink && $permalink !== home_url('?page_id=' . $post->ID) ) 
    575     $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>'; 
     572 
     573// As of 4.4, the Get Shortlink button is hidden by default. 
     574if ( has_filter( 'pre_get_shortlink' ) || has_filter( 'get_shortlink' ) ) { 
     575    $shortlink = wp_get_shortlink($post->ID, 'post'); 
     576 
     577    if ( !empty( $shortlink ) && $shortlink !== $permalink && $permalink !== home_url('?page_id=' . $post->ID) ) { 
     578        $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>'; 
     579    } 
     580} 
    576581 
    577582if ( $post_type_object->public && ! ( 'pending' == get_post_status( $post ) && !current_user_can( $post_type_object->cap->publish_posts ) ) ) { 
Note: See TracChangeset for help on using the changeset viewer.