On this page
set_url_scheme( string $url, string|null $scheme = null ): string
Sets the scheme for a URL.
Parameters
$urlstring Required-
Absolute URL that includes a scheme
$schemestring|null Optional-
Scheme to give $url. Currently
'http','https','login','login_post','admin','relative','rest','rpc', or null.Default:
null
Return
string URL with chosen scheme.
Source
File: wp-includes/link-template.php. View all references
function set_url_scheme( $url, $scheme = null ) {
$orig_scheme = $scheme;
if ( ! $scheme ) {
$scheme = is_ssl() ? 'https' : 'http';
} elseif ( 'admin' === $scheme || 'login' === $scheme || 'login_post' === $scheme || 'rpc' === $scheme ) {
$scheme = is_ssl() || force_ssl_admin() ? 'https' : 'http';
} elseif ( 'http' !== $scheme && 'https' !== $scheme && 'relative' !== $scheme ) {
$scheme = is_ssl() ? 'https' : 'http';
}
$url = trim( $url );
if ( substr( $url, 0, 2 ) === '//' ) {
$url = 'http:' . $url;
}
if ( 'relative' === $scheme ) {
$url = ltrim( preg_replace( '#^\w+://[^/]*#', '', $url ) );
if ( '' !== $url && '/' === $url[0] ) {
$url = '/' . ltrim( $url, "/ \t\n\r\0\x0B" );
}
} else {
$url = preg_replace( '#^\w+://#', $scheme . '://', $url );
}
/**
* Filters the resulting URL after setting the scheme.
*
* @since 3.4.0
*
* @param string $url The complete URL including scheme and path.
* @param string $scheme Scheme applied to the URL. One of 'http', 'https', or 'relative'.
* @param string|null $orig_scheme Scheme requested for the URL. One of 'http', 'https', 'login',
* 'login_post', 'admin', 'relative', 'rest', 'rpc', or null.
*/
return apply_filters( 'set_url_scheme', $url, $scheme, $orig_scheme );
}
Hooks
- apply_filters( 'set_url_scheme',
string $url ,string $scheme ,string|null $orig_scheme ) -
Filters the resulting URL after setting the scheme.
Related
Uses
| Uses | Description |
|---|---|
| is_ssl() wp-includes/load.php | Determines if SSL is used. |
| force_ssl_admin() wp-includes/functions.php | Determines whether to force SSL used for the Administration Screens. |
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
Used By
| Used By | Description |
|---|---|
| WP_REST_Pattern_Directory_Controller::get_items() wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php | Search and retrieve block patterns metadata |
| get_self_link() wp-includes/feed.php | Returns the link for the currently displayed feed. |
| wp_check_php_version() wp-admin/includes/misc.php | Checks if the user needs to update PHP. |
| WP_Customize_Manager::handle_load_themes_request() wp-includes/class-wp-customize-manager.php | Loads themes into the theme browsing/installation UI. |
| WP_Community_Events::get_events() wp-admin/includes/class-wp-community-events.php | Gets data about events near a particular location. |
| get_header_video_url() wp-includes/theme.php | Retrieves header video URL for custom header. |
| get_rest_url() wp-includes/rest-api.php | Retrieves the URL to a REST endpoint on a site. |
| wp_calculate_image_srcset() wp-includes/media.php | A helper function to calculate the image sources to include in a ‘srcset’ attribute. |
| get_preview_post_link() wp-includes/link-template.php | Retrieves the URL used for the post preview. |
| get_avatar_data() wp-includes/link-template.php | Retrieves default data about the avatar. |
| wp_admin_canonical_url() wp-admin/includes/misc.php | Removes single-use URL parameters and create canonical link based on new URL. |
| translations_api() wp-admin/includes/translation-install.php | Retrieve translations from WordPress Translation API. |
| themes_api() wp-admin/includes/theme.php | Retrieves theme installer pages from the WordPress.org Themes API. |
| WP_List_Table::pagination() wp-admin/includes/class-wp-list-table.php | Displays the pagination. |
| WP_List_Table::print_column_headers() wp-admin/includes/class-wp-list-table.php | Prints column headers, accounting for hidden and sortable columns. |
| get_core_checksums() wp-admin/includes/update.php | Gets and caches the checksums for the given version of WordPress. |
| wp_check_browser_version() wp-admin/includes/dashboard.php | Checks if the user needs a browser update. |
| plugins_api() wp-admin/includes/plugin-install.php | Retrieves plugin installer pages from the WordPress.org Plugins API. |
| add_menu_page() wp-admin/includes/plugin.php | Adds a top-level menu page. |
| edit_form_image_editor() wp-admin/includes/media.php | Displays the image and editor in the post editor |
| wp_ajax_query_themes() wp-admin/includes/ajax-actions.php | Ajax handler for getting themes from themes_api() . |
| get_home_path() wp-admin/includes/file.php | Gets the absolute filesystem path to the root of the WordPress installation. |
| wp_get_popular_importers() wp-admin/includes/import.php | Returns a list from WordPress.org of popular importer plugins. |
| wp_credits() wp-admin/includes/credits.php | Retrieve the contributor credits. |
| Custom_Image_Header::show_header_selector() wp-admin/includes/class-custom-image-header.php | Display UI for selecting one of several default headers. |
| Custom_Background::admin_page() wp-admin/includes/class-custom-background.php | Displays the custom background page. |
| _custom_background_cb() wp-includes/theme.php | Default custom background callback. |
| get_header_image() wp-includes/theme.php | Retrieves header image for custom header. |
| auth_redirect() wp-includes/pluggable.php | Checks if a user is logged in, if not it redirects them to the login page. |
| url_is_accessable_via_ssl() wp-includes/deprecated.php | Determines if the URL can be accessed over SSL. |
| content_url() wp-includes/link-template.php | Retrieves the URL to the content directory. |
| plugins_url() wp-includes/link-template.php | Retrieves a URL within the plugins or mu-plugins directory. |
| network_site_url() wp-includes/link-template.php | Retrieves the site URL for the current network. |
| network_home_url() wp-includes/link-template.php | Retrieves the home URL for the current network. |
| get_home_url() wp-includes/link-template.php | Retrieves the URL for a given site where the front end is accessible. |
| get_site_url() wp-includes/link-template.php | Retrieves the URL for a given site where WordPress application files (e.g. wp-blog-header.php or the wp-admin/ folder) are accessible. |
| wp_version_check() wp-includes/update.php | Checks WordPress version against the newest version. |
| wp_update_plugins() wp-includes/update.php | Checks for available updates to plugins based on the latest versions hosted on WordPress.org. |
| wp_update_themes() wp-includes/update.php | Checks for available updates to themes based on the latest versions hosted on WordPress.org. |
| _wp_menu_item_classes_by_context() wp-includes/nav-menu-template.php | Adds the class property classes for the current context, if applicable. |
| wp_video_shortcode() wp-includes/media.php | Builds the Video shortcode output. |
| wp_get_attachment_url() wp-includes/post.php | Retrieves the URL for an attachment. |
| url_to_postid() wp-includes/rewrite.php | Examines a URL and try to determine the post ID it represents. |
| filter_SSL() wp-includes/ms-functions.php | Formats a URL to use https. |
| install_blog() wp-includes/ms-deprecated.php | Install an empty blog. |
| _WP_Editors::editor_settings() wp-includes/class-wp-editor.php |
Changelog
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/set_url_scheme