PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.7
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.7
16.3-a.5 16.3-a.7 16.3-a.3 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 All 506 releases
← All changes | modules/sharedaddy/sharing-service.php +41 -30 12.5.2 → 16.3-a.7 View file →
@@ -12,12 +12,14 @@
12 12
13 13 // phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files.
14 14
15 15 use Automattic\Jetpack\Assets;
16 -use Automattic\Jetpack\Redirect;
17 -use Automattic\Jetpack\Status;
18 16 use Automattic\Jetpack\Sync\Settings;
19 17
18 +if ( ! defined( 'ABSPATH' ) ) {
19 + exit( 0 );
20 +}
21 +
20 22 require_once __DIR__ . '/sharing-sources.php';
21 23
22 24 define( 'WP_SHARING_PLUGIN_VERSION', JETPACK__VERSION );
23 25
@@ -71,9 +73,9 @@
71 73 if ( isset( $all[ $id ] ) ) {
72 74 $config = array();
73 75
74 76 // Pre-load custom modules otherwise they won't know who they are
75 - if ( substr( $id, 0, 7 ) === 'custom-' && is_array( $options[ $id ] ) ) {
77 + if ( str_starts_with( $id, 'custom-' ) && is_array( $options[ $id ] ) ) {
76 78 $config = $options[ $id ];
77 79 }
78 80
79 81 $services[ $id ] = new $all[ $id ]( $id, $config );
@@ -102,15 +104,15 @@
102 104 'reddit' => 'Share_Reddit',
103 105 'twitter' => 'Share_Twitter',
104 106 'tumblr' => 'Share_Tumblr',
105 107 'pinterest' => 'Share_Pinterest',
106 - 'pocket' => 'Share_Pocket',
107 108 'telegram' => 'Share_Telegram',
109 + 'threads' => 'Share_Threads',
108 110 'jetpack-whatsapp' => 'Jetpack_Share_WhatsApp',
109 111 'mastodon' => 'Share_Mastodon',
110 112 'nextdoor' => 'Share_Nextdoor',
111 - // deprecated.
112 - 'skype' => 'Share_Skype',
113 + 'x' => 'Share_X',
114 + 'bluesky' => 'Share_Bluesky',
113 115 );
114 116
115 117 if ( is_multisite() && is_plugin_active( 'press-this/press-this-plugin.php' ) ) {
116 118 $services['press-this'] = 'Share_PressThis';
@@ -118,10 +120,12 @@
118 120
119 121 if ( $include_custom ) {
120 122 // Add any custom services in
121 123 $options = $this->get_global_options();
122 - foreach ( (array) $options['custom'] as $custom_id ) {
123 - $services[ $custom_id ] = 'Share_Custom';
124 + if ( isset( $options['custom'] ) ) {
125 + foreach ( $options['custom'] as $custom_id ) {
126 + $services[ $custom_id ] = 'Share_Custom';
127 + }
124 128 }
125 129 }
126 130
127 131 /**
@@ -292,10 +296,10 @@
292 296 // Default services
293 297 if ( ! is_array( $enabled ) ) {
294 298 $enabled = array(
295 299 'visible' => array(
296 - 'twitter',
297 300 'facebook',
301 + 'x',
298 302 ),
299 303 'hidden' => array(),
300 304 );
301 305
@@ -311,15 +315,15 @@
311 315 $enabled = apply_filters( 'sharing_default_services', $enabled );
312 316 }
313 317
314 318 // Cleanup after any filters that may have produced duplicate services
315 - if ( is_array( $enabled['visible'] ) ) {
319 + if ( isset( $enabled['visible'] ) && is_array( $enabled['visible'] ) ) {
316 320 $enabled['visible'] = array_unique( $enabled['visible'] );
317 321 } else {
318 322 $enabled['visible'] = array();
319 323 }
320 324
321 - if ( is_array( $enabled['hidden'] ) ) {
325 + if ( isset( $enabled['hidden'] ) && is_array( $enabled['hidden'] ) ) {
322 326 $enabled['hidden'] = array_unique( $enabled['hidden'] );
323 327 } else {
324 328 $enabled['hidden'] = array();
325 329 }
@@ -401,9 +405,9 @@
401 405 'button_style' => 'icon-text',
402 406 'sharing_label' => $this->default_sharing_label,
403 407 'open_links' => 'same',
404 408 'show' => ! isset( $options['global'] ) ? array( 'post', 'page' ) : array(),
405 - 'custom' => isset( $options['global']['custom'] ) ? $options['global']['custom'] : array(),
409 + 'custom' => $options['global']['custom'] ?? array(),
406 410 );
407 411
408 412 /**
409 413 * Filters global sharing settings.
@@ -497,9 +501,9 @@
497 501 break;
498 502 }
499 503 }
500 504
501 - if ( false === $this->global['sharing_label'] ) {
505 + if ( ! isset( $this->global['sharing_label'] ) || false === $this->global['sharing_label'] || $this->global['sharing_label'] === 'Share this:' ) {
502 506 $this->global['sharing_label'] = $this->default_sharing_label;
503 507 }
504 508
505 509 return $this->global;
@@ -507,14 +511,14 @@
507 511
508 512 /**
509 513 * Save a sharing service for use.
510 514 *
511 - * @param int $id Sharing unique ID.
512 - * @param Sharing_Source $service Sharing service.
515 + * @param string $id Sharing unique ID.
516 + * @param Sharing_Advanced_Source $service Sharing service.
513 517 *
514 518 * @return void
515 519 */
516 - public function set_service( $id, Sharing_Source $service ) {
520 + public function set_service( $id, Sharing_Advanced_Source $service ) {
517 521 // Update the options for this service
518 522 $options = get_option( 'sharing-options' );
519 523
520 524 // No options yet
@@ -685,9 +689,11 @@
685 689 $this->id = esc_html( $id );
686 690 $this->service = $services->get_service( $id );
687 691 $this->total = (int) $total;
688 692
689 - $this->name = $this->service->get_name();
693 + if ( $this->service instanceof Sharing_Source ) {
694 + $this->name = $this->service->get_name();
695 + }
690 696 }
691 697
692 698 /**
693 699 * Compare total shares between 2 posts.
@@ -694,15 +700,15 @@
694 700 *
695 701 * @param object $a Sharing_Service_Total object.
696 702 * @param object $b Sharing_Service_Total object.
697 703 *
698 - * @return bool
704 + * @return int -1, 0, or 1 if $a is <, =, or > $b
699 705 */
700 706 public static function cmp( $a, $b ) {
701 707 if ( $a->total === $b->total ) {
702 - return $a->name < $b->name;
708 + return $b->name <=> $a->name;
703 709 }
704 - return $a->total < $b->total;
710 + return $b->total <=> $a->total;
705 711 }
706 712 }
707 713
708 714 /**
@@ -755,15 +761,15 @@
755 761 *
756 762 * @param object $a Sharing_Post_Total object.
757 763 * @param object $b Sharing_Post_Total object.
758 764 *
759 - * @return bool
765 + * @return int -1, 0, or 1 if $a is <, =, or > $b
760 766 */
761 767 public static function cmp( $a, $b ) {
762 768 if ( $a->total === $b->total ) {
763 - return $a->id < $b->id;
769 + return $b->id <=> $a->id;
764 770 }
765 - return $a->total < $b->total;
771 + return $b->total <=> $a->total;
766 772 }
767 773 }
768 774
769 775 /**
@@ -866,9 +872,9 @@
866 872 if ( $sharing_post_urls ) :
867 873 ?>
868 874
869 875 <script type="text/javascript">
870 - window.WPCOM_sharing_counts = <?php echo wp_json_encode( array_flip( $sharing_post_urls ) ); ?>;
876 + window.WPCOM_sharing_counts = <?php echo wp_json_encode( array_flip( $sharing_post_urls ), JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ); ?>;
871 877 </script>
872 878 <?php
873 879 endif;
874 880 endif;
@@ -926,17 +932,21 @@
926 932 $service->process_request( $post, $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
927 933 }
928 934 }
929 935 }
930 -add_action( 'template_redirect', 'sharing_process_requests', 9 );
931 936
937 +// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Only checking for the data being present.
938 +if ( isset( $_GET['share'] ) ) {
939 + add_action( 'template_redirect', 'sharing_process_requests', 9 );
940 +}
941 +
932 942 /**
933 - * Gets the url to customise the sharing buttons in Calypso.
943 + * Gets the url to customise the sharing buttons in WP-Admin.
934 944 *
935 - * @return string the customisation URL or null if it couldn't be determinde.
945 + * @return string the customisation URL.
936 946 */
937 947 function get_sharing_buttons_customisation_url() {
938 - return Redirect::get_url( 'calypso-marketing-sharing-buttons', array( 'site' => ( new Status() )->get_site_suffix() ) );
948 + return admin_url( 'options-general.php?page=sharing' );
939 949 }
940 950
941 951 /**
942 952 * Append sharing links to text.
@@ -952,9 +962,10 @@
952 962 if ( Settings::is_syncing() ) {
953 963 return $text;
954 964 }
955 965
956 - if ( empty( $post ) ) {
966 + // We require the post to not be empty and be an actual WordPress post object. If it's not - we just return.
967 + if ( empty( $post ) || ! $post instanceof \WP_Post ) {
957 968 return $text;
958 969 }
959 970
960 971 if ( ( is_preview() || is_admin() ) && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
@@ -1098,9 +1109,9 @@
1098 1109 if ( is_countable( $enabled['all'] ) && ( count( $enabled['all'] ) > 0 ) ) {
1099 1110 $dir = get_option( 'text_direction' );
1100 1111
1101 1112 // Wrapper.
1102 - $sharing_content .= '<div class="sharedaddy sd-sharing-enabled"><div class="robots-nocontent sd-block sd-social sd-social-' . $global['button_style'] . ' sd-sharing">';
1113 + $sharing_content .= '<div class="sharedaddy sd-sharing-enabled"><div class="robots-nocontent sd-block sd-social sd-social-' . ( $global['button_style'] ?? 'icon-text' ) . ' sd-sharing">';
1103 1114 if ( '' !== $global['sharing_label'] ) {
1104 1115 $sharing_content .= sprintf(
1105 1116 /**
1106 1117 * Filter the sharing buttons' headline structure.