<?php $this->output_preview( $service ); ?>
<?php if ( is_countable( $enabled['hidden'] ) && count( $enabled['hidden'] ) > 0 ) : ?>
<li class="advanced"><a href="#" class="sharing-anchor sd-button share-more"><span><?php esc_html_e( 'More', 'jetpack' ); ?></span></a></li>
<?php if ( is_countable( $enabled['hidden'] ) && count( $enabled['hidden'] ) > 0 ) : ?>
<div class="sharing-hidden">
<div class="inner" style="display: none; <?php echo count( $enabled['hidden'] ) === 1 ? 'width:150px;' : ''; ?>">
<?php if ( count( $enabled['hidden'] ) === 1 ) : ?>
<ul style="background-image:none;">
foreach ( $enabled['hidden'] as $id => $service ) {
$this->output_preview( $service );
<ul class="archive" style="display:none;">
foreach ( $sharer->get_all_services_blog() as $id => $service ) :
if ( isset( $enabled['visible'][ $id ] ) ) {
$service = $enabled['visible'][ $id ];
} elseif ( isset( $enabled['hidden'][ $id ] ) ) {
$service = $enabled['hidden'][ $id ];
$service->button_style = 'icon-text'; // The archive needs the full text, which is removed in JS later.
$this->output_preview( $service );
<li class="advanced"><a href="#" class="sharing-anchor sd-button share-more"><span><?php esc_html_e( 'More', 'jetpack' ); ?></span></a></li>
<form method="post" action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>" id="save-enabled-shares">
<input type="hidden" name="action" value="sharing_save_services" />
<input type="hidden" name="visible" value="<?php echo esc_attr( implode( ',', array_keys( $enabled['visible'] ) ) ); ?>" />
<input type="hidden" name="hidden" value="<?php echo esc_attr( implode( ',', array_keys( $enabled['hidden'] ) ) ); ?>" />
<input type="hidden" name="_wpnonce" value="<?php echo esc_attr( wp_create_nonce( 'sharing-options' ) ); ?>" />
<form method="post" action="">
<table class="form-table">
<th scope="row"><label><?php esc_html_e( 'Button style', 'jetpack' ); ?></label></th>
<select name="button_style" id="button_style">
<option<?php echo ( $global['button_style'] === 'icon-text' ) ? ' selected="selected"' : ''; ?> value="icon-text"><?php esc_html_e( 'Icon + text', 'jetpack' ); ?></option>
<option<?php echo ( $global['button_style'] === 'icon' ) ? ' selected="selected"' : ''; ?> value="icon"><?php esc_html_e( 'Icon only', 'jetpack' ); ?></option>
<option<?php echo ( $global['button_style'] === 'text' ) ? ' selected="selected"' : ''; ?> value="text"><?php esc_html_e( 'Text only', 'jetpack' ); ?></option>
<option<?php echo ( $global['button_style'] === 'official' ) ? ' selected="selected"' : ''; ?> value="official"><?php esc_html_e( 'Official buttons', 'jetpack' ); ?></option>
<th scope="row"><label><?php esc_html_e( 'Sharing label', 'jetpack' ); ?></label></th>
<input type="text" name="sharing_label" value="<?php echo esc_attr( $global['sharing_label'] ); ?>" />
* Filters the HTML at the beginning of the "Show button on" row.
* @param string $var Opening HTML tag at the beginning of the "Show button on" row.
echo apply_filters( 'sharing_show_buttons_on_row_start', '<tr valign="top">' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
<th scope="row"><label><?php esc_html_e( 'Show buttons on', 'jetpack' ); ?></label></th>
foreach ( $shows as $show ) :
if ( 'index' === $show ) {
$label = __( 'Front Page, Archive Pages, and Search Results', 'jetpack' );
$post_type_object = get_post_type_object( $show );
$label = $post_type_object->labels->name;
<label><input type="checkbox"<?php checked( in_array( $show, $global['show'], true ) ); ?> name="show[]" value="<?php echo esc_attr( $show ); ?>" /> <?php echo esc_html( $label ); ?></label>
* Filters the HTML at the end of the "Show button on" row.
* @param string $var Closing HTML tag at the end of the "Show button on" row.
echo apply_filters( 'sharing_show_buttons_on_row_end', '</tr>' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
* Fires at the end of the sharing global options settings table.
do_action( 'sharing_global_options' );
<input type="submit" name="submit" class="button-primary" value="<?php esc_attr_e( 'Save Changes', 'jetpack' ); ?>" />
<input type="hidden" name="_wpnonce" value="<?php echo esc_attr( wp_create_nonce( 'sharing-options' ) ); ?>" />
<div id="new-service" style="display: none">
<form method="post" action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>" id="new-service-form">
<table class="form-table">
<th scope="row" width="100"><label><?php esc_html_e( 'Service name', 'jetpack' ); ?></label></th>
<input type="text" name="sharing_name" id="new_sharing_name" size="40" />
<th scope="row" width="100"><label><?php esc_html_e( 'Sharing URL', 'jetpack' ); ?></label></th>
<input type="text" name="sharing_url" id="new_sharing_url" size="40" />
<p><?php esc_html_e( 'You can add the following variables to your service sharing URL:', 'jetpack' ); ?><br/>
<code>%post_id%</code>, <code>%post_title%</code>, <code>%post_slug%</code>, <code>%post_url%</code>, <code>%post_full_url%</code>, <code>%post_excerpt%</code>, <code>%post_tags%</code>, <code>%home_url%</code></p>
<th scope="row" width="100"><label><?php esc_html_e( 'Icon URL', 'jetpack' ); ?></label></th>
<input type="text" name="sharing_icon" id="new_sharing_icon" size="40" />
<p><?php esc_html_e( 'Enter the URL of a 16x16px icon you want to use for this service.', 'jetpack' ); ?></p>
<tr valign="top" width="100">
<input type="submit" class="button-primary" value="<?php esc_attr_e( 'Create Share Button', 'jetpack' ); ?>" />
<img src="<?php echo esc_url( admin_url( 'images/loading.gif' ) ); ?>" width="16" height="16" alt="loading" style="vertical-align: middle; display: none" />
* Fires after the custom sharing service form
do_action( 'sharing_new_service_form' );
* Fires at the bottom of the admin sharing settings screen.
do_action( 'post_admin_screen_sharing' );
<div class="inerror" style="display: none; margin-top: 15px">
<p><?php esc_html_e( 'An error occurred creating your new sharing service - please check you gave valid details.', 'jetpack' ); ?></p>
<input type="hidden" name="action" value="sharing_new_service" />
<input type="hidden" name="_wpnonce" value="<?php echo esc_attr( wp_create_nonce( 'sharing-new_service' ) ); ?>" />
* Display sharing block admin UI for settings.
public function sharing_block_display() {
$showcase_services = array(
new Share_Tumblr( 'tumblr', array() ),
new Share_Facebook( 'facebook', array() ),
new Share_Email( 'email', array() ),
new Share_Reddit( 'reddit', array() ),
// Hide the link to Jetpack Sharing settings if no Jetpack Settings found in submenu list
$show_jetpack_admin_settings_link = array_reduce(
function ( $carry, $item ) {
return $carry || ( isset( $item[2] ) && $item[2] === 'jetpack#/settings' );
$host = new Status\Host();
$wpcom_link = 'https://wordpress.com/support/wordpress-editor/blocks/sharing-buttons-block/';
if ( function_exists( 'localized_wpcom_url' ) ) {
$wpcom_link = localized_wpcom_url( $wpcom_link );
$link = $host->is_wpcom_platform() ? $wpcom_link : Redirect::get_url( 'jetpack-support-sharing-block' );
<div class="share_manage_options">
<h2><?php esc_html_e( 'Sharing Buttons', 'jetpack' ); ?></h2>
<div class="sharing-block-message__items-wrapper">
<p><?php esc_html_e( 'Add sharing buttons to your blog and allow your visitors to share posts with their friends.', 'jetpack' ); ?></p>
<div class="sharing-block-message__buttons-wrapper">
<a href="<?php echo esc_url( admin_url( 'site-editor.php?path=%2Fwp_template' ) ); ?>" class="button button-primary">
<?php esc_html_e( 'Go to the site editor', 'jetpack' ); ?>
<a data-target="wpcom-help-center" href="<?php echo esc_url( $link ); ?>" class="button" target="_blank" rel="noopener noreferrer">
<?php esc_html_e( 'Learn how to add Sharing Buttons', 'jetpack' ); ?>
<p><?php esc_html_e( 'Sharing Buttons example:', 'jetpack' ); ?></p>
<div class="sharedaddy sd-sharing-enabled">
<?php foreach ( $showcase_services as $service ) : ?>
<?php $this->output_preview( $service ); ?>
<?php if ( $show_jetpack_admin_settings_link ) : ?>
<p class="settings-sharing__block-theme-description">
/* translators: Link to Jetpack sharing settings. */
__( 'You are using a block-based theme. You can <a class="dops-card__link" href="%s">disable Jetpack’s legacy sharing buttons</a> and add a sharing block to your theme’s template instead.', 'jetpack' ),
'a' => array( 'href' => array() ),
esc_url( admin_url( 'admin.php?page=jetpack#/sharing' ) )
* Callback to get the value for the jetpack_sharing_enabled field.
* When the sharing_disabled post_meta is unset, we follow the global setting in Sharing.
* When it is set to 1, we disable sharing on the post, regardless of the global setting.
* It is not possible to enable sharing on a post if it is disabled globally.
* @param array $post The post object.
function jetpack_post_sharing_get_value( array $post ) {
if ( ! isset( $post['id'] ) ) {
// if sharing IS disabled on this post, enabled=false, so negate the meta
return (bool) ! get_post_meta( $post['id'], 'sharing_disabled', true );
* Callback to set sharing_disabled post_meta when the
* jetpack_sharing_enabled field is updated.
* When the sharing_disabled post_meta is unset, we follow the global setting in Sharing.
* When it is set to 1, we disable sharing on the post, regardless of the global setting.
* It is not possible to enable sharing on a post if it is disabled globally.
* @param bool $enable_sharing Should sharing be enabled on this post.
* @param WP_Post $post_object The post object.
function jetpack_post_sharing_update_value( $enable_sharing, $post_object ) {
// delete the override if we want to enable sharing
return delete_post_meta( $post_object->ID, 'sharing_disabled' );
return update_post_meta( $post_object->ID, 'sharing_disabled', true );
* Add Sharing post_meta to the REST API Post response.
* @uses register_rest_field
* @link https://developer.wordpress.org/rest-api/extending-the-rest-api/modifying-responses/
function jetpack_post_sharing_register_rest_field() {
$post_types = get_post_types( array( 'public' => true ) );
foreach ( $post_types as $post_type ) {
'jetpack_sharing_enabled',
'get_callback' => 'jetpack_post_sharing_get_value',
'update_callback' => 'jetpack_post_sharing_update_value',
'description' => __( 'Are sharing buttons enabled?', 'jetpack' ),
* Ensures all public internal post-types support `sharing`
* This feature support flag is used by the REST API and Gutenberg.
add_post_type_support( $post_type, 'jetpack-sharing-buttons' );
// Add Sharing post_meta to the REST API Post response.
add_action( 'rest_api_init', 'jetpack_post_sharing_register_rest_field' );
// Some CPTs (e.g. Jetpack portfolios and testimonials) get registered with
// restapi_theme_init because they depend on theme support, so let's also hook to that
add_action( 'restapi_theme_init', 'jetpack_post_likes_register_rest_field', 20 );
* Initialize sharing settings in WP Admin.
function sharing_admin_init() {
$sharing_admin = new Sharing_Admin();
add_action( 'init', 'sharing_admin_init' );