PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.2
Jetpack – WP Security, Backup, Speed, & Growth v16.2
16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 All 502 releases
← All changes | modules/sharedaddy/sharing.php +192 -69 12.2.316.2 View file →
@@ -7,10 +7,15 @@
7 7
8 8 // phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files.
9 9
10 10 use Automattic\Jetpack\Assets;
11 +use Automattic\Jetpack\Redirect;
11 12 use Automattic\Jetpack\Status;
12 13
14 +if ( ! defined( 'ABSPATH' ) ) {
15 + exit( 0 );
16 +}
17 +
13 18 if ( ! defined( 'WP_SHARING_PLUGIN_URL' ) ) {
14 19 define( 'WP_SHARING_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
15 20 define( 'WP_SHARING_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
16 21 }
@@ -26,9 +31,13 @@
26 31 */
27 32 public function __construct() {
28 33 require_once WP_SHARING_PLUGIN_DIR . 'sharing-service.php';
29 34
30 - add_action( 'admin_init', array( $this, 'admin_init' ) );
35 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- nonces are handled in process_requests.
36 + if ( isset( $_GET['page'] ) && ( $_GET['page'] === 'sharing.php' || $_GET['page'] === 'sharing' ) ) {
37 + add_action( 'admin_init', array( $this, 'admin_init' ) );
38 + }
39 +
31 40 add_action( 'admin_menu', array( $this, 'subscription_menu' ) );
32 41
33 42 // Insert our CSS and JS
34 43 add_action( 'load-settings_page_sharing', array( $this, 'sharing_head' ) );
@@ -52,9 +61,9 @@
52 61 '_inc/build/sharedaddy/admin-sharing.min.js',
53 62 'modules/sharedaddy/admin-sharing.js'
54 63 ),
55 64 array( 'jquery', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'jquery-form' ),
56 - 2,
65 + JETPACK__VERSION,
57 66 false
58 67 );
59 68
60 69 /**
@@ -88,11 +97,9 @@
88 97 *
89 98 * @return void
90 99 */
91 100 public function admin_init() {
92 - if ( isset( $_GET['page'] ) && ( $_GET['page'] === 'sharing.php' || $_GET['page'] === 'sharing' ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- nonces are handled in process_requests.
93 - $this->process_requests();
94 - }
101 + $this->process_requests();
95 102 }
96 103
97 104 /**
98 105 * Save changes to sharing settings.
@@ -115,31 +122,21 @@
115 122 */
116 123 do_action( 'sharing_admin_update' );
117 124
118 125 wp_safe_redirect( admin_url( 'options-general.php?page=sharing&update=saved' ) );
119 - die();
126 + die( 0 );
120 127 }
121 128 }
122 129
123 130 /**
124 - * Register Sharing settings menu page.
131 + * Register Sharing settings menu page in Settings > Sharing.
125 132 */
126 133 public function subscription_menu() {
127 - if ( ! defined( 'IS_WPCOM' ) || ! IS_WPCOM ) {
128 - $active = Jetpack::get_active_modules();
129 - if (
130 - ! in_array( 'publicize', $active, true )
131 - && ! current_user_can( 'manage_options' )
132 - ) {
133 - return;
134 - }
135 - }
136 -
137 134 add_submenu_page(
138 135 'options-general.php',
139 136 __( 'Sharing Settings', 'jetpack' ),
140 137 __( 'Sharing', 'jetpack' ),
141 - 'publish_posts',
138 + 'manage_options',
142 139 'sharing',
143 140 array( $this, 'wrapper_admin_page' )
144 141 );
145 142 }
@@ -161,9 +158,9 @@
161 158 $sharer->set_blog_services(
162 159 explode( ',', sanitize_text_field( wp_unslash( $_POST['visible'] ) ) ),
163 160 explode( ',', sanitize_text_field( wp_unslash( $_POST['hidden'] ) ) )
164 161 );
165 - die();
162 + die( 0 );
166 163 }
167 164 }
168 165
169 166 /**
@@ -168,9 +165,9 @@
168 165
169 166 /**
170 167 * Create a new custom sharing service via AJAX.
171 168 *
172 - * @return void
169 + * @return never
173 170 */
174 171 public function ajax_new_service() {
175 172 if (
176 173 isset( $_POST['_wpnonce'] )
@@ -191,9 +188,9 @@
191 188 echo '<!--->';
192 189 $service->button_style = 'icon-text';
193 190 $this->output_preview( $service );
194 191
195 - die();
192 + die( 0 );
196 193 }
197 194 }
198 195
199 196 // Fail
@@ -245,9 +242,9 @@
245 242 $this->output_service( $service->get_id(), $service, true );
246 243 echo '<!--->';
247 244 $service->button_style = 'icon-text';
248 245 $this->output_preview( $service );
249 - die();
246 + die( 0 );
250 247 }
251 248 }
252 249
253 250 /**
@@ -292,9 +289,9 @@
292 289 $displayed_klasses = implode( ' ', $klasses );
293 290
294 291 if ( $service->is_deprecated() ) {
295 292 /* translators: %1$s is the name of a deprecated Sharing Service like "Google+" */
296 - $title = sprintf( __( 'The %1$s service has shut down. This sharing button is not displayed to your visitors and should be removed.', 'jetpack' ), $service->get_name() );
293 + $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() );
297 294 $klasses[] = 'share-deprecated';
298 295 }
299 296
300 297 ?>
@@ -299,9 +296,9 @@
299 296
300 297 ?>
301 298 <li class="<?php echo esc_attr( $displayed_klasses ); ?>" id="<?php echo esc_attr( $service->get_id() ); ?>" tabindex="0" title="<?php echo esc_attr( $title ); ?>">
302 299 <span class="options-left"><?php echo esc_html( $service->get_name() ); ?></span>
303 - <?php if ( 0 === strpos( $service->get_id(), 'custom-' ) || $service->has_advanced_options() ) : ?>
300 + <?php if ( str_starts_with( $service->get_id(), 'custom-' ) || $service->has_advanced_options() ) : ?>
304 301 <span class="close"><a href="#" class="remove">&times;</a></span>
305 302 <form method="post" action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>">
306 303 <input type="hidden" name="action" value="sharing_delete_service" />
307 304 <input type="hidden" name="service" value="<?php echo esc_attr( $id ); ?>" />
@@ -326,15 +323,9 @@
326 323 *
327 324 * @return void
328 325 */
329 326 public function management_page() {
330 - $sharer = new Sharing_Service();
331 - $enabled = $sharer->get_blog_services();
332 - $global = $sharer->get_global_options();
333 327
334 - $shows = array_values( get_post_types( array( 'public' => true ) ) );
335 - array_unshift( $shows, 'index' );
336 -
337 328 if ( ! function_exists( 'mb_stripos' ) ) {
338 329 echo '<div id="message" class="updated fade"><h3>' . esc_html__( 'Warning! Multibyte support missing!', 'jetpack' ) . '</h3>';
339 330 echo '<p>' . wp_kses(
340 331 sprintf(
@@ -354,12 +345,8 @@
354 345
355 346 if ( isset( $_GET['update'] ) && 'saved' === $_GET['update'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- only used to display a message.
356 347 echo '<div class="updated"><p>' . esc_html__( 'Settings have been saved', 'jetpack' ) . '</p></div>';
357 348 }
358 -
359 - if ( ! isset( $global['sharing_label'] ) ) {
360 - $global['sharing_label'] = __( 'Share this:', 'jetpack' );
361 - }
362 349 ?>
363 350
364 351 <div class="wrap">
365 352 <div class="icon32" id="icon-options-general"><br /></div>
@@ -375,14 +362,87 @@
375 362 */
376 363 do_action( 'pre_admin_screen_sharing' );
377 364 ?>
378 365
379 - <?php if ( current_user_can( 'manage_options' ) ) : ?>
366 + <?php
367 + $is_simple_site = defined( 'IS_WPCOM' ) && IS_WPCOM;
368 + $show_block_message = $this->should_use_site_editor() && ! $is_simple_site;
380 369
370 + // We either show old services config or the sharing block message.
371 + if ( current_user_can( 'manage_options' ) ) :
372 + $show_block_message ? $this->sharing_block_display() : $this->services_config_display();
373 + endif;
374 + ?>
375 + </div>
376 +
377 + <script type="text/javascript">
378 + var sharing_loading_icon = <?php echo wp_json_encode( admin_url( '/images/loading.gif' ), JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ); ?>;
379 + <?php
380 + // phpcs:disable WordPress.Security.NonceVerification.Recommended -- we handle the nonce on the PHP side.
381 + if (
382 + isset( $_GET['create_new_service'] ) && isset( $_GET['name'] ) && isset( $_GET['url'] ) && isset( $_GET['icon'] )
383 + && 'true' == $_GET['create_new_service'] // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual
384 + ) :
385 + ?>
386 + jQuery(document).ready(function() {
387 + // Prefill new service box and then open it
388 + jQuery( '#new_sharing_name' ).val( <?php echo wp_json_encode( sanitize_text_field( wp_unslash( $_GET['name'] ) ), JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ); ?> );
389 + jQuery( '#new_sharing_url' ).val( <?php echo wp_json_encode( sanitize_text_field( wp_unslash( $_GET['url'] ) ), JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ); ?> );
390 + jQuery( '#new_sharing_icon' ).val( <?php echo wp_json_encode( sanitize_text_field( wp_unslash( $_GET['icon'] ) ), JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ); ?> );
391 + jQuery( '#add-a-new-service' ).click();
392 + });
393 + <?php endif; ?>
394 + </script>
395 + <?php
396 + // phpcs:enable WordPress.Security.NonceVerification.Recommended
397 + }
398 +
399 + /**
400 + * Check if we should encourage to use the site editor instead of the legacy sharing settings.
401 + *
402 + * @return boolean
403 + */
404 + public function should_use_site_editor() {
405 + $block_availability = Jetpack_Gutenberg::get_cached_availability();
406 + $is_block_available = isset( $block_availability['sharing-buttons'] ) && $block_availability['sharing-buttons']['available'];
407 + $is_block_theme = wp_is_block_theme();
408 + return $is_block_available && $is_block_theme;
409 + }
410 +
411 + /**
412 + * Display services admin UI for settings.
413 + *
414 + * @return void
415 + */
416 + public function services_config_display() {
417 + $sharer = new Sharing_Service();
418 + $enabled = $sharer->get_blog_services();
419 + $global = $sharer->get_global_options();
420 +
421 + $shows = array_values( get_post_types( array( 'public' => true ) ) );
422 + array_unshift( $shows, 'index' );
423 + if ( ! isset( $global['sharing_label'] ) ) {
424 + $global['sharing_label'] = __( 'Share this:', 'jetpack' );
425 + }
426 + ?>
381 427 <div class="share_manage_options">
382 428 <h2><?php esc_html_e( 'Sharing Buttons', 'jetpack' ); ?></h2>
383 429 <p><?php esc_html_e( 'Add sharing buttons to your blog and allow your visitors to share posts with their friends.', 'jetpack' ); ?></p>
384 430
431 + <?php
432 + $is_simple_site = defined( 'IS_WPCOM' ) && IS_WPCOM;
433 + if ( $this->should_use_site_editor() && $is_simple_site ) :
434 + $this->site_editor_prompt_display();
435 + ?>
436 + <div class="notice notice-info inline">
437 + <p>
438 + <?php esc_html_e( 'You are using a block-based theme. We recommend that you disable the legacy sharing features below and add a sharing button block to your theme’s template instead.', 'jetpack' ); ?>
439 + </p>
440 + </div>
441 + <?php
442 + endif;
443 + ?>
444 +
385 445 <div id="services-config">
386 446 <table id="available-services">
387 447 <tr>
388 448 <td class="description">
@@ -414,9 +474,9 @@
414 474 <tr>
415 475 <td class="description">
416 476 <h3>
417 477 <?php esc_html_e( 'Enabled Services', 'jetpack' ); ?>
418 - <img src="<?php echo esc_url( admin_url( 'images/loading.gif' ) ); ?>" width="16" height="16" alt="loading" style="vertical-align: middle; display: none" />
478 + <span class="spinner" style="vertical-align: middle"></span>
419 479 </h3>
420 480 <p><?php esc_html_e( 'Services dragged here will appear individually.', 'jetpack' ); ?></p>
421 481 </td>
422 482 <td class="services" id="share-drop-target">
@@ -637,9 +697,9 @@
637 697 <tr valign="top" width="100">
638 698 <th scope="row"></th>
639 699 <td>
640 700 <input type="submit" class="button-primary" value="<?php esc_attr_e( 'Create Share Button', 'jetpack' ); ?>" />
641 - <img src="<?php echo esc_url( admin_url( 'images/loading.gif' ) ); ?>" width="16" height="16" alt="loading" style="vertical-align: middle; display: none" />
701 + <span class="spinner" style="vertical-align: middle"></span>
642 702 </td>
643 703 </tr>
644 704
645 705 <?php
@@ -673,35 +733,103 @@
673 733 <input type="hidden" name="action" value="sharing_new_service" />
674 734 <input type="hidden" name="_wpnonce" value="<?php echo esc_attr( wp_create_nonce( 'sharing-new_service' ) ); ?>" />
675 735 </form>
676 736 </div>
677 - </div>
737 + <?php
738 + }
678 739
679 - <?php endif; ?>
740 + /**
741 + * Display sharing block admin UI for settings.
742 + *
743 + * @return void
744 + */
745 + public function sharing_block_display() {
746 + $showcase_services = array(
747 + new Share_Tumblr( 'tumblr', array() ),
748 + new Share_Facebook( 'facebook', array() ),
749 + new Share_Email( 'email', array() ),
750 + new Share_Reddit( 'reddit', array() ),
751 + );
680 752
753 + global $submenu;
754 + // Hide the link to Jetpack Sharing settings if no Jetpack Settings found in submenu list
755 + $show_jetpack_admin_settings_link = array_reduce(
756 + $submenu['jetpack'],
757 + function ( $carry, $item ) {
758 + return $carry || ( isset( $item[2] ) && $item[2] === 'jetpack#/settings' );
759 + },
760 + false
761 + );
762 + ?>
681 763
682 - </div>
764 + <div class="share_manage_options">
765 + <br class="clearing" />
766 + <h2><?php esc_html_e( 'Sharing Buttons', 'jetpack' ); ?></h2>
767 + <div class="sharing-block-message__items-wrapper">
768 + <div>
769 + <p><?php esc_html_e( 'Add sharing buttons to your blog and allow your visitors to share posts with their friends.', 'jetpack' ); ?></p>
770 + <?php $this->site_editor_prompt_display(); ?>
771 + </div>
772 + <div>
773 + <p><?php esc_html_e( 'Sharing Buttons example:', 'jetpack' ); ?></p>
774 + <div class="sharedaddy sd-sharing-enabled">
775 + <div class="sd-content">
776 + <ul class="preview">
777 + <?php foreach ( $showcase_services as $service ) : ?>
778 + <?php $this->output_preview( $service ); ?>
779 + <?php endforeach; ?>
780 + </ul>
781 + </div>
782 + </div>
783 + </div>
784 + <?php if ( $show_jetpack_admin_settings_link ) : ?>
785 + <p class="settings-sharing__block-theme-description">
786 + <?php
787 + printf(
788 + wp_kses(
789 + /* translators: Link to Jetpack sharing settings. */
790 + __( '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' ),
791 + array(
792 + 'a' => array( 'href' => array() ),
793 + )
794 + ),
795 + esc_url( admin_url( 'admin.php?page=jetpack#/sharing' ) )
796 + );
797 + ?>
798 + </p>
799 + <?php endif; ?>
800 + </div>
801 + <br class="clearing" />
802 + </div>
803 + <?php
804 + }
683 805
684 - <script type="text/javascript">
685 - var sharing_loading_icon = '<?php echo esc_js( admin_url( '/images/loading.gif' ) ); ?>';
806 + /**
807 + * Display the "Go to the site editor" prompt.
808 + *
809 + * @return void
810 + */
811 + public function site_editor_prompt_display() {
812 + $host = new Status\Host();
813 +
814 + $wpcom_link = 'https://wordpress.com/support/wordpress-editor/blocks/sharing-buttons-block/';
815 +
816 + if ( function_exists( 'localized_wpcom_url' ) ) {
817 + $wpcom_link = localized_wpcom_url( $wpcom_link );
818 + }
819 +
820 + $link = $host->is_wpcom_platform() ? $wpcom_link : Redirect::get_url( 'jetpack-support-sharing-block' );
821 +
822 + ?>
823 + <div class="sharing-block-message__buttons-wrapper">
824 + <a href="<?php echo esc_url( admin_url( 'site-editor.php?path=%2Fwp_template' ) ); ?>" class="button button-primary">
825 + <?php esc_html_e( 'Go to the site editor', 'jetpack' ); ?>
826 + </a>
827 + <a data-target="wpcom-help-center" href="<?php echo esc_url( $link ); ?>" class="button" target="_blank" rel="noopener noreferrer">
828 + <?php esc_html_e( 'Learn how to add Sharing Buttons', 'jetpack' ); ?>
829 + </a>
830 + </div>
686 831 <?php
687 - // phpcs:disable WordPress.Security.NonceVerification.Recommended -- we handle the nonce on the PHP side.
688 - if (
689 - isset( $_GET['create_new_service'] ) && isset( $_GET['name'] ) && isset( $_GET['url'] ) && isset( $_GET['icon'] )
690 - && 'true' == $_GET['create_new_service'] // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual
691 - ) :
692 - ?>
693 - jQuery(document).ready(function() {
694 - // Prefill new service box and then open it
695 - jQuery( '#new_sharing_name' ).val( '<?php echo esc_js( sanitize_text_field( wp_unslash( $_GET['name'] ) ) ); ?>' );
696 - jQuery( '#new_sharing_url' ).val( '<?php echo esc_js( sanitize_text_field( wp_unslash( $_GET['url'] ) ) ); ?>' );
697 - jQuery( '#new_sharing_icon' ).val( '<?php echo esc_js( sanitize_text_field( wp_unslash( $_GET['icon'] ) ) ); ?>' );
698 - jQuery( '#add-a-new-service' ).click();
699 - });
700 - <?php endif; ?>
701 - </script>
702 - <?php
703 - // phpcs:enable WordPress.Security.NonceVerification.Recommended
704 832 }
705 833 }
706 834
707 835 /**
@@ -715,10 +843,14 @@
715 843 *
716 844 * @return bool
717 845 */
718 846 function jetpack_post_sharing_get_value( array $post ) {
847 + if ( ! isset( $post['id'] ) ) {
848 + return false;
849 + }
850 +
719 851 // if sharing IS disabled on this post, enabled=false, so negate the meta
720 - return (bool) ! get_post_meta( $post['id'], 'sharing_disabled', true );
852 + return ! get_post_meta( $post['id'], 'sharing_disabled', true );
721 853 }
722 854
723 855 /**
724 856 * Callback to set sharing_disabled post_meta when the
@@ -789,15 +921,6 @@
789 921 global $sharing_admin;
790 922
791 923 $sharing_admin = new Sharing_Admin();
792 924 }
793 -
794 -/**
795 - * Set the Likes and Sharing Gutenberg extension as available
796 - */
797 -function jetpack_sharing_set_extension_availability() {
798 - Jetpack_Gutenberg::set_extension_available( 'sharing' );
799 -}
800 -
801 -add_action( 'jetpack_register_gutenberg_extensions', 'jetpack_sharing_set_extension_availability' );
802 925
803 926 add_action( 'init', 'sharing_admin_init' );