PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.5
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.5
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 | extensions/blocks/sharing-button/sharing-button.php +71 -39 13.2.4 → 16.3-a.5 View file →
@@ -12,9 +12,14 @@
12 12 use Automattic\Jetpack\Blocks;
13 13 use Automattic\Jetpack\Modules;
14 14 use Automattic\Jetpack\Status\Host;
15 15 use Jetpack_Gutenberg;
16 +use WP_Block_Template;
16 17
18 +if ( ! defined( 'ABSPATH' ) ) {
19 + exit( 0 );
20 +}
21 +
17 22 require_once __DIR__ . '/class-sharing-source-block.php';
18 23 require_once __DIR__ . '/components/social-icons.php';
19 24
20 25 const PARENT_BLOCK_NAME = 'jetpack/sharing-buttons';
@@ -31,17 +36,12 @@
31 36 array( 'render_callback' => __NAMESPACE__ . '\render_block' )
32 37 );
33 38
34 39 /*
35 - * Automatically add the sharing block to the end of single posts
36 - * only when running WordPress 6.5 or later.
37 - * @todo: remove when WordPress 6.5 is the minimum required version.
40 + * Automatically add the sharing block to the end of single posts.
38 41 */
39 - global $wp_version;
40 - if ( version_compare( $wp_version, '6.5-beta2', '>=' ) ) {
41 - add_filter( 'hooked_block_types', __NAMESPACE__ . '\add_block_to_single_posts_template', 10, 4 );
42 - add_filter( 'hooked_block_' . PARENT_BLOCK_NAME, __NAMESPACE__ . '\add_default_services_to_block', 10, 5 );
43 - }
42 + add_filter( 'hooked_block_types', __NAMESPACE__ . '\add_block_to_single_posts_template', 10, 4 );
43 + add_filter( 'hooked_block_' . PARENT_BLOCK_NAME, __NAMESPACE__ . '\add_default_services_to_block', 10, 5 );
44 44 }
45 45 add_action( 'init', __NAMESPACE__ . '\register_block' );
46 46
47 47 /**
@@ -53,8 +53,13 @@
53 53 *
54 54 * @return string
55 55 */
56 56 function render_block( $attr, $content, $block ) {
57 + $services = get_services();
58 + if ( ! isset( $attr['service'] ) || ! array_key_exists( $attr['service'], $services ) ) {
59 + return $content;
60 + }
61 +
57 62 $service_name = $attr['service'];
58 63 $title = $attr['label'] ?? $service_name;
59 64 $icon = get_social_logo( $service_name );
60 65 $style_type = $block->context['styleType'] ?? 'icon-text';
@@ -64,27 +69,45 @@
64 69 $service_name,
65 70 $post_id
66 71 );
67 72
68 - $services = get_services();
69 - $service = new $services[ $service_name ]( $service_name, array() );
70 - $link_props = $service->get_link(
73 + $service = new $services[ $service_name ]( $service_name, array() );
74 + $link_props = $service->get_link(
71 75 $post_id,
72 76 'share=' . esc_attr( $service_name ) . '&nb=1',
73 77 esc_attr( $data_shared )
74 78 );
75 - $link_url = $link_props['url'];
76 - $link_classes = sprintf(
79 + $link_url = $link_props['url'];
80 + $link_classes = sprintf(
77 81 'jetpack-sharing-button__button style-%1$s share-%2$s',
78 82 $style_type,
79 83 $service_name
80 84 );
81 - $link_aria_label = sprintf(
82 - /* translators: %s refers to a string representation of sharing service, e.g. Facebook */
85 +
86 + $accessible_name = sprintf(
87 + /* translators: %s refers to a string representation of sharing service, e.g. Facebook */
83 88 esc_html__( 'Share on %s', 'jetpack' ),
84 89 esc_html( $title )
85 90 );
86 91
92 + $accessible_name .= __( ' (Opens in new window)', 'jetpack' );
93 +
94 + $block_class_name = 'jetpack-sharing-button__list-item';
95 +
96 + if ( $service_name === 'share' ) {
97 + $block_class_name .= ' tooltip';
98 + /* translators: aria label for SMS sharing button */
99 + $accessible_name = esc_attr__( 'Share using Native tools', 'jetpack' );
100 + $link_props = $service->get_link( $post_id );
101 + }
102 +
103 + $link_url = $link_props['url'];
104 + $link_classes = sprintf(
105 + 'jetpack-sharing-button__button style-%1$s share-%2$s',
106 + $style_type,
107 + $service_name
108 + );
109 +
87 110 $styles = array();
88 111 if (
89 112 array_key_exists( 'iconColorValue', $block->context )
90 113 && ! empty( $block->context['iconColorValue'] )
@@ -103,20 +126,30 @@
103 126 }
104 127
105 128 Jetpack_Gutenberg::load_assets_as_required( __DIR__ );
106 129
107 - $component = '<li class="jetpack-sharing-button__list-item">';
130 + $component = '<li class="' . esc_attr( $block_class_name ) . '">';
108 131 $component .= sprintf(
109 - '<a href="%1$s" target="_blank" rel="nofollow noopener noreferrer" class="%2$s" style="%3$s" data-service="%4$s" data-shared="%5$s" aria-label="%6$s">',
132 + '<a href="%1$s" target="_blank" rel="nofollow noopener noreferrer" class="%2$s" style="%3$s" data-service="%4$s" data-shared="%5$s" aria-labelledby="%5$s">',
110 133 esc_url( $link_url ),
111 134 esc_attr( $link_classes ),
112 135 esc_attr( $link_styles ),
113 136 esc_attr( $service_name ),
137 + esc_attr( $data_shared )
138 + );
139 +
140 + // Add hidden span with accessible name
141 + $component .= sprintf(
142 + '<span id="%s" hidden>%s</span>',
114 143 esc_attr( $data_shared ),
115 - esc_attr( $link_aria_label )
144 + esc_html( $accessible_name )
116 145 );
146 +
117 147 $component .= $style_type !== 'text' ? $icon : '';
118 148 $component .= '<span class="jetpack-sharing-button__service-label" aria-hidden="true">' . esc_html( $title ) . '</span>';
149 + if ( $service_name === 'share' ) {
150 + $component .= '<span class="tooltiptext" aria-live="assertive">' . esc_html__( 'Copied to clipboard', 'jetpack' ) . '</span>';
151 + }
119 152 $component .= '</a>';
120 153 $component .= '</li>';
121 154
122 155 return $component;
@@ -136,14 +169,16 @@
136 169 'reddit' => Share_Reddit_Block::class,
137 170 'twitter' => Share_Twitter_Block::class,
138 171 'tumblr' => Share_Tumblr_Block::class,
139 172 'pinterest' => Share_Pinterest_Block::class,
140 - 'pocket' => Share_Pocket_Block::class,
141 173 'telegram' => Share_Telegram_Block::class,
174 + 'threads' => Share_Threads_Block::class,
142 175 'whatsapp' => Jetpack_Share_WhatsApp_Block::class,
143 176 'mastodon' => Share_Mastodon_Block::class,
144 177 'nextdoor' => Share_Nextdoor_Block::class,
178 + 'bluesky' => Share_Bluesky_Block::class,
145 179 'x' => Share_X_Block::class,
180 + 'share' => Share_Native_Block::class,
146 181 );
147 182
148 183 return $services;
149 184 }
@@ -165,16 +200,18 @@
165 200 if ( ! array_key_exists( $service_name, $services ) ) {
166 201 return;
167 202 }
168 203
169 - $service = new $services[ ( $service_name ) ]( $service_name, array() ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
170 - if ( $service ) {
171 - $service->process_request( $post, $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
172 - }
204 + $service = new $services[ ( $service_name ) ]( $service_name, array() );
205 + $service->process_request( $post, $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
173 206 }
174 207 }
175 -add_action( 'template_redirect', __NAMESPACE__ . '\sharing_process_requests', 9 );
176 208
209 +// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Only checking for the data being present.
210 +if ( isset( $_GET['share'] ) ) {
211 + add_action( 'template_redirect', __NAMESPACE__ . '\sharing_process_requests', 9 );
212 +}
213 +
177 214 /**
178 215 * Automatically add the Sharing Buttons block to the end of the Single Posts template.
179 216 *
180 217 * @since 13.2
@@ -186,8 +223,16 @@
186 223 *
187 224 * @return array
188 225 */
189 226 function add_block_to_single_posts_template( $hooked_block_types, $relative_position, $anchor_block_type, $context ) {
227 + // Add the block at the end of the post content.
228 + if (
229 + 'after' !== $relative_position
230 + || 'core/post-content' !== $anchor_block_type
231 + ) {
232 + return $hooked_block_types;
233 + }
234 +
190 235 // Only automate the addition of the block in block-based themes.
191 236 if ( ! wp_is_block_theme() ) {
192 237 return $hooked_block_types;
193 238 }
@@ -222,9 +267,9 @@
222 267 }
223 268
224 269 // Only hook into page and single post templates.
225 270 if (
226 - ! $context instanceof \WP_Block_Template
271 + ! $context instanceof WP_Block_Template
227 272 || ! property_exists( $context, 'slug' )
228 273 || empty( $context->slug )
229 274 || ! preg_match( '/^(page|single)/', $context->slug )
230 275 ) {
@@ -230,22 +275,9 @@
230 275 ) {
231 276 return $hooked_block_types;
232 277 }
233 278
234 - $content = $context->content ?? '';
235 - // Check if the block is already in the template. If so, abort.
236 - if ( false !== strpos( $content, 'wp:' . PARENT_BLOCK_NAME ) ) {
237 - return $hooked_block_types;
238 - }
239 -
240 - // Add the block at the end of the post content.
241 - if (
242 - 'after' === $relative_position
243 - && 'core/post-content' === $anchor_block_type
244 - ) {
245 - $hooked_block_types[] = PARENT_BLOCK_NAME;
246 - }
247 -
279 + $hooked_block_types[] = PARENT_BLOCK_NAME;
248 280 return $hooked_block_types;
249 281 }
250 282
251 283 /**