PluginProbe
Gutenberg / 24.1.0
Gutenberg v24.1.0
24.1.0 24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 All 404 releases
← All changes | build/scripts/block-library/social-link.php +25 -23 23.5.2 → 24.1.0 View file →
@@ -9,24 +9,26 @@
9 9 * Renders the `core/social-link` block on server.
10 10 *
11 11 * @since 5.4.0
12 12 *
13 - * @param Array $attributes The block attributes.
14 - * @param String $content InnerBlocks content of the Block.
13 + * @param array $attributes The block attributes.
14 + * @param string $content InnerBlocks content of the Block.
15 15 * @param WP_Block $block Block object.
16 - *
17 16 * @return string Rendered HTML of the referenced block.
18 17 */
19 18 function gutenberg_render_block_core_social_link( $attributes, $content, $block ) {
20 19 $open_in_new_tab = $block->context['openInNewTab'] ?? false;
21 20
22 - $text = ! empty( $attributes['label'] ) ? trim( $attributes['label'] ) : '';
21 + $label_attr = $attributes['label'] ?? null;
22 + $text = is_string( $label_attr ) && '' !== $label_attr ? trim( $label_attr ) : '';
23 23
24 - $service = $attributes['service'] ?? 'Icon';
25 - $url = $attributes['url'] ?? false;
26 - $text = $text ? $text : gutenberg_block_core_social_link_get_name( $service );
27 - $rel = $attributes['rel'] ?? '';
28 - $show_labels = array_key_exists( 'showLabels', $block->context ) ? $block->context['showLabels'] : false;
24 + $service_attr = $attributes['service'] ?? null;
25 + $service = is_string( $service_attr ) ? $service_attr : 'Icon';
26 + $url = $attributes['url'] ?? false;
27 + $text = $text ? $text : gutenberg_block_core_social_link_get_name( $service );
28 + $rel_attr = $attributes['rel'] ?? null;
29 + $rel = is_string( $rel_attr ) ? $rel_attr : '';
30 + $show_labels = array_key_exists( 'showLabels', $block->context ) ? $block->context['showLabels'] : false;
29 31
30 32 // Don't render a link if there is no URL set.
31 33 if ( ! $url ) {
32 34 return '';
@@ -31,9 +33,13 @@
31 33 if ( ! $url ) {
32 34 return '';
33 35 }
34 36
35 - /**
37 + if ( ! is_string( $url ) ) {
38 + return '';
39 + }
40 +
41 + /*
36 42 * Prepend emails with `mailto:` if not set.
37 43 * The `is_email` returns false for emails with schema.
38 44 */
39 45 if ( is_email( $url ) ) {
@@ -39,9 +45,9 @@
39 45 if ( is_email( $url ) ) {
40 46 $url = 'mailto:' . antispambot( $url );
41 47 }
42 48
43 - /**
49 + /*
44 50 * Prepend URL with https:// if it doesn't appear to contain a scheme
45 51 * and it's not a relative link or a fragment.
46 52 */
47 53 if ( ! parse_url( $url, PHP_URL_SCHEME ) && ! str_starts_with( $url, '//' ) && ! str_starts_with( $url, '#' ) ) {
@@ -87,9 +93,8 @@
87 93 );
88 94 }
89 95 add_action( 'init', 'gutenberg_register_block_core_social_link', 20 );
90 96
91 -
92 97 /**
93 98 * Returns the SVG for social link.
94 99 *
95 100 * @since 5.4.0
@@ -94,14 +99,13 @@
94 99 *
95 100 * @since 5.4.0
96 101 *
97 102 * @param string $service The service icon.
98 - *
99 103 * @return string SVG Element for service icon.
100 104 */
101 105 function gutenberg_block_core_social_link_get_icon( $service ) {
102 106 $services = gutenberg_block_core_social_link_services();
103 - if ( isset( $services[ $service ] ) && isset( $services[ $service ]['icon'] ) ) {
107 + if ( is_string( $service ) && isset( $services[ $service ] ) && isset( $services[ $service ]['icon'] ) ) {
104 108 return $services[ $service ]['icon'];
105 109 }
106 110
107 111 return $services['share']['icon'];
@@ -112,14 +116,13 @@
112 116 *
113 117 * @since 5.4.0
114 118 *
115 119 * @param string $service The service icon.
116 - *
117 120 * @return string Brand label.
118 121 */
119 122 function gutenberg_block_core_social_link_get_name( $service ) {
120 123 $services = gutenberg_block_core_social_link_services();
121 - if ( isset( $services[ $service ] ) && isset( $services[ $service ]['name'] ) ) {
124 + if ( is_string( $service ) && isset( $services[ $service ] ) && isset( $services[ $service ]['name'] ) ) {
122 125 return $services[ $service ]['name'];
123 126 }
124 127
125 128 return $services['share']['name'];
@@ -130,13 +133,15 @@
130 133 *
131 134 * @since 5.4.0
132 135 *
133 136 * @param string $service The service slug to extract data from.
134 - * @param string $field The field ('name', 'icon', etc) to extract for a service.
135 - *
137 + * @param string $field The field ('name', 'icon', etc) to extract for a service.
136 138 * @return array|string
137 139 */
138 140 function gutenberg_block_core_social_link_services( $service = '', $field = '' ) {
141 + if ( ! is_string( $service ) || ! is_string( $field ) ) {
142 + return array();
143 + }
139 144 $services_data = array(
140 145 'fivehundredpx' => array(
141 146 'name' => _x( '500px', 'social link block variation name' ),
142 147 'icon' => '<svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M6.94026,15.1412c.00437.01213.108.29862.168.44064a6.55008,6.55008,0,1,0,6.03191-9.09557,6.68654,6.68654,0,0,0-2.58357.51467A8.53914,8.53914,0,0,0,8.21268,8.61344L8.209,8.61725V3.22948l9.0504-.00008c.32934-.0036.32934-.46353.32934-.61466s0-.61091-.33035-.61467L7.47248,2a.43.43,0,0,0-.43131.42692v7.58355c0,.24466.30476.42131.58793.4819.553.11812.68074-.05864.81617-.2457l.018-.02481A10.52673,10.52673,0,0,1,9.32258,9.258a5.35268,5.35268,0,1,1,7.58985,7.54976,5.417,5.417,0,0,1-3.80867,1.56365,5.17483,5.17483,0,0,1-2.69822-.74478l.00342-4.61111a2.79372,2.79372,0,0,1,.71372-1.78792,2.61611,2.61611,0,0,1,1.98282-.89477,2.75683,2.75683,0,0,1,1.95525.79477,2.66867,2.66867,0,0,1,.79656,1.909,2.724,2.724,0,0,1-2.75849,2.748,4.94651,4.94651,0,0,1-.86254-.13719c-.31234-.093-.44519.34058-.48892.48349-.16811.54966.08453.65862.13687.67489a3.75751,3.75751,0,0,0,1.25234.18375,3.94634,3.94634,0,1,0-2.82444-6.742,3.67478,3.67478,0,0,0-1.13028,2.584l-.00041.02323c-.0035.11667-.00579,2.881-.00644,3.78811l-.00407-.00451a6.18521,6.18521,0,0,1-1.0851-1.86092c-.10544-.27856-.34358-.22925-.66857-.12917-.14192.04372-.57386.17677-.47833.489Zm4.65165-1.08338a.51346.51346,0,0,0,.19513.31818l.02276.022a.52945.52945,0,0,0,.3517.18416.24242.24242,0,0,0,.16577-.0611c.05473-.05082.67382-.67812.73287-.738l.69041.68819a.28978.28978,0,0,0,.21437.11032.53239.53239,0,0,0,.35708-.19486c.29792-.30419.14885-.46821.07676-.54751l-.69954-.69975.72952-.73469c.16-.17311.01874-.35708-.12218-.498-.20461-.20461-.402-.25742-.52855-.14083l-.7254.72665-.73354-.73375a.20128.20128,0,0,0-.14179-.05695.54135.54135,0,0,0-.34379.19648c-.22561.22555-.274.38149-.15656.5059l.73374.7315-.72942.73072A.26589.26589,0,0,0,11.59191,14.05782Zm1.59866-9.915A8.86081,8.86081,0,0,0,9.854,4.776a.26169.26169,0,0,0-.16938.22759.92978.92978,0,0,0,.08619.42094c.05682.14524.20779.531.50006.41955a8.40969,8.40969,0,0,1,2.91968-.55484,7.87875,7.87875,0,0,1,3.086.62286,8.61817,8.61817,0,0,1,2.30562,1.49315.2781.2781,0,0,0,.18318.07586c.15529,0,.30425-.15253.43167-.29551.21268-.23861.35873-.4369.1492-.63538a8.50425,8.50425,0,0,0-2.62312-1.694A9.0177,9.0177,0,0,0,13.19058,4.14283ZM19.50945,18.6236h0a.93171.93171,0,0,0-.36642-.25406.26589.26589,0,0,0-.27613.06613l-.06943.06929A7.90606,7.90606,0,0,1,7.60639,18.505a7.57284,7.57284,0,0,1-1.696-2.51537,8.58715,8.58715,0,0,1-.5147-1.77754l-.00871-.04864c-.04939-.25873-.28755-.27684-.62981-.22448-.14234.02178-.5755.088-.53426.39969l.001.00712a9.08807,9.08807,0,0,0,15.406,4.99094c.00193-.00192.04753-.04718.0725-.07436C19.79425,19.16234,19.87422,18.98728,19.50945,18.6236Z"></path></svg>',
@@ -294,9 +299,9 @@
294 299 'icon' => '<svg width="24" height="24" viewBox="0 0 32 32" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M16.708 0.027c1.745-0.027 3.48-0.011 5.213-0.027 0.105 2.041 0.839 4.12 2.333 5.563 1.491 1.479 3.6 2.156 5.652 2.385v5.369c-1.923-0.063-3.855-0.463-5.6-1.291-0.76-0.344-1.468-0.787-2.161-1.24-0.009 3.896 0.016 7.787-0.025 11.667-0.104 1.864-0.719 3.719-1.803 5.255-1.744 2.557-4.771 4.224-7.88 4.276-1.907 0.109-3.812-0.411-5.437-1.369-2.693-1.588-4.588-4.495-4.864-7.615-0.032-0.667-0.043-1.333-0.016-1.984 0.24-2.537 1.495-4.964 3.443-6.615 2.208-1.923 5.301-2.839 8.197-2.297 0.027 1.975-0.052 3.948-0.052 5.923-1.323-0.428-2.869-0.308-4.025 0.495-0.844 0.547-1.485 1.385-1.819 2.333-0.276 0.676-0.197 1.427-0.181 2.145 0.317 2.188 2.421 4.027 4.667 3.828 1.489-0.016 2.916-0.88 3.692-2.145 0.251-0.443 0.532-0.896 0.547-1.417 0.131-2.385 0.079-4.76 0.095-7.145 0.011-5.375-0.016-10.735 0.025-16.093z" /></svg>',
295 300 ),
296 301 'tumblr' => array(
297 302 'name' => _x( 'Tumblr', 'social link block variation name' ),
298 - 'icon' => '<svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M17.04 21.28h-3.28c-2.84 0-4.94-1.37-4.94-5.02v-5.67H6.08V7.5c2.93-.73 4.11-3.3 4.3-5.48h3.01v4.93h3.47v3.65H13.4v4.93c0 1.47.73 2.01 1.92 2.01h1.73v3.75z" /></path></svg>',
303 + 'icon' => '<svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M17.04 21.28h-3.28c-2.84 0-4.94-1.37-4.94-5.02v-5.67H6.08V7.5c2.93-.73 4.11-3.3 4.3-5.48h3.01v4.93h3.47v3.65H13.4v4.93c0 1.47.73 2.01 1.92 2.01h1.73v3.75z"></path></svg>',
299 304 ),
300 305 'twitch' => array(
301 306 'name' => _x( 'Twitch', 'social link block variation name' ),
302 307 'icon' => '<svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M16.499,8.089h-1.636v4.91h1.636V8.089z M12,8.089h-1.637v4.91H12V8.089z M4.228,3.178L3,6.451v13.092h4.499V22h2.456 l2.454-2.456h3.681L21,14.636V3.178H4.228z M19.364,13.816l-2.864,2.865H12l-2.453,2.453V16.68H5.863V4.814h13.501V13.816z"></path></svg>',
@@ -335,9 +340,9 @@
335 340 ),
336 341 );
337 342
338 343 /**
339 - * Filter the list of available social service.
344 + * Filters the list of available social service.
340 345 *
341 346 * This can be used to change icons or add custom icons (additionally to variations in the editor).
342 347 * Icons should be directly renderable - therefore SVGs work best.
343 348 *
@@ -343,9 +348,8 @@
343 348 *
344 349 * @since 6.9.0
345 350 *
346 351 * @param array $services_data The list of services. Each item is an array containing a 'name' and 'icon' key.
347 - * @return array The list of social services.
348 352 */
349 353 $services_data = apply_filters( 'block_core_social_link_get_services', $services_data );
350 354
351 355 if ( ! empty( $service )
@@ -366,9 +370,8 @@
366 370 *
367 371 * @since 5.7.0
368 372 *
369 373 * @param array $context Block context passed to Social Link.
370 - *
371 374 * @return string Inline CSS styles for link's icon and background colors.
372 375 */
373 376 function gutenberg_block_core_social_link_get_color_styles( $context ) {
374 377 $styles = array();
@@ -389,9 +392,8 @@
389 392 *
390 393 * @since 6.3.0
391 394 *
392 395 * @param array $context Block context passed to Social Sharing Link.
393 - *
394 396 * @return string CSS classes for link's icon and background colors.
395 397 */
396 398 function gutenberg_block_core_social_link_get_color_classes( $context ) {
397 399 $classes = array();