$opts = $this->get_options();
if ( $this->button_style !== 'icon' ) {
$text = $this->get_name();
$klasses = array( 'share-' . $this->shortname );
if ( $this->button_style === 'icon' || $this->button_style === 'icon-text' ) {
$klasses[] = 'share-icon';
if ( $this->button_style === 'icon' ) {
if ( $this->button_style === 'text' ) {
'<a rel="nofollow" class="%s" href="javascript:void(0)" title="%s"><span style="background-image:url("%s") !important;background-position:left center;background-repeat:no-repeat;">%s</span></a>',
esc_attr( implode( ' ', $klasses ) ),
esc_attr( $this->get_name() ),
addcslashes( esc_url_raw( $opts['icon'] ), '"' ),
<div class="option option-smart-off">
<?php echo $link; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped above. ?>
* Tumblr sharing service.
class Share_Tumblr extends Sharing_Source {
public $shortname = 'tumblr';
* Service icon font code.
* @param int $id Sharing source ID.
* @param array $settings Sharing settings.
public function __construct( $id, array $settings ) {
parent::__construct( $id, $settings );
if ( 'official' === $this->button_style ) {
public function get_name() {
return __( 'Tumblr', 'jetpack' );
* Get the markup of the sharing button.
* @param WP_Post $post Post object.
public function get_display( $post ) {
if ( true === $this->open_link_in_new ) {
* If we are looking at a single post, let Tumblr figure out the post type (text, photo, link, quote, chat, or video)
* based on the content available on the page.
* If we are not looking at a single post, content from other posts can appear on the page and Tumblr will pick that up.
* In this case, we want Tumblr to focus on our current post, so we will limit the post type to link, where we can give Tumblr a link to our post.
$posttype = 'data-posttype="link"';
// Documentation: https://www.tumblr.com/docs/en/share_button
'<a class="tumblr-share-button" target="%1$s" href="%2$s" data-title="%3$s" data-content="%4$s" title="%5$s"%6$s>%5$s</a>',
'https://www.tumblr.com/share',
$this->get_share_title( $post->ID ),
$this->get_share_url( $post->ID ),
__( 'Share on Tumblr', 'jetpack' ),
return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Tumblr', 'share to', 'jetpack' ), __( 'Share on Tumblr', 'jetpack' ), 'share=tumblr', 'sharing-tumblr-' . $post->ID );
* Process sharing request. Add actions that need to happen when sharing here.
* @param WP_Post $post Post object.
* @param array $post_data Array of information about the post we're sharing.
public function process_request( $post, array $post_data ) {
parent::process_request( $post, $post_data );
// Redirect to Tumblr's sharing endpoint (a la their bookmarklet)
$url = 'https://www.tumblr.com/share?v=3&u=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&t=' . rawurlencode( $this->get_share_title( $post->ID ) ) . '&s=';
parent::redirect_request( $url );
* Add content specific to a service in the footer.
public function display_footer() {
// phpcs:disable WordPress.WP.EnqueuedResources.NonEnqueuedScript
<script id="tumblr-js" type="text/javascript" src="https://assets.tumblr.com/share-button.js"></script>
// phpcs:enable WordPress.WP.EnqueuedResources.NonEnqueuedScript
* Pinterest sharing service.
class Share_Pinterest extends Sharing_Source {
public $shortname = 'pinterest';
* Service icon font code.
* @param int $id Sharing source ID.
* @param array $settings Sharing settings.
public function __construct( $id, array $settings ) {
parent::__construct( $id, $settings );
if ( 'official' === $this->button_style ) {
public function get_name() {
return __( 'Pinterest', 'jetpack' );
* Get image representative of the post to pass on to Pinterest.
* @param WP_Post $post Post object.
public function get_image( $post ) {
$image = Images::get_image( $post->ID, array( 'fallback_to_avatars' => true ) );
if ( ! empty( $image ) ) {
* Filters the default image used by the Pinterest Pin It share button.
* @param string $url Default image URL.
return apply_filters( 'jetpack_sharing_pinterest_default_image', 'https://s0.wp.com/i/blank.jpg' );
* Get Pinterest external sharing URL.
* @param WP_Post $post Post object.
public function get_external_url( $post ) {
$url = 'https://www.pinterest.com/pin/create/button/?url=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&media=' . rawurlencode( $this->get_image( $post ) ) . '&description=' . rawurlencode( $post->post_title );
* Filters the Pinterest share URL used in sharing button output.
* @param string $url Pinterest share URL.
return apply_filters( 'jetpack_sharing_pinterest_share_url', $url );
* Get Pinterest widget type.
public function get_widget_type() {
* Filters the Pinterest widget type.
* @see https://business.pinterest.com/en/widget-builder
* @param string $type Pinterest widget type. Default of 'buttonPin' for single-image selection. 'buttonBookmark' for multi-image modal.
return apply_filters( 'jetpack_sharing_pinterest_widget_type', 'buttonPin' );
* Get the markup of the sharing button.
* @param WP_Post $post Post object.
public function get_display( $post ) {
'<div class="pinterest_button"><a href="%s" data-pin-do="%s" data-pin-config="beside"><img src="//assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png" /></a></div>',
esc_url( $this->get_external_url( $post ) ),
esc_attr( $this->get_widget_type() )
$display = $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Pinterest', 'share to', 'jetpack' ), __( 'Share on Pinterest', 'jetpack' ), 'share=pinterest', 'sharing-pinterest-' . $post->ID );
/** This filter is already documented in modules/sharedaddy/sharing-sources.php */
if ( apply_filters( 'jetpack_register_post_for_share_counts', true, $post->ID, 'linkedin' ) ) {
sharing_register_post_for_share_counts( $post->ID );
* Process sharing request. Add actions that need to happen when sharing here.
* @param WP_Post $post Post object.
* @param array $post_data Array of information about the post we're sharing.
public function process_request( $post, array $post_data ) {
parent::process_request( $post, $post_data );
// If we're triggering the multi-select panel, then we don't need to redirect to Pinterest
if ( ! isset( $_GET['js_only'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
$pinterest_url = esc_url_raw( $this->get_external_url( $post ) );
parent::redirect_request( $pinterest_url );
echo '// share count bumped';
* Add content specific to a service in the footer.
public function display_footer() {
* Filter the Pin it button appearing when hovering over images when using the official button style.
* @param bool $jetpack_pinit_over True by default, displays the Pin it button when hovering over images.
$jetpack_pinit_over = apply_filters( 'jetpack_pinit_over_button', true );
<?php if ( $this->smart ) : ?>
<script type="text/javascript">
// Pinterest shared resources
var s = document.createElement( 'script' );
s.type = 'text/javascript';
if ( $jetpack_pinit_over ) {
echo "s.setAttribute( 'data-pin-hover', true );";
s.src = window.location.protocol + '//assets.pinterest.com/js/pinit.js';
var x = document.getElementsByTagName( 'script' )[ 0 ];
x.parentNode.insertBefore(s, x);
// if 'Pin it' button has 'counts' make container wider
var shares = document.querySelectorAll( 'li.share-pinterest' );
for ( var i = 0; i < shares.length; i++ ) {
var countElement = share.querySelector( 'a span' );
var countComputedStyle = window.getComputedStyle(countElement);
if ( countComputedStyle.display === 'block' ) {
var countWidth = parseInt( countComputedStyle.width, 10 );
share.style.marginRight = countWidth + 11 + 'px';
if ( document.readyState !== 'complete' ) {
document.addEventListener( 'load', init );
<?php elseif ( 'buttonPin' !== $this->get_widget_type() ) : ?>
<script type="text/javascript">
document.body.addEventListener( 'click', function ( e ) {
e.target.matches && e.target.matches( 'a.share-pinterest' ) ||
e.target.msMatchesSelector && e.target.msMatchesSelector( 'a.share-pinterest' )
// Load Pinterest Bookmarklet code
var s = document.createElement( 'script' );
s.type = 'text/javascript';
s.src = window.location.protocol + '//assets.pinterest.com/js/pinmarklet.js?r=' + ( Math.random() * 99999999 );
var x = document.getElementsByTagName( 'script' )[ 0 ];
x.parentNode.insertBefore( s, x );
var s = document.createElement( 'script' );
s.type = 'text/javascript';
s.src = e.target.href + ( e.target.href.indexOf( '?' ) ? '&' : '?' ) + 'js_only=1';
var x = document.getElementsByTagName( 'script' )[ '0' ];
x.parentNode.insertBefore( s, x );
if ( document.readyState === 'loading' ) {
document.addEventListener( 'DOMContentLoaded', init );
* Telegram sharing service.
class Share_Telegram extends Sharing_Source {
public $shortname = 'telegram';
* @param int $id Sharing source ID.
* @param array $settings Sharing settings.
public function __construct( $id, array $settings ) { // phpcs:ignore Generic.CodeAnalysis.UselessOverridingMethod.Found
parent::__construct( $id, $settings );
public function get_name() {
return __( 'Telegram', 'jetpack' );
* Process sharing request. Add actions that need to happen when sharing here.
* @param WP_Post $post Post object.
* @param array $post_data Array of information about the post we're sharing.
public function process_request( $post, array $post_data ) {
parent::process_request( $post, $post_data );
$telegram_url = esc_url_raw( 'https://telegram.me/share/url?url=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&text=' . rawurlencode( $this->get_share_title( $post->ID ) ) );
parent::redirect_request( $telegram_url );
* Get the markup of the sharing button.
* @param WP_Post $post Post object.
public function get_display( $post ) {
return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Telegram', 'share to', 'jetpack' ), __( 'Share on Telegram', 'jetpack' ), 'share=telegram', 'sharing-telegram-' . $post->ID );
* AMP display for Telegram.
* @param \WP_Post $post The current post being viewed.
public function get_amp_display( $post ) {
'data-share-endpoint' => esc_url_raw( 'https://telegram.me/share/url?url=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&text=' . rawurlencode( $this->get_share_title( $post->ID ) ) ),
return $this->build_amp_markup( $attrs );
* Add content specific to a service in the footer.
public function display_footer() {
* WhatsApp sharing service.
class Jetpack_Share_WhatsApp extends Sharing_Source {