diff -r 7b1b88e27a20 -r 48c4eec2b7e6 wp/wp-includes/blocks/social-link.php --- a/wp/wp-includes/blocks/social-link.php Thu Sep 29 08:06:27 2022 +0200 +++ b/wp/wp-includes/blocks/social-link.php Fri Sep 05 18:40:08 2025 +0200 @@ -8,6 +8,8 @@ /** * Renders the `core/social-link` block on server. * + * @since 5.4.0 + * * @param Array $attributes The block attributes. * @param String $content InnerBlocks content of the Block. * @param WP_Block $block Block object. @@ -17,9 +19,12 @@ function render_block_core_social_link( $attributes, $content, $block ) { $open_in_new_tab = isset( $block->context['openInNewTab'] ) ? $block->context['openInNewTab'] : false; - $service = ( isset( $attributes['service'] ) ) ? $attributes['service'] : 'Icon'; - $url = ( isset( $attributes['url'] ) ) ? $attributes['url'] : false; - $label = ( isset( $attributes['label'] ) ) ? $attributes['label'] : block_core_social_link_get_name( $service ); + $text = ! empty( $attributes['label'] ) ? trim( $attributes['label'] ) : ''; + + $service = isset( $attributes['service'] ) ? $attributes['service'] : 'Icon'; + $url = isset( $attributes['url'] ) ? $attributes['url'] : false; + $text = $text ? $text : block_core_social_link_get_name( $service ); + $rel = isset( $attributes['rel'] ) ? $attributes['rel'] : ''; $show_labels = array_key_exists( 'showLabels', $block->context ) ? $block->context['showLabels'] : false; // Don't render a link if there is no URL set. @@ -27,31 +32,51 @@ return ''; } - $rel_target_attributes = ''; - if ( $open_in_new_tab ) { - $rel_target_attributes = 'rel="noopener nofollow" target="_blank"'; + /** + * Prepend emails with `mailto:` if not set. + * The `is_email` returns false for emails with schema. + */ + if ( is_email( $url ) ) { + $url = 'mailto:' . antispambot( $url ); + } + + /** + * Prepend URL with https:// if it doesn't appear to contain a scheme + * and it's not a relative link starting with //. + */ + if ( ! parse_url( $url, PHP_URL_SCHEME ) && ! str_starts_with( $url, '//' ) ) { + $url = 'https://' . $url; } $icon = block_core_social_link_get_icon( $service ); $wrapper_attributes = get_block_wrapper_attributes( array( - 'class' => 'wp-social-link wp-social-link-' . $service, + 'class' => 'wp-social-link wp-social-link-' . $service . block_core_social_link_get_color_classes( $block->context ), 'style' => block_core_social_link_get_color_styles( $block->context ), ) ); $link = '
  • '; - $link .= ''; + $link .= ''; $link .= $icon; - $link .= ''; - $link .= esc_html( $label ); - $link .= '
  • '; + $link .= '' . esc_html( $text ) . ''; + $link .= ''; - return $link; + $processor = new WP_HTML_Tag_Processor( $link ); + $processor->next_tag( 'a' ); + if ( $open_in_new_tab ) { + $processor->set_attribute( 'rel', trim( $rel . ' noopener nofollow' ) ); + $processor->set_attribute( 'target', '_blank' ); + } elseif ( '' !== $rel ) { + $processor->set_attribute( 'rel', trim( $rel ) ); + } + return $processor->get_updated_html(); } /** * Registers the `core/social-link` blocks. + * + * @since 5.4.0 */ function register_block_core_social_link() { register_block_type_from_metadata( @@ -67,6 +92,8 @@ /** * Returns the SVG for social link. * + * @since 5.4.0 + * * @param string $service The service icon. * * @return string SVG Element for service icon. @@ -83,6 +110,8 @@ /** * Returns the brand name for social link. * + * @since 5.4.0 + * * @param string $service The service icon. * * @return string Brand label. @@ -99,6 +128,8 @@ /** * Returns the SVG for social link. * + * @since 5.4.0 + * * @param string $service The service slug to extract data from. * @param string $field The field ('name', 'icon', etc) to extract for a service. * @@ -122,9 +153,13 @@ 'name' => 'Behance', 'icon' => '', ), + 'bluesky' => array( + 'name' => 'Bluesky', + 'icon' => '', + ), 'chain' => array( 'name' => 'Link', - 'icon' => '', + 'icon' => '', ), 'codepen' => array( 'name' => 'CodePen', @@ -174,6 +209,10 @@ 'name' => 'GitHub', 'icon' => '', ), + 'gravatar' => array( + 'name' => 'Gravatar', + 'icon' => '', + ), 'instagram' => array( 'name' => 'Instagram', 'icon' => '', @@ -188,7 +227,7 @@ ), 'mail' => array( 'name' => 'Mail', - 'icon' => '', + 'icon' => '', ), 'mastodon' => array( 'name' => 'Mastodon', @@ -200,11 +239,11 @@ ), 'medium' => array( 'name' => 'Medium', - 'icon' => '', + 'icon' => '', ), 'patreon' => array( 'name' => 'Patreon', - 'icon' => '', + 'icon' => '', ), 'pinterest' => array( 'name' => 'Pinterest', @@ -216,7 +255,11 @@ ), 'reddit' => array( 'name' => 'Reddit', - 'icon' => '', + 'icon' => '', + ), + 'share' => array( + 'name' => 'Share Icon', + 'icon' => '', ), 'skype' => array( 'name' => 'Skype', @@ -238,6 +281,10 @@ 'name' => 'Telegram', 'icon' => '', ), + 'threads' => array( + 'name' => 'Threads', + 'icon' => '', + ), 'tiktok' => array( 'name' => 'TikTok', 'icon' => '', @@ -266,6 +313,14 @@ 'name' => 'WordPress', 'icon' => '', ), + 'whatsapp' => array( + 'name' => 'WhatsApp', + 'icon' => '', + ), + 'x' => array( + 'name' => 'X', + 'icon' => '', + ), 'yelp' => array( 'name' => 'Yelp', 'icon' => '', @@ -274,10 +329,6 @@ 'name' => 'YouTube', 'icon' => '', ), - 'share' => array( - 'name' => 'Share Icon', - 'icon' => '', - ), ); if ( ! empty( $service ) @@ -296,6 +347,8 @@ /** * Returns CSS styles for icon and icon background colors. * + * @since 5.7.0 + * * @param array $context Block context passed to Social Link. * * @return string Inline CSS styles for link's icon and background colors. @@ -313,3 +366,26 @@ return implode( '', $styles ); } + +/** + * Returns CSS classes for icon and icon background colors. + * + * @since 6.3.0 + * + * @param array $context Block context passed to Social Sharing Link. + * + * @return string CSS classes for link's icon and background colors. + */ +function block_core_social_link_get_color_classes( $context ) { + $classes = array(); + + if ( array_key_exists( 'iconColor', $context ) ) { + $classes[] = 'has-' . $context['iconColor'] . '-color'; + } + + if ( array_key_exists( 'iconBackgroundColor', $context ) ) { + $classes[] = 'has-' . $context['iconBackgroundColor'] . '-background-color'; + } + + return ' ' . implode( ' ', $classes ); +}