-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Social links, default protocol to https if not set #30100
Conversation
Size Change: 0 B Total Size: 1.42 MB ℹ️ View Unchanged
|
A follow up fix, I proposed this change in core: https://core.trac.wordpress.org/ticket/52886 This change can still go in prior, and then if/when the core change goes in it will be seamless to switch over. |
141f4a8
to
1213ae8
Compare
Sorry for inadvertent pings, rebase mishap. 😞 |
If no protocol is specified the core esc_url function will default to http:// protocol, this probably should be updated in core to allow a parameter to default to https See: https://developer.wordpress.org/reference/functions/esc_url/ This change takes the chunk of code from esc_url that determines if needed and defaults to https if no protocol specified. Fixes #21699
1213ae8
to
d2b985c
Compare
d2b985c
to
010b671
Compare
@gwwar Kerry can you take a look through this PR? |
// changed to pass the parameter in esc_url after | ||
// https://core.trac.wordpress.org/ticket/52886 is in core. | ||
if ( strpos( $url, ':' ) === false && ! in_array( $url[0], array( '/', '#', '?' ), true ) && | ||
! preg_match( '/^[a-z0-9-]+?\.php/i', $url ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add a few unit tests for this? For example, why would we be looking for a .php
filename? Are there any other valid protocol-less links that folks would normally enter?
To make this easier to test, we can pull this logic out to a helper function. See example and docs https://developer.wordpress.org/block-editor/contributors/code/testing-overview/#php-testing
If no protocol is specified the core esc_url function will default to http:// protocol, this probably should be updated in core to allow a parameter to default to https
See: https://developer.wordpress.org/reference/functions/esc_url/
This change takes the chunk of code from esc_url that determines if needed and defaults to https if no protocol specified.
Fixes #21699
Testing
Before:
You should see
http://
protocol for links with no protocol specifiedAfter:
You should see
https://
protocol for links with no protocol specified.Links with protocol specified will be unchanged, so
http://
entered will stay ashttp://