context['openInNewTab'] ?? false; $text = ! empty( $attributes['label'] ) ? trim( $attributes['label'] ) : ''; $service = $attributes['service'] ?? 'Icon'; $url = $attributes['url'] ?? false; $text = $text ? $text : block_core_social_link_get_name( $service ); $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. if ( ! $url ) { return ''; } /** * 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 or a fragment. */ if ( ! parse_url( $url, PHP_URL_SCHEME ) && ! str_starts_with( $url, '//' ) && ! 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 . block_core_social_link_get_color_classes( $block->context ), 'style' => block_core_social_link_get_color_styles( $block->context ), ) ); $link = '
  • '; $link .= ''; $link .= $icon; $link .= '' . esc_html( $text ) . ''; $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( __DIR__ . '/social-link', array( 'render_callback' => 'render_block_core_social_link', ) ); } add_action( 'init', 'register_block_core_social_link' ); /** * Returns the SVG for social link. * * @since 5.4.0 * * @param string $service The service icon. * * @return string SVG Element for service icon. */ function block_core_social_link_get_icon( $service ) { $services = block_core_social_link_services(); if ( isset( $services[ $service ] ) && isset( $services[ $service ]['icon'] ) ) { return $services[ $service ]['icon']; } return $services['share']['icon']; } /** * Returns the brand name for social link. * * @since 5.4.0 * * @param string $service The service icon. * * @return string Brand label. */ function block_core_social_link_get_name( $service ) { $services = block_core_social_link_services(); if ( isset( $services[ $service ] ) && isset( $services[ $service ]['name'] ) ) { return $services[ $service ]['name']; } return $services['share']['name']; } /** * 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. * * @return array|string */ function block_core_social_link_services( $service = '', $field = '' ) { $services_data = array( 'fivehundredpx' => array( 'name' => _x( '500px', 'social link block variation name' ), 'icon' => '', ), 'amazon' => array( 'name' => _x( 'Amazon', 'social link block variation name' ), 'icon' => '', ), 'bandcamp' => array( 'name' => _x( 'Bandcamp', 'social link block variation name' ), 'icon' => '', ), 'behance' => array( 'name' => _x( 'Behance', 'social link block variation name' ), 'icon' => '', ), 'bluesky' => array( 'name' => _x( 'Bluesky', 'social link block variation name' ), 'icon' => '', ), 'chain' => array( 'name' => _x( 'Link', 'social link block variation name' ), 'icon' => '', ), 'codepen' => array( 'name' => _x( 'CodePen', 'social link block variation name' ), 'icon' => '', ), 'deviantart' => array( 'name' => _x( 'DeviantArt', 'social link block variation name' ), 'icon' => '', ), 'discord' => array( 'name' => _x( 'Discord', 'social link block variation name' ), 'icon' => '', ), 'dribbble' => array( 'name' => _x( 'Dribbble', 'social link block variation name' ), 'icon' => '', ), 'dropbox' => array( 'name' => _x( 'Dropbox', 'social link block variation name' ), 'icon' => '', ), 'etsy' => array( 'name' => _x( 'Etsy', 'social link block variation name' ), 'icon' => '', ), 'facebook' => array( 'name' => _x( 'Facebook', 'social link block variation name' ), 'icon' => '', ), 'feed' => array( 'name' => _x( 'RSS Feed', 'social link block variation name' ), 'icon' => '', ), 'flickr' => array( 'name' => _x( 'Flickr', 'social link block variation name' ), 'icon' => '', ), 'foursquare' => array( 'name' => _x( 'Foursquare', 'social link block variation name' ), 'icon' => '', ), 'goodreads' => array( 'name' => _x( 'Goodreads', 'social link block variation name' ), 'icon' => '', ), 'google' => array( 'name' => _x( 'Google', 'social link block variation name' ), 'icon' => '', ), 'github' => array( 'name' => _x( 'GitHub', 'social link block variation name' ), 'icon' => '', ), 'gravatar' => array( 'name' => _x( 'Gravatar', 'social link block variation name' ), 'icon' => '', ), 'instagram' => array( 'name' => _x( 'Instagram', 'social link block variation name' ), 'icon' => '', ), 'lastfm' => array( 'name' => _x( 'Last.fm', 'social link block variation name' ), 'icon' => '', ), 'linkedin' => array( 'name' => _x( 'LinkedIn', 'social link block variation name' ), 'icon' => '', ), 'mail' => array( 'name' => _x( 'Mail', 'social link block variation name' ), 'icon' => '', ), 'mastodon' => array( 'name' => _x( 'Mastodon', 'social link block variation name' ), 'icon' => '', ), 'meetup' => array( 'name' => _x( 'Meetup', 'social link block variation name' ), 'icon' => '', ), 'medium' => array( 'name' => _x( 'Medium', 'social link block variation name' ), 'icon' => '', ), 'patreon' => array( 'name' => _x( 'Patreon', 'social link block variation name' ), 'icon' => '', ), 'pinterest' => array( 'name' => _x( 'Pinterest', 'social link block variation name' ), 'icon' => '', ), 'pocket' => array( 'name' => _x( 'Pocket', 'social link block variation name' ), 'icon' => '', ), 'reddit' => array( 'name' => _x( 'Reddit', 'social link block variation name' ), 'icon' => '', ), 'share' => array( 'name' => _x( 'Share Icon', 'social link block variation name' ), 'icon' => '', ), 'skype' => array( 'name' => _x( 'Skype', 'social link block variation name' ), 'icon' => '', ), 'snapchat' => array( 'name' => _x( 'Snapchat', 'social link block variation name' ), 'icon' => '', ), 'soundcloud' => array( 'name' => _x( 'SoundCloud', 'social link block variation name' ), 'icon' => '', ), 'spotify' => array( 'name' => _x( 'Spotify', 'social link block variation name' ), 'icon' => '', ), 'telegram' => array( 'name' => _x( 'Telegram', 'social link block variation name' ), 'icon' => '', ), 'threads' => array( 'name' => _x( 'Threads', 'social link block variation name' ), 'icon' => '', ), 'tiktok' => array( 'name' => _x( 'TikTok', 'social link block variation name' ), 'icon' => '', ), 'tumblr' => array( 'name' => _x( 'Tumblr', 'social link block variation name' ), 'icon' => '', ), 'twitch' => array( 'name' => _x( 'Twitch', 'social link block variation name' ), 'icon' => '', ), 'twitter' => array( 'name' => _x( 'Twitter', 'social link block variation name' ), 'icon' => '', ), 'vimeo' => array( 'name' => _x( 'Vimeo', 'social link block variation name' ), 'icon' => '', ), 'vk' => array( 'name' => _x( 'VK', 'social link block variation name' ), 'icon' => '', ), 'wordpress' => array( 'name' => _x( 'WordPress', 'social link block variation name' ), 'icon' => '', ), 'whatsapp' => array( 'name' => _x( 'WhatsApp', 'social link block variation name' ), 'icon' => '', ), 'x' => array( 'name' => _x( 'X', 'social link block variation name' ), 'icon' => '', ), 'yelp' => array( 'name' => _x( 'Yelp', 'social link block variation name' ), 'icon' => '', ), 'youtube' => array( 'name' => _x( 'YouTube', 'social link block variation name' ), 'icon' => '', ), ); /** * Filter the list of available social service. * * This can be used to change icons or add custom icons (additionally to variations in the editor). * Icons should be directly renderable - therefore SVGs work best. * * @since 6.9.0 * * @param array $services_data The list of services. Each item is an array containing a 'name' and 'icon' key. * @return array The list of social services. */ $services_data = apply_filters( 'block_core_social_link_get_services', $services_data ); if ( ! empty( $service ) && ! empty( $field ) && isset( $services_data[ $service ] ) && ( 'icon' === $field || 'name' === $field ) ) { return $services_data[ $service ][ $field ]; } elseif ( ! empty( $service ) && isset( $services_data[ $service ] ) ) { return $services_data[ $service ]; } return $services_data; } /** * 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. */ 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 ); } /** * 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 ); } array( 'dependencies' => array( ), 'version' => '1c371cb517a97cdbcb9f' ), 'abilities/index.js' => array( 'dependencies' => array( 'wp-data', 'wp-i18n' ), 'version' => 'f3475bc77a30dcc5b38d' ), 'block-editor/utils/fit-text-frontend.js' => array( 'dependencies' => array( ), 'module_dependencies' => array( array( 'id' => '@wordpress/interactivity', 'import' => 'static' ) ), 'version' => '383c7a8bd24a1f2fd9b9' ), 'block-library/accordion/view.js' => array( 'dependencies' => array( ), 'module_dependencies' => array( array( 'id' => '@wordpress/interactivity', 'import' => 'static' ) ), 'version' => '2af01b43d30739c3fb8d' ), 'block-library/file/view.js' => array( 'dependencies' => array( ), 'module_dependencies' => array( array( 'id' => '@wordpress/interactivity', 'import' => 'static' ) ), 'version' => '7d4d261d10dca47ebecb' ), 'block-library/form/view.js' => array( 'dependencies' => array( ), 'version' => '5542f8ad251fe43ef09e' ), 'block-library/image/view.js' => array( 'dependencies' => array( ), 'module_dependencies' => array( array( 'id' => '@wordpress/interactivity', 'import' => 'static' ) ), 'version' => '25ee935fd6c67371d0f3' ), 'block-library/navigation/view.js' => array( 'dependencies' => array( ), 'module_dependencies' => array( array( 'id' => '@wordpress/interactivity', 'import' => 'static' ) ), 'version' => '96a846e1d7b789c39ab9' ), 'block-library/playlist/view.js' => array( 'dependencies' => array( ), 'module_dependencies' => array( array( 'id' => '@wordpress/interactivity', 'import' => 'static' ) ), 'version' => '99f747d731f80246db11' ), 'block-library/query/view.js' => array( 'dependencies' => array( ), 'module_dependencies' => array( array( 'id' => '@wordpress/interactivity', 'import' => 'static' ), array( 'id' => '@wordpress/interactivity-router', 'import' => 'dynamic' ) ), 'version' => '7a4ec5bfb61a7137cf4b' ), 'block-library/search/view.js' => array( 'dependencies' => array( ), 'module_dependencies' => array( array( 'id' => '@wordpress/interactivity', 'import' => 'static' ) ), 'version' => '38bd0e230eaffa354d2a' ), 'block-library/tabs/view.js' => array( 'dependencies' => array( ), 'module_dependencies' => array( array( 'id' => '@wordpress/interactivity', 'import' => 'static' ) ), 'version' => '1f60dd5e3fa56c6b2e2e' ), 'boot/index.js' => array( 'dependencies' => array( 'react', 'react-dom', 'react-jsx-runtime', 'wp-commands', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-editor', 'wp-element', 'wp-html-entities', 'wp-i18n', 'wp-keyboard-shortcuts', 'wp-keycodes', 'wp-notices', 'wp-primitives', 'wp-private-apis', 'wp-theme', 'wp-url' ), 'module_dependencies' => array( array( 'id' => '@wordpress/a11y', 'import' => 'static' ), array( 'id' => '@wordpress/lazy-editor', 'import' => 'dynamic' ), array( 'id' => '@wordpress/route', 'import' => 'static' ) ), 'version' => '54bb5a420026a61c7e4f' ), 'connectors/index.js' => array( 'dependencies' => array( 'react-jsx-runtime', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-private-apis' ), 'version' => '274797868955a828dfdc' ), 'core-abilities/index.js' => array( 'dependencies' => array( 'wp-api-fetch', 'wp-url' ), 'module_dependencies' => array( array( 'id' => '@wordpress/abilities', 'import' => 'static' ) ), 'version' => '012760fd849397dd0031' ), 'edit-site-init/index.js' => array( 'dependencies' => array( 'react-jsx-runtime', 'wp-data', 'wp-element', 'wp-primitives' ), 'module_dependencies' => array( array( 'id' => '@wordpress/boot', 'import' => 'static' ) ), 'version' => 'e57f44d1a9f69e75d2d9' ), 'interactivity/index.js' => array( 'dependencies' => array( ), 'version' => 'efaa5193bbad9c60ffd1' ), 'interactivity-router/full-page.js' => array( 'dependencies' => array( ), 'module_dependencies' => array( array( 'id' => '@wordpress/interactivity-router', 'import' => 'dynamic' ) ), 'version' => '5c07cd7a12ae073c5241' ), 'interactivity-router/index.js' => array( 'dependencies' => array( ), 'module_dependencies' => array( array( 'id' => '@wordpress/a11y', 'import' => 'dynamic' ), array( 'id' => '@wordpress/interactivity', 'import' => 'static' ) ), 'version' => '71aa17bac91628a0f874' ), 'latex-to-mathml/index.js' => array( 'dependencies' => array( ), 'version' => 'e5fd3ae6d2c3b6e669da' ), 'latex-to-mathml/loader.js' => array( 'dependencies' => array( ), 'module_dependencies' => array( array( 'id' => '@wordpress/latex-to-mathml', 'import' => 'dynamic' ) ), 'version' => '4f37456af539bd3d2351' ), 'lazy-editor/index.js' => array( 'dependencies' => array( 'react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-editor', 'wp-element', 'wp-i18n', 'wp-private-apis', 'wp-style-engine' ), 'version' => '30ab62f45bfe9f971ea0' ), 'route/index.js' => array( 'dependencies' => array( 'react', 'react-dom', 'react-jsx-runtime', 'wp-private-apis' ), 'version' => 'c5843b6c5e84b352f43b' ), 'workflow/index.js' => array( 'dependencies' => array( 'react', 'react-dom', 'react-jsx-runtime', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-keyboard-shortcuts', 'wp-primitives', 'wp-private-apis' ), 'module_dependencies' => array( array( 'id' => '@wordpress/abilities', 'import' => 'static' ) ), 'version' => '13556bc597bbf2a8d620' ) );