Share_LinkedIn

The Jetpack by WordPress.com Share LinkedIn class.

Defined (1)

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

/modules/sharedaddy/sharing-sources.php  
  1. class Share_LinkedIn extends Sharing_Source { 
  2. public $shortname = 'linkedin'; 
  3. public $genericon = '\f207'; 
  4. public function __construct( $id, array $settings ) { 
  5. parent::__construct( $id, $settings ); 
  6.  
  7. if ( 'official' == $this->button_style ) 
  8. $this->smart = true; 
  9. else 
  10. $this->smart = false; 
  11.  
  12. public function get_name() { 
  13. return __( 'LinkedIn', 'jetpack' ); 
  14.  
  15. public function has_custom_button_style() { 
  16. return $this->smart; 
  17.  
  18. public function get_display( $post ) { 
  19. $display = ''; 
  20.  
  21. if ( $this->smart ) { 
  22. $share_url = $this->get_share_url( $post->ID ); 
  23. $display .= sprintf( '<div class="linkedin_button"><script type="in/share" data-url="%s" data-counter="right"></script></div>', esc_url( $share_url ) ); 
  24. } else { 
  25. $display = $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'LinkedIn', 'share to', 'jetpack' ), __( 'Click to share on LinkedIn', 'jetpack' ), 'share=linkedin', 'sharing-linkedin-' . $post->ID ); 
  26.  
  27. /** This filter is already documented in modules/sharedaddy/sharing-sources.php */ 
  28. if ( apply_filters( 'jetpack_register_post_for_share_counts', true, $post->ID, 'linkedin' ) ) { 
  29. sharing_register_post_for_share_counts( $post->ID ); 
  30.  
  31. return $display; 
  32.  
  33. public function process_request( $post, array $post_data ) { 
  34.  
  35. $post_link = $this->get_share_url( $post->ID ); 
  36.  
  37. // Using the same URL as the official button, which is *not* LinkedIn's documented sharing link 
  38. // https://www.linkedin.com/cws/share?url={url}&token=&isFramed=false 
  39.  
  40. $linkedin_url = add_query_arg( array( 
  41. 'url' => rawurlencode( $post_link ),  
  42. ), 'https://www.linkedin.com/cws/share?token=&isFramed=false' ); 
  43.  
  44. // Record stats 
  45. parent::process_request( $post, $post_data ); 
  46.  
  47. // Redirect to LinkedIn 
  48. wp_redirect( $linkedin_url ); 
  49. die(); 
  50.  
  51. public function display_footer() { 
  52. if ( !$this->smart ) { 
  53. $this->js_dialog( $this->shortname, array( 'width' => 580, 'height' => 450 ) ); 
  54. } else { 
  55. ?><script type="text/javascript"> 
  56. jQuery( document ).ready( function() { 
  57. jQuery.getScript( '//platform.linkedin.com/in.js?async=true', function success() { 
  58. IN.init(); 
  59. }); 
  60. }); 
  61. jQuery( document.body ).on( 'post-load', function() { 
  62. if ( typeof IN != 'undefined' ) 
  63. IN.parse(); 
  64. }); 
  65. </script><?php