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 +33 -26 13.8.3 → 16.3-a.5 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';
@@ -49,8 +53,13 @@
49 53 *
50 54 * @return string
51 55 */
52 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 +
53 62 $service_name = $attr['service'];
54 63 $title = $attr['label'] ?? $service_name;
55 64 $icon = get_social_logo( $service_name );
56 65 $style_type = $block->context['styleType'] ?? 'icon-text';
@@ -60,37 +69,28 @@
60 69 $service_name,
61 70 $post_id
62 71 );
63 72
64 - $services = get_services();
65 - if ( ! array_key_exists( $service_name, $services ) ) {
66 - return $content;
67 - }
68 -
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
87 - $link_props = $service->get_link(
88 - $post_id,
89 - 'share=' . esc_attr( $service_name ) . '&nb=1',
90 - false,
91 - esc_attr( $data_shared )
92 - );
92 + $accessible_name .= __( ' (Opens in new window)', 'jetpack' );
93 93
94 94 $block_class_name = 'jetpack-sharing-button__list-item';
95 95
96 96 if ( $service_name === 'share' ) {
@@ -95,9 +95,9 @@
95 95
96 96 if ( $service_name === 'share' ) {
97 97 $block_class_name .= ' tooltip';
98 98 /* translators: aria label for SMS sharing button */
99 - $link_aria_label = esc_attr__( 'Share using Native tools', 'jetpack' );
99 + $accessible_name = esc_attr__( 'Share using Native tools', 'jetpack' );
100 100 $link_props = $service->get_link( $post_id );
101 101 }
102 102
103 103 $link_url = $link_props['url'];
@@ -128,15 +128,21 @@
128 128 Jetpack_Gutenberg::load_assets_as_required( __DIR__ );
129 129
130 130 $component = '<li class="' . esc_attr( $block_class_name ) . '">';
131 131 $component .= sprintf(
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-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">',
133 133 esc_url( $link_url ),
134 134 esc_attr( $link_classes ),
135 135 esc_attr( $link_styles ),
136 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>',
137 143 esc_attr( $data_shared ),
138 - esc_attr( $link_aria_label )
144 + esc_html( $accessible_name )
139 145 );
140 146
141 147 $component .= $style_type !== 'text' ? $icon : '';
142 148 $component .= '<span class="jetpack-sharing-button__service-label" aria-hidden="true">' . esc_html( $title ) . '</span>';
@@ -163,9 +169,8 @@
163 169 'reddit' => Share_Reddit_Block::class,
164 170 'twitter' => Share_Twitter_Block::class,
165 171 'tumblr' => Share_Tumblr_Block::class,
166 172 'pinterest' => Share_Pinterest_Block::class,
167 - 'pocket' => Share_Pocket_Block::class,
168 173 'telegram' => Share_Telegram_Block::class,
169 174 'threads' => Share_Threads_Block::class,
170 175 'whatsapp' => Jetpack_Share_WhatsApp_Block::class,
171 176 'mastodon' => Share_Mastodon_Block::class,
@@ -195,15 +200,17 @@
195 200 if ( ! array_key_exists( $service_name, $services ) ) {
196 201 return;
197 202 }
198 203
199 - $service = new $services[ ( $service_name ) ]( $service_name, array() ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
200 - if ( $service ) {
201 - $service->process_request( $post, $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
202 - }
204 + $service = new $services[ ( $service_name ) ]( $service_name, array() );
205 + $service->process_request( $post, $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
203 206 }
204 207 }
205 -add_action( 'template_redirect', __NAMESPACE__ . '\sharing_process_requests', 9 );
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 +}
206 213
207 214 /**
208 215 * Automatically add the Sharing Buttons block to the end of the Single Posts template.
209 216 *