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 | extensions/blocks/sharing-button/sharing-button.php +36 -40 13.5.2 → 16.3-a.7 View file →
@@ -14,8 +14,12 @@
14 14 use Automattic\Jetpack\Status\Host;
15 15 use Jetpack_Gutenberg;
16 16 use WP_Block_Template;
17 17
18 +if ( ! defined( 'ABSPATH' ) ) {
19 + exit( 0 );
20 +}
21 +
18 22 require_once __DIR__ . '/class-sharing-source-block.php';
19 23 require_once __DIR__ . '/components/social-icons.php';
20 24
21 25 const PARENT_BLOCK_NAME = 'jetpack/sharing-buttons';
@@ -32,17 +36,12 @@
32 36 array( 'render_callback' => __NAMESPACE__ . '\render_block' )
33 37 );
34 38
35 39 /*
36 - * Automatically add the sharing block to the end of single posts
37 - * only when running WordPress 6.5 or later.
38 - * @todo: remove when WordPress 6.5 is the minimum required version.
40 + * Automatically add the sharing block to the end of single posts.
39 41 */
40 - global $wp_version;
41 - if ( version_compare( $wp_version, '6.5-beta2', '>=' ) ) {
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 - }
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 );
45 44 }
46 45 add_action( 'init', __NAMESPACE__ . '\register_block' );
47 46
48 47 /**
@@ -54,8 +53,13 @@
54 53 *
55 54 * @return string
56 55 */
57 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 +
58 62 $service_name = $attr['service'];
59 63 $title = $attr['label'] ?? $service_name;
60 64 $icon = get_social_logo( $service_name );
61 65 $style_type = $block->context['styleType'] ?? 'icon-text';
@@ -65,37 +69,28 @@
65 69 $service_name,
66 70 $post_id
67 71 );
68 72
69 - $services = get_services();
70 - if ( ! array_key_exists( $service_name, $services ) ) {
71 - return $content;
72 - }
73 -
74 - $service = new $services[ $service_name ]( $service_name, array() );
75 - $link_props = $service->get_link(
73 + $service = new $services[ $service_name ]( $service_name, array() );
74 + $link_props = $service->get_link(
76 75 $post_id,
77 76 'share=' . esc_attr( $service_name ) . '&nb=1',
78 77 esc_attr( $data_shared )
79 78 );
80 - $link_url = $link_props['url'];
81 - $link_classes = sprintf(
79 + $link_url = $link_props['url'];
80 + $link_classes = sprintf(
82 81 'jetpack-sharing-button__button style-%1$s share-%2$s',
83 82 $style_type,
84 83 $service_name
85 84 );
86 - $link_aria_label = sprintf(
87 - /* 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 */
88 88 esc_html__( 'Share on %s', 'jetpack' ),
89 89 esc_html( $title )
90 90 );
91 91
92 - $link_props = $service->get_link(
93 - $post_id,
94 - 'share=' . esc_attr( $service_name ) . '&nb=1',
95 - false,
96 - esc_attr( $data_shared )
97 - );
92 + $accessible_name .= __( ' (Opens in new window)', 'jetpack' );
98 93
99 94 $block_class_name = 'jetpack-sharing-button__list-item';
100 95
101 96 if ( $service_name === 'share' ) {
@@ -100,9 +95,9 @@
100 95
101 96 if ( $service_name === 'share' ) {
102 97 $block_class_name .= ' tooltip';
103 98 /* translators: aria label for SMS sharing button */
104 - $link_aria_label = esc_attr__( 'Share using Native tools', 'jetpack' );
99 + $accessible_name = esc_attr__( 'Share using Native tools', 'jetpack' );
105 100 $link_props = $service->get_link( $post_id );
106 101 }
107 102
108 103 $link_url = $link_props['url'];
@@ -133,15 +128,21 @@
133 128 Jetpack_Gutenberg::load_assets_as_required( __DIR__ );
134 129
135 130 $component = '<li class="' . esc_attr( $block_class_name ) . '">';
136 131 $component .= sprintf(
137 - '<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">',
138 133 esc_url( $link_url ),
139 134 esc_attr( $link_classes ),
140 135 esc_attr( $link_styles ),
141 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>',
142 143 esc_attr( $data_shared ),
143 - esc_attr( $link_aria_label )
144 + esc_html( $accessible_name )
144 145 );
145 146
146 147 $component .= $style_type !== 'text' ? $icon : '';
147 148 $component .= '<span class="jetpack-sharing-button__service-label" aria-hidden="true">' . esc_html( $title ) . '</span>';
@@ -168,9 +169,8 @@
168 169 'reddit' => Share_Reddit_Block::class,
169 170 'twitter' => Share_Twitter_Block::class,
170 171 'tumblr' => Share_Tumblr_Block::class,
171 172 'pinterest' => Share_Pinterest_Block::class,
172 - 'pocket' => Share_Pocket_Block::class,
173 173 'telegram' => Share_Telegram_Block::class,
174 174 'threads' => Share_Threads_Block::class,
175 175 'whatsapp' => Jetpack_Share_WhatsApp_Block::class,
176 176 'mastodon' => Share_Mastodon_Block::class,
@@ -200,16 +200,18 @@
200 200 if ( ! array_key_exists( $service_name, $services ) ) {
201 201 return;
202 202 }
203 203
204 - $service = new $services[ ( $service_name ) ]( $service_name, array() ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
205 - if ( $service ) {
206 - $service->process_request( $post, $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
207 - }
204 + $service = new $services[ ( $service_name ) ]( $service_name, array() );
205 + $service->process_request( $post, $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
208 206 }
209 207 }
210 -add_action( 'template_redirect', __NAMESPACE__ . '\sharing_process_requests', 9 );
211 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 +
212 214 /**
213 215 * Automatically add the Sharing Buttons block to the end of the Single Posts template.
214 216 *
215 217 * @since 13.2
@@ -270,14 +272,8 @@
270 272 || ! property_exists( $context, 'slug' )
271 273 || empty( $context->slug )
272 274 || ! preg_match( '/^(page|single)/', $context->slug )
273 275 ) {
274 - return $hooked_block_types;
275 - }
276 -
277 - $content = $context->content ?? '';
278 - // Check if the block is already in the template. If so, abort.
279 - if ( false !== strpos( $content, 'wp:' . PARENT_BLOCK_NAME ) ) {
280 276 return $hooked_block_types;
281 277 }
282 278
283 279 $hooked_block_types[] = PARENT_BLOCK_NAME;