From 299b89409dab4b86fd62756dc64d6176d5d591be Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Wed, 6 Jul 2022 10:45:07 +0400 Subject: [PATCH] Social Links: Set the default protocol to 'https' if not specified (#42167) --- packages/block-library/src/social-link/index.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/block-library/src/social-link/index.php b/packages/block-library/src/social-link/index.php index 488b91b02c27de..c1f5afcba4df07 100644 --- a/packages/block-library/src/social-link/index.php +++ b/packages/block-library/src/social-link/index.php @@ -27,6 +27,14 @@ function render_block_core_social_link( $attributes, $content, $block ) { return ''; } + /** + * 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; + } + $rel_target_attributes = ''; if ( $open_in_new_tab ) { $rel_target_attributes = 'rel="noopener nofollow" target="_blank"';