diff -r 34716fd837a4 -r be944660c56a wp/wp-includes/blocks/social-link.php --- a/wp/wp-includes/blocks/social-link.php Tue Dec 15 15:52:01 2020 +0100 +++ b/wp/wp-includes/blocks/social-link.php Wed Sep 21 18:19:35 2022 +0200 @@ -8,14 +8,23 @@ /** * Renders the `core/social-link` block on server. * - * @param array $attributes The block attributes. + * @param Array $attributes The block attributes. + * @param String $content InnerBlocks content of the Block. + * @param WP_Block $block Block object. * * @return string Rendered HTML of the referenced block. */ -function render_block_core_social_link( $attributes ) { - $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 ); +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'] : sprintf( + /* translators: %1$s: Social-network name. %2$s: URL. */ + __( '%1$s: %2$s' ), + block_core_social_link_get_name( $service ), + $url + ); $class_name = isset( $attributes['className'] ) ? ' ' . $attributes['className'] : false; // Don't render a link if there is no URL set. @@ -23,8 +32,20 @@ return ''; } - $icon = block_core_social_link_get_icon( $service ); - return ''; + $attribute = ''; + if ( $open_in_new_tab ) { + $attribute = 'rel="noopener nofollow" target="_blank"'; + } + + $icon = block_core_social_link_get_icon( $service ); + $wrapper_attributes = get_block_wrapper_attributes( + array( + 'class' => 'wp-social-link wp-social-link-' . $service . $class_name, + 'style' => block_core_social_link_get_color_styles( $block->context ), + ) + ); + + return '
  • ' . $icon . '
  • '; } /** @@ -179,6 +200,10 @@ 'name' => 'Medium', 'icon' => '', ), + 'patreon' => array( + 'name' => 'Patreon', + 'icon' => '', + ), 'pinterest' => array( 'name' => 'Pinterest', 'icon' => '', @@ -207,6 +232,14 @@ 'name' => 'Spotify', 'icon' => '', ), + 'telegram' => array( + 'name' => 'Telegram', + 'icon' => '', + ), + 'tiktok' => array( + 'name' => 'TikTok', + 'icon' => '', + ), 'tumblr' => array( 'name' => 'Tumblr', 'icon' => '', @@ -257,3 +290,24 @@ return $services_data; } + +/** + * Returns CSS styles for icon and icon background colors. + * + * @param array $context Block context passed to Social Link. + * + * @return string Inline CSS styles for link's icon and background colors. + */ +function block_core_social_link_get_color_styles( $context ) { + $styles = array(); + + if ( array_key_exists( 'iconColorValue', $context ) ) { + $styles[] = 'color: ' . $context['iconColorValue'] . '; '; + } + + if ( array_key_exists( 'iconBackgroundColorValue', $context ) ) { + $styles[] = 'background-color: ' . $context['iconBackgroundColorValue'] . '; '; + } + + return implode( '', $styles ); +}