PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.1
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.1
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 13.9.2 14.0.1 All 504 releases
← All changes | modules/sharedaddy/sharing-service.php +42 -29 12.2.316.3-a.1 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,13 +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 - 'skype' => 'Share_Skype',
110 111 'mastodon' => 'Share_Mastodon',
112 + 'nextdoor' => 'Share_Nextdoor',
113 + 'x' => 'Share_X',
114 + 'bluesky' => 'Share_Bluesky',
111 115 );
112 116
113 117 if ( is_multisite() && is_plugin_active( 'press-this/press-this-plugin.php' ) ) {
114 118 $services['press-this'] = 'Share_PressThis';
@@ -116,10 +120,12 @@
116 120
117 121 if ( $include_custom ) {
118 122 // Add any custom services in
119 123 $options = $this->get_global_options();
120 - foreach ( (array) $options['custom'] as $custom_id ) {
121 - $services[ $custom_id ] = 'Share_Custom';
124 + if ( isset( $options['custom'] ) ) {
125 + foreach ( $options['custom'] as $custom_id ) {
126 + $services[ $custom_id ] = 'Share_Custom';
127 + }
122 128 }
123 129 }
124 130
125 131 /**
@@ -290,10 +296,10 @@
290 296 // Default services
291 297 if ( ! is_array( $enabled ) ) {
292 298 $enabled = array(
293 299 'visible' => array(
294 - 'twitter',
295 300 'facebook',
301 + 'x',
296 302 ),
297 303 'hidden' => array(),
298 304 );
299 305
@@ -309,15 +315,15 @@
309 315 $enabled = apply_filters( 'sharing_default_services', $enabled );
310 316 }
311 317
312 318 // Cleanup after any filters that may have produced duplicate services
313 - if ( is_array( $enabled['visible'] ) ) {
319 + if ( isset( $enabled['visible'] ) && is_array( $enabled['visible'] ) ) {
314 320 $enabled['visible'] = array_unique( $enabled['visible'] );
315 321 } else {
316 322 $enabled['visible'] = array();
317 323 }
318 324
319 - if ( is_array( $enabled['hidden'] ) ) {
325 + if ( isset( $enabled['hidden'] ) && is_array( $enabled['hidden'] ) ) {
320 326 $enabled['hidden'] = array_unique( $enabled['hidden'] );
321 327 } else {
322 328 $enabled['hidden'] = array();
323 329 }
@@ -399,9 +405,9 @@
399 405 'button_style' => 'icon-text',
400 406 'sharing_label' => $this->default_sharing_label,
401 407 'open_links' => 'same',
402 408 'show' => ! isset( $options['global'] ) ? array( 'post', 'page' ) : array(),
403 - 'custom' => isset( $options['global']['custom'] ) ? $options['global']['custom'] : array(),
409 + 'custom' => $options['global']['custom'] ?? array(),
404 410 );
405 411
406 412 /**
407 413 * Filters global sharing settings.
@@ -495,9 +501,9 @@
495 501 break;
496 502 }
497 503 }
498 504
499 - if ( false === $this->global['sharing_label'] ) {
505 + if ( ! isset( $this->global['sharing_label'] ) || false === $this->global['sharing_label'] || $this->global['sharing_label'] === 'Share this:' ) {
500 506 $this->global['sharing_label'] = $this->default_sharing_label;
501 507 }
502 508
503 509 return $this->global;
@@ -505,14 +511,14 @@
505 511
506 512 /**
507 513 * Save a sharing service for use.
508 514 *
509 - * @param int $id Sharing unique ID.
510 - * @param Sharing_Source $service Sharing service.
515 + * @param int $id Sharing unique ID.
516 + * @param Sharing_Advanced_Source $service Sharing service.
511 517 *
512 518 * @return void
513 519 */
514 - public function set_service( $id, Sharing_Source $service ) {
520 + public function set_service( $id, Sharing_Advanced_Source $service ) {
515 521 // Update the options for this service
516 522 $options = get_option( 'sharing-options' );
517 523
518 524 // No options yet
@@ -683,9 +689,11 @@
683 689 $this->id = esc_html( $id );
684 690 $this->service = $services->get_service( $id );
685 691 $this->total = (int) $total;
686 692
687 - $this->name = $this->service->get_name();
693 + if ( $this->service instanceof Sharing_Source ) {
694 + $this->name = $this->service->get_name();
695 + }
688 696 }
689 697
690 698 /**
691 699 * Compare total shares between 2 posts.
@@ -692,15 +700,15 @@
692 700 *
693 701 * @param object $a Sharing_Service_Total object.
694 702 * @param object $b Sharing_Service_Total object.
695 703 *
696 - * @return bool
704 + * @return int -1, 0, or 1 if $a is <, =, or > $b
697 705 */
698 706 public static function cmp( $a, $b ) {
699 707 if ( $a->total === $b->total ) {
700 - return $a->name < $b->name;
708 + return $b->name <=> $a->name;
701 709 }
702 - return $a->total < $b->total;
710 + return $b->total <=> $a->total;
703 711 }
704 712 }
705 713
706 714 /**
@@ -753,15 +761,15 @@
753 761 *
754 762 * @param object $a Sharing_Post_Total object.
755 763 * @param object $b Sharing_Post_Total object.
756 764 *
757 - * @return bool
765 + * @return int -1, 0, or 1 if $a is <, =, or > $b
758 766 */
759 767 public static function cmp( $a, $b ) {
760 768 if ( $a->total === $b->total ) {
761 - return $a->id < $b->id;
769 + return $b->id <=> $a->id;
762 770 }
763 - return $a->total < $b->total;
771 + return $b->total <=> $a->total;
764 772 }
765 773 }
766 774
767 775 /**
@@ -864,9 +872,9 @@
864 872 if ( $sharing_post_urls ) :
865 873 ?>
866 874
867 875 <script type="text/javascript">
868 - 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 ); ?>;
869 877 </script>
870 878 <?php
871 879 endif;
872 880 endif;
@@ -924,17 +932,21 @@
924 932 $service->process_request( $post, $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
925 933 }
926 934 }
927 935 }
928 -add_action( 'template_redirect', 'sharing_process_requests', 9 );
929 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 +
930 942 /**
931 - * Gets the url to customise the sharing buttons in Calypso.
943 + * Gets the url to customise the sharing buttons in WP-Admin.
932 944 *
933 - * @return string the customisation URL or null if it couldn't be determinde.
945 + * @return string the customisation URL.
934 946 */
935 947 function get_sharing_buttons_customisation_url() {
936 - return Redirect::get_url( 'calypso-marketing-sharing-buttons', array( 'site' => ( new Status() )->get_site_suffix() ) );
948 + return admin_url( 'options-general.php?page=sharing' );
937 949 }
938 950
939 951 /**
940 952 * Append sharing links to text.
@@ -950,9 +962,10 @@
950 962 if ( Settings::is_syncing() ) {
951 963 return $text;
952 964 }
953 965
954 - 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 ) {
955 968 return $text;
956 969 }
957 970
958 971 if ( ( is_preview() || is_admin() ) && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
@@ -1096,9 +1109,9 @@
1096 1109 if ( is_countable( $enabled['all'] ) && ( count( $enabled['all'] ) > 0 ) ) {
1097 1110 $dir = get_option( 'text_direction' );
1098 1111
1099 1112 // Wrapper.
1100 - $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">';
1101 1114 if ( '' !== $global['sharing_label'] ) {
1102 1115 $sharing_content .= sprintf(
1103 1116 /**
1104 1117 * Filter the sharing buttons' headline structure.