process_requests();
}
/**
* Save changes to sharing settings.
*
* @return void
*/
public function process_requests() {
if (
isset( $_POST['_wpnonce'] )
&& wp_verify_nonce( sanitize_key( wp_unslash( $_POST['_wpnonce'] ) ), 'sharing-options' )
) {
$sharer = new Sharing_Service();
$sharer->set_global_options( $_POST );
/**
* Fires when updating sharing settings.
*
* @module sharedaddy
*
* @since 1.1.0
*/
do_action( 'sharing_admin_update' );
wp_safe_redirect( admin_url( 'options-general.php?page=sharing&update=saved' ) );
die( 0 );
}
}
/**
* Register Sharing settings menu page in Settings > Sharing.
*/
public function subscription_menu() {
add_submenu_page(
'options-general.php',
__( 'Sharing Settings', 'jetpack' ),
__( 'Sharing', 'jetpack' ),
'manage_options',
'sharing',
array( $this, 'wrapper_admin_page' )
);
}
/**
* Save changes to sharing services via AJAX.
*
* @return void
*/
public function ajax_save_services() {
if (
isset( $_POST['_wpnonce'] )
&& wp_verify_nonce( sanitize_key( wp_unslash( $_POST['_wpnonce'] ) ), 'sharing-options' )
&& isset( $_POST['hidden'] )
&& isset( $_POST['visible'] )
) {
$sharer = new Sharing_Service();
$sharer->set_blog_services(
explode( ',', sanitize_text_field( wp_unslash( $_POST['visible'] ) ) ),
explode( ',', sanitize_text_field( wp_unslash( $_POST['hidden'] ) ) )
);
die( 0 );
}
}
/**
* Create a new custom sharing service via AJAX.
*
* @return never
*/
public function ajax_new_service() {
if (
isset( $_POST['_wpnonce'] )
&& isset( $_POST['sharing_name'] )
&& isset( $_POST['sharing_url'] )
&& isset( $_POST['sharing_icon'] )
&& wp_verify_nonce( sanitize_key( wp_unslash( $_POST['_wpnonce'] ) ), 'sharing-new_service' )
) {
$sharer = new Sharing_Service();
$service = $sharer->new_service(
sanitize_text_field( wp_unslash( $_POST['sharing_name'] ) ),
esc_url_raw( wp_unslash( $_POST['sharing_url'] ) ),
esc_url_raw( wp_unslash( $_POST['sharing_icon'] ) )
);
if ( $service ) {
$this->output_service( $service->get_id(), $service );
echo '';
$service->button_style = 'icon-text';
$this->output_preview( $service );
die( 0 );
}
}
// Fail
die( '1' );
}
/**
* Delete a sharing service via AJAX.
*
* @return void
*/
public function ajax_delete_service() {
if (
isset( $_POST['_wpnonce'] )
&& isset( $_POST['service'] )
&& wp_verify_nonce(
sanitize_key( wp_unslash( $_POST['_wpnonce'] ) ),
'sharing-options_' . sanitize_text_field( wp_unslash( $_POST['service'] ) )
)
) {
$sharer = new Sharing_Service();
$sharer->delete_service( sanitize_text_field( wp_unslash( $_POST['service'] ) ) );
}
}
/**
* Save changes to sharing settings via AJAX.
*
* @return void
*/
public function ajax_save_options() {
if (
isset( $_POST['_wpnonce'] )
&& isset( $_POST['service'] )
&& wp_verify_nonce(
sanitize_key( wp_unslash( $_POST['_wpnonce'] ) ),
'sharing-options_' . sanitize_text_field( wp_unslash( $_POST['service'] ) )
)
) {
$sharer = new Sharing_Service();
$service = $sharer->get_service( sanitize_text_field( wp_unslash( $_POST['service'] ) ) );
if ( $service && $service instanceof Sharing_Advanced_Source ) {
$service->update_options( $_POST );
$sharer->set_service( sanitize_text_field( wp_unslash( $_POST['service'] ) ), $service );
}
$this->output_service( $service->get_id(), $service, true );
echo '';
$service->button_style = 'icon-text';
$this->output_preview( $service );
die( 0 );
}
}
/**
* Display a preview of a sharing service.
*
* @param object $service Sharing service object.
*
* @return void
*/
public function output_preview( $service ) {
$klasses = array( 'advanced', 'preview-item' );
if ( $service->button_style !== 'text' || $service->has_custom_button_style() ) {
$klasses[] = 'preview-' . $service->get_class();
$klasses[] = 'share-' . $service->get_class();
if ( $service->is_deprecated() ) {
$klasses[] = 'share-deprecated';
}
if ( $service->get_class() !== $service->get_id() ) {
$klasses[] = 'preview-' . $service->get_id();
}
}
echo '
';
$service->display_preview();
echo '';
}
/**
* Display a specific sharing service.
*
* @param int $id Service unique ID.
* @param object $service Sharing service.
* @param bool $show_dropdown Display a dropdown. Not in use at the moment.
*
* @return void
*/
public function output_service( $id, $service, $show_dropdown = false ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
$title = '';
$klasses = array( 'service', 'advanced', 'share-' . $service->get_class() );
$displayed_klasses = implode( ' ', $klasses );
if ( $service->is_deprecated() ) {
/* translators: %1$s is the name of a deprecated Sharing Service like "Google+" */
$title = sprintf( __( 'The %1$s sharing service has shut down or discontinued support for sharing buttons. This sharing button is not displayed to your visitors and should be removed.', 'jetpack' ), $service->get_name() );
$klasses[] = 'share-deprecated';
}
?>
get_name() ); ?>
get_id(), 'custom-' ) || $service->has_advanced_options() ) : ?>
×
true ) );
}
/**
* Sharing settings inner page structure.
*
* @return void
*/
public function management_page() {
if ( ! function_exists( 'mb_stripos' ) ) {
echo '' . esc_html__( 'Warning! Multibyte support missing!', 'jetpack' ) . '
';
echo '
' . wp_kses(
sprintf(
/* Translators: placeholder is a link to a PHP support document. */
__( 'This plugin will work without it, but multibyte support is used if available. You may see minor problems with Tweets and other sharing services.', 'jetpack' ),
'https://www.php.net/manual/en/mbstring.installation.php'
),
array(
'a' => array(
'href' => array(),
'rel' => array(),
'target' => array(),
),
)
) . '
';
}
if ( isset( $_GET['update'] ) && 'saved' === $_GET['update'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- only used to display a message.
echo '' . esc_html__( 'Settings have been saved', 'jetpack' ) . '
';
}
?>
should_use_site_editor() && ! $is_simple_site;
// We either show old services config or the sharing block message.
if ( current_user_can( 'manage_options' ) ) :
$show_block_message ? $this->sharing_block_display() : $this->services_config_display();
endif;
?>
get_blog_services();
$global = $sharer->get_global_options();
$shows = array_values( get_post_types( array( 'public' => true ) ) );
array_unshift( $shows, 'index' );
if ( ! isset( $global['sharing_label'] ) ) {
$global['sharing_label'] = __( 'Share this:', 'jetpack' );
}
?>
should_use_site_editor() && $is_simple_site ) :
$this->site_editor_prompt_display();
?>
|
|
get_all_services_blog() as $id => $service ) : ?>
output_service( $id, $service );
}
?>
is_private_site() ) {
echo '' . esc_html__( 'Please note that your services have been restricted because your site is private.', 'jetpack' ) . ' ';
}
?>
|
|
0 ) {
echo ' style="display: none"';}
?>
>
$service ) : ?>
output_service( $id, $service, true ); ?>
|
$service ) : ?>
output_service( $id, $service, true ); ?>
|
|
|
0 ) ? ' style="display: none"' : ''; ?>>
0 ) : ?>
$service ) : ?>
output_preview( $service ); ?>
0 ) : ?>
0 ) : ?>
$service ) {
$this->output_preview( $service );
}
?>
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.
$service->smart = false;
$this->output_preview( $service );
endforeach;
?>
|
site_editor_prompt_display(); ?>
output_preview( $service ); ?>
disable Jetpack’s legacy sharing buttons and add a sharing block to your theme’s template instead.', 'jetpack' ),
array(
'a' => array( 'href' => array() ),
)
),
esc_url( admin_url( 'admin.php?page=jetpack#/sharing' ) )
);
?>
is_wpcom_platform() ? $wpcom_link : Redirect::get_url( 'jetpack-support-sharing-block' );
?>
ID, 'sharing_disabled' );
} else {
return update_post_meta( $post_object->ID, 'sharing_disabled', true );
}
}
/**
* Add Sharing post_meta to the REST API Post response.
*
* @action rest_api_init
* @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 ) {
register_rest_field(
$post_type,
'jetpack_sharing_enabled',
array(
'get_callback' => 'jetpack_post_sharing_get_value',
'update_callback' => 'jetpack_post_sharing_update_value',
'schema' => array(
'description' => __( 'Are sharing buttons enabled?', 'jetpack' ),
'type' => 'boolean',
),
)
);
/**
* 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.
*
* @return void
*/
function sharing_admin_init() {
global $sharing_admin;
$sharing_admin = new Sharing_Admin();
}
add_action( 'init', 'sharing_admin_init' );