PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.2
Jetpack – WP Security, Backup, Speed, & Growth v16.2
16.3-a.1 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 All 503 releases
← All changes | modules/sharedaddy/sharing.php +81 -42 14.2.216.2 View file →
@@ -7,12 +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\Connection\Manager as Connection_Manager;
12 11 use Automattic\Jetpack\Redirect;
13 12 use Automattic\Jetpack\Status;
14 13
14 +if ( ! defined( 'ABSPATH' ) ) {
15 + exit( 0 );
16 +}
17 +
15 18 if ( ! defined( 'WP_SHARING_PLUGIN_URL' ) ) {
16 19 define( 'WP_SHARING_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
17 20 define( 'WP_SHARING_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
18 21 }
@@ -119,33 +122,24 @@
119 122 */
120 123 do_action( 'sharing_admin_update' );
121 124
122 125 wp_safe_redirect( admin_url( 'options-general.php?page=sharing&update=saved' ) );
123 - die();
126 + die( 0 );
124 127 }
125 128 }
126 129
127 130 /**
128 - * Register Sharing settings menu page in offline mode or when wp-admin interface is enabled.
131 + * Register Sharing settings menu page in Settings > Sharing.
129 132 */
130 133 public function subscription_menu() {
131 - $wpcom_is_wp_admin_interface = get_option( 'wpcom_admin_interface' ) === 'wp-admin';
132 - $is_user_connected = ( new Connection_Manager() )->is_user_connected();
133 -
134 - if (
135 - ( new Status() )->is_offline_mode()
136 - || $wpcom_is_wp_admin_interface
137 - || ! $is_user_connected
138 - ) {
139 - add_submenu_page(
140 - 'options-general.php',
141 - __( 'Sharing Settings', 'jetpack' ),
142 - __( 'Sharing', 'jetpack' ),
143 - 'manage_options',
144 - 'sharing',
145 - array( $this, 'wrapper_admin_page' )
146 - );
147 - }
134 + add_submenu_page(
135 + 'options-general.php',
136 + __( 'Sharing Settings', 'jetpack' ),
137 + __( 'Sharing', 'jetpack' ),
138 + 'manage_options',
139 + 'sharing',
140 + array( $this, 'wrapper_admin_page' )
141 + );
148 142 }
149 143
150 144 /**
151 145 * Save changes to sharing services via AJAX.
@@ -164,9 +158,9 @@
164 158 $sharer->set_blog_services(
165 159 explode( ',', sanitize_text_field( wp_unslash( $_POST['visible'] ) ) ),
166 160 explode( ',', sanitize_text_field( wp_unslash( $_POST['hidden'] ) ) )
167 161 );
168 - die();
162 + die( 0 );
169 163 }
170 164 }
171 165
172 166 /**
@@ -194,9 +188,9 @@
194 188 echo '<!--->';
195 189 $service->button_style = 'icon-text';
196 190 $this->output_preview( $service );
197 191
198 - die();
192 + die( 0 );
199 193 }
200 194 }
201 195
202 196 // Fail
@@ -248,9 +242,9 @@
248 242 $this->output_service( $service->get_id(), $service, true );
249 243 echo '<!--->';
250 244 $service->button_style = 'icon-text';
251 245 $this->output_preview( $service );
252 - die();
246 + die( 0 );
253 247 }
254 248 }
255 249
256 250 /**
@@ -369,12 +363,10 @@
369 363 do_action( 'pre_admin_screen_sharing' );
370 364 ?>
371 365
372 366 <?php
373 - $block_availability = Jetpack_Gutenberg::get_cached_availability();
374 - $is_block_available = (bool) isset( $block_availability['sharing-buttons'] ) && $block_availability['sharing-buttons']['available'];
375 - $is_block_theme = wp_is_block_theme();
376 - $show_block_message = $is_block_available && $is_block_theme;
367 + $is_simple_site = defined( 'IS_WPCOM' ) && IS_WPCOM;
368 + $show_block_message = $this->should_use_site_editor() && ! $is_simple_site;
377 369
378 370 // We either show old services config or the sharing block message.
379 371 if ( current_user_can( 'manage_options' ) ) :
380 372 $show_block_message ? $this->sharing_block_display() : $this->services_config_display();
@@ -382,9 +374,9 @@
382 374 ?>
383 375 </div>
384 376
385 377 <script type="text/javascript">
386 - var sharing_loading_icon = '<?php echo esc_js( admin_url( '/images/loading.gif' ) ); ?>';
378 + var sharing_loading_icon = <?php echo wp_json_encode( admin_url( '/images/loading.gif' ), JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ); ?>;
387 379 <?php
388 380 // phpcs:disable WordPress.Security.NonceVerification.Recommended -- we handle the nonce on the PHP side.
389 381 if (
390 382 isset( $_GET['create_new_service'] ) && isset( $_GET['name'] ) && isset( $_GET['url'] ) && isset( $_GET['icon'] )
@@ -392,11 +384,11 @@
392 384 ) :
393 385 ?>
394 386 jQuery(document).ready(function() {
395 387 // Prefill new service box and then open it
396 - jQuery( '#new_sharing_name' ).val( '<?php echo esc_js( sanitize_text_field( wp_unslash( $_GET['name'] ) ) ); ?>' );
397 - jQuery( '#new_sharing_url' ).val( '<?php echo esc_js( sanitize_text_field( wp_unslash( $_GET['url'] ) ) ); ?>' );
398 - jQuery( '#new_sharing_icon' ).val( '<?php echo esc_js( sanitize_text_field( wp_unslash( $_GET['icon'] ) ) ); ?>' );
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 ); ?> );
399 391 jQuery( '#add-a-new-service' ).click();
400 392 });
401 393 <?php endif; ?>
402 394 </script>
@@ -404,8 +396,20 @@
404 396 // phpcs:enable WordPress.Security.NonceVerification.Recommended
405 397 }
406 398
407 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 + /**
408 412 * Display services admin UI for settings.
409 413 *
410 414 * @return void
411 415 */
@@ -423,8 +427,22 @@
423 427 <div class="share_manage_options">
424 428 <h2><?php esc_html_e( 'Sharing Buttons', 'jetpack' ); ?></h2>
425 429 <p><?php esc_html_e( 'Add sharing buttons to your blog and allow your visitors to share posts with their friends.', 'jetpack' ); ?></p>
426 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 +
427 445 <div id="services-config">
428 446 <table id="available-services">
429 447 <tr>
430 448 <td class="description">
@@ -456,9 +474,9 @@
456 474 <tr>
457 475 <td class="description">
458 476 <h3>
459 477 <?php esc_html_e( 'Enabled Services', 'jetpack' ); ?>
460 - <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>
461 479 </h3>
462 480 <p><?php esc_html_e( 'Services dragged here will appear individually.', 'jetpack' ); ?></p>
463 481 </td>
464 482 <td class="services" id="share-drop-target">
@@ -679,9 +697,9 @@
679 697 <tr valign="top" width="100">
680 698 <th scope="row"></th>
681 699 <td>
682 700 <input type="submit" class="button-primary" value="<?php esc_attr_e( 'Create Share Button', 'jetpack' ); ?>" />
683 - <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>
684 702 </td>
685 703 </tr>
686 704
687 705 <?php
@@ -748,16 +766,9 @@
748 766 <h2><?php esc_html_e( 'Sharing Buttons', 'jetpack' ); ?></h2>
749 767 <div class="sharing-block-message__items-wrapper">
750 768 <div>
751 769 <p><?php esc_html_e( 'Add sharing buttons to your blog and allow your visitors to share posts with their friends.', 'jetpack' ); ?></p>
752 - <div class="sharing-block-message__buttons-wrapper">
753 - <a href="<?php echo esc_url( admin_url( 'site-editor.php?path=%2Fwp_template' ) ); ?>" class="button button-primary">
754 - <?php esc_html_e( 'Go to the site editor', 'jetpack' ); ?>
755 - </a>
756 - <a href="<?php echo esc_url( Redirect::get_url( 'jetpack-support-sharing-block' ) ); ?>" class="button" target="_blank" rel="noopener noreferrer">
757 - <?php esc_html_e( 'Learn how to add Sharing Buttons', 'jetpack' ); ?>
758 - </a>
759 - </div>
770 + <?php $this->site_editor_prompt_display(); ?>
760 771 </div>
761 772 <div>
762 773 <p><?php esc_html_e( 'Sharing Buttons example:', 'jetpack' ); ?></p>
763 774 <div class="sharedaddy sd-sharing-enabled">
@@ -790,8 +801,36 @@
790 801 <br class="clearing" />
791 802 </div>
792 803 <?php
793 804 }
805 +
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>
831 + <?php
832 + }
794 833 }
795 834
796 835 /**
797 836 * Callback to get the value for the jetpack_sharing_enabled field.
@@ -809,9 +848,9 @@
809 848 return false;
810 849 }
811 850
812 851 // if sharing IS disabled on this post, enabled=false, so negate the meta
813 - return (bool) ! get_post_meta( $post['id'], 'sharing_disabled', true );
852 + return ! get_post_meta( $post['id'], 'sharing_disabled', true );
814 853 }
815 854
816 855 /**
817 856 * Callback to set sharing_disabled post_meta when the