sharing_display

The Jetpack by WordPress.com sharing display function.

Description

sharing_display( (string) $text = '', (bool) $echo = false ); 

Parameters (2)

0. $text — Optional. (string) => ''
The text.
1. $echo — Optional. (bool) => false
The echo.

Usage

  1. if ( !function_exists( 'sharing_display' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'jetpack-by-wordpress-com/modules/sharedaddy/sharing-service.php'; 
  3.  
  4. // The text. 
  5. $text = ''; 
  6.  
  7. // The echo. 
  8. $echo = false; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = sharing_display($text, $echo); 
  12.  

Defined (1)

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

/modules/sharedaddy/sharing-service.php  
  1. function sharing_display( $text = '', $echo = false ) { 
  2. global $post, $wp_current_filter; 
  3.  
  4. if ( empty( $post ) ) 
  5. return $text; 
  6.  
  7. if ( ( is_preview() || is_admin() ) && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { 
  8. return $text; 
  9.  
  10. // Don't output flair on excerpts 
  11. if ( in_array( 'get_the_excerpt', (array) $wp_current_filter ) ) { 
  12. return $text; 
  13.  
  14. // Don't allow flair to be added to the_content more than once (prevent infinite loops) 
  15. $done = false; 
  16. foreach ( $wp_current_filter as $filter ) { 
  17. if ( 'the_content' == $filter ) { 
  18. if ( $done ) 
  19. return $text; 
  20. else 
  21. $done = true; 
  22.  
  23. // check whether we are viewing the front page and whether the front page option is checked 
  24. $options = get_option( 'sharing-options' ); 
  25. $display_options = $options['global']['show']; 
  26.  
  27. if ( is_front_page() && ( is_array( $display_options ) && ! in_array( 'index', $display_options ) ) ) 
  28. return $text; 
  29.  
  30. if ( is_attachment() && in_array( 'the_excerpt', (array) $wp_current_filter ) ) { 
  31. // Many themes run the_excerpt() conditionally on an attachment page, then run the_content(). 
  32. // We only want to output the sharing buttons once. Let's stick with the_content(). 
  33. return $text; 
  34.  
  35. $sharer = new Sharing_Service(); 
  36. $global = $sharer->get_global_options(); 
  37.  
  38. $show = false; 
  39. if ( !is_feed() ) { 
  40. if ( is_singular() && in_array( get_post_type(), $global['show'] ) ) { 
  41. $show = true; 
  42. } elseif ( in_array( 'index', $global['show'] ) && ( is_home() || is_front_page() || is_archive() || is_search() || in_array( get_post_type(), $global['show'] ) ) ) { 
  43. $show = true; 
  44.  
  45. /** 
  46. * Filter to decide if sharing buttons should be displayed. 
  47. * @module sharedaddy 
  48. * @since 1.1.0 
  49. * @param bool $show Should the sharing buttons be displayed. 
  50. * @param WP_Post $post The post to share. 
  51. */ 
  52. $show = apply_filters( 'sharing_show', $show, $post ); 
  53.  
  54. // Disabled for this post? 
  55. $switched_status = get_post_meta( $post->ID, 'sharing_disabled', false ); 
  56.  
  57. if ( !empty( $switched_status ) ) 
  58. $show = false; 
  59.  
  60. // Private post? 
  61. $post_status = get_post_status( $post->ID ); 
  62.  
  63. if ( 'private' === $post_status ) { 
  64. $show = false; 
  65.  
  66. // Allow to be used on P2 ajaxrequestsfor latest posts. 
  67. if ( defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_REQUEST['action'] ) && 'get_latest_posts' == $_REQUEST['action'] ) 
  68. $show = true; 
  69.  
  70. $sharing_content = ''; 
  71.  
  72. if ( $show ) { 
  73. /** 
  74. * Filters the list of enabled Sharing Services. 
  75. * @module sharedaddy 
  76. * @since 2.2.3 
  77. * @param array $sharer->get_blog_services() Array of Sharing Services currently enabled. 
  78. */ 
  79. $enabled = apply_filters( 'sharing_enabled', $sharer->get_blog_services() ); 
  80.  
  81. if ( count( $enabled['all'] ) > 0 ) { 
  82. global $post; 
  83.  
  84. $dir = get_option( 'text_direction' ); 
  85.  
  86. // Wrapper 
  87. $sharing_content .= '<div class="sharedaddy sd-sharing-enabled"><div class="robots-nocontent sd-block sd-social sd-social-' . $global['button_style'] . ' sd-sharing">'; 
  88. if ( $global['sharing_label'] != '' ) 
  89. $sharing_content .= '<h3 class="sd-title">' . $global['sharing_label'] . '</h3>'; 
  90. $sharing_content .= '<div class="sd-content"><ul>'; 
  91.  
  92. // Visible items 
  93. $visible = ''; 
  94. foreach ( $enabled['visible'] as $id => $service ) { 
  95. // Individual HTML for sharing service 
  96. $visible .= '<li class="share-' . $service->get_class() . '">' . $service->get_display( $post ) . '</li>'; 
  97.  
  98. $parts = array(); 
  99. $parts[] = $visible; 
  100. if ( count( $enabled['hidden'] ) > 0 ) { 
  101. if ( count( $enabled['visible'] ) > 0 ) 
  102. $expand = __( 'More', jetpack ); 
  103. else 
  104. $expand = __( 'Share', jetpack ); 
  105. $parts[] = '<li><a href="#" class="sharing-anchor sd-button share-more"><span>'.$expand.'</span></a></li>'; 
  106.  
  107. if ( $dir == 'rtl' ) 
  108. $parts = array_reverse( $parts ); 
  109.  
  110. $sharing_content .= implode( '', $parts ); 
  111. $sharing_content .= '<li class="share-end"></li></ul>'; 
  112.  
  113. if ( count( $enabled['hidden'] ) > 0 ) { 
  114. $sharing_content .= '<div class="sharing-hidden"><div class="inner" style="display: none;'; 
  115.  
  116. if ( count( $enabled['hidden'] ) == 1 ) 
  117. $sharing_content .= 'width:150px;'; 
  118.  
  119. $sharing_content .= '">'; 
  120.  
  121. if ( count( $enabled['hidden'] ) == 1 ) 
  122. $sharing_content .= '<ul style="background-image:none;">'; 
  123. else 
  124. $sharing_content .= '<ul>'; 
  125.  
  126. $count = 1; 
  127. foreach ( $enabled['hidden'] as $id => $service ) { 
  128. // Individual HTML for sharing service 
  129. $sharing_content .= '<li class="share-'.$service->get_class().'">'; 
  130. $sharing_content .= $service->get_display( $post ); 
  131. $sharing_content .= '</li>'; 
  132.  
  133. if ( ( $count % 2 ) == 0 ) 
  134. $sharing_content .= '<li class="share-end"></li>'; 
  135.  
  136. $count ++; 
  137.  
  138. // End of wrapper 
  139. $sharing_content .= '<li class="share-end"></li></ul></div></div>'; 
  140.  
  141. $sharing_content .= '</div></div></div>'; 
  142.  
  143. // Register our JS 
  144. if ( defined( 'JETPACK__VERSION' ) ) { 
  145. $ver = JETPACK__VERSION
  146. } else { 
  147. $ver = '20141212'; 
  148. wp_register_script( 'sharing-js', plugin_dir_url( __FILE__ ).'sharing.js', array( 'jquery' ), $ver ); 
  149. add_action( 'wp_footer', 'sharing_add_footer' ); 
  150.  
  151. /** 
  152. * Filters the content markup of the Jetpack sharing links 
  153. * @module sharedaddy 
  154. * @since 3.8.0 
  155. * @param string $sharing_content Content markup of the Jetpack sharing links 
  156. */ 
  157. $sharing_markup = apply_filters( 'jetpack_sharing_display_markup', $sharing_content ); 
  158.  
  159. if ( $echo ) 
  160. echo $text . $sharing_markup; 
  161. else 
  162. return $text . $sharing_markup;