get_shortcut_link

Retrieves the Press This bookmarklet link.

Description

get_shortcut_link(); 

Usage

  1. if ( !function_exists( 'get_shortcut_link' ) ) { 
  2. require_once ABSPATH . WPINC . '/link-template.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = get_shortcut_link(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/link-template.php  
  1. function get_shortcut_link() { 
  2. global $is_IE; 
  3.  
  4. include_once( ABSPATH . 'wp-admin/includes/class-wp-press-this.php' ); 
  5.  
  6. $link = ''; 
  7.  
  8. if ( $is_IE ) { 
  9. /** 
  10. * Return the old/shorter bookmarklet code for MSIE 8 and lower,  
  11. * since they only support a max length of ~2000 characters for 
  12. * bookmark[let] URLs, which is way to small for our smarter one. 
  13. * Do update the version number so users do not get the "upgrade your 
  14. * bookmarklet" notice when using PT in those browsers. 
  15. */ 
  16. $ua = $_SERVER['HTTP_USER_AGENT']; 
  17.  
  18. if ( ! empty( $ua ) && preg_match( '/\bMSIE (\d)/', $ua, $matches ) && (int) $matches[1] <= 8 ) { 
  19. $url = wp_json_encode( admin_url( 'press-this.php' ) ); 
  20.  
  21. $link = 'javascript:var d=document, w=window, e=w.getSelection, k=d.getSelection, x=d.selection, ' . 
  22. 's=(e?e():(k)?k():(x?x.createRange().text:0)), f=' . $url . ', l=d.location, e=encodeURIComponent, ' . 
  23. 'u=f+"?u="+e(l.href)+"&t="+e(d.title)+"&s="+e(s)+"&v=' . WP_Press_This::VERSION . '";' . 
  24. 'a=function() {if(!w.open(u, "t", "toolbar=0, resizable=1, scrollbars=1, status=1, width=600, height=700"))l.href=u;};' . 
  25. 'if(/Firefox/.test(navigator.userAgent))setTimeout(a, 0);else a();void(0)'; 
  26.  
  27. if ( empty( $link ) ) { 
  28. $src = @file_get_contents( ABSPATH . 'wp-admin/js/bookmarklet.min.js' ); 
  29.  
  30. if ( $src ) { 
  31. $url = wp_json_encode( admin_url( 'press-this.php' ) . '?v=' . WP_Press_This::VERSION ); 
  32. $link = 'javascript:' . str_replace( 'window.pt_url', $url, $src ); 
  33.  
  34. $link = str_replace( array( "\r", "\n", "\t" ), '', $link ); 
  35.  
  36. /** 
  37. * Filters the Press This bookmarklet link. 
  38. * @since 2.6.0 
  39. * @param string $link The Press This bookmarklet link. 
  40. */ 
  41. return apply_filters( 'shortcut_link', $link );