Warning: Trying to access array offset on false in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 216
set_url_scheme() - 设置URL的scheme - WordPress函数 - WordPress动力
当前浏览:首页 / WordPress函数 / set_url_scheme()

set_url_scheme( string $url, string|null $scheme = null ): string

设置URL的scheme


Warning: Undefined array key -1 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 185

Warning: Undefined array key 3 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 186

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "07e66cb4c5ecaad84c5914cd20f91506" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "6f1a738255000cf2c8ba3882fd6e44da" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "05a767e1e80b3fbcaa4313c042c82dd3" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

scheme

setmore...

urlmore...


参数

$urlstring必填
包含scheme的绝对URL
$schemestring|null可选
给出$url的scheme。当前为'http'、'https'、'login'、'login_post'、'admin'、'relative'、'rest'、'rpc'或null。

默认:null


返回

string 具有所选scheme的URL。


钩子



源码

查看源码 官方文档


更新日志

版本描述
4.4.0添加了'rest'方案。
3.4.0开始引入

使用示例

  • 示例1

    重要提示: set_url_scheme()不会向空URL添加scheme。如果你传入‘example.org/what/ever’,你会从另一边得到‘example.org/what/ever’。因此,如果您知道输入URL没有基础scheme,那么您应该始终向URl添加基础scheme,例如‘https://’。

    $url = 'example.org/what/ever/'
    print_r( set_url_scheme( $url, 'https' ) );
    // Result: 'example.org/what/ever'
    
    print_r( set_url_scheme( 'http://' . $url, 'https' ) );
    // Result: 'https://example.org/what/ever ('https' if is_ssl() is true, otherwise 'http')
  • 示例2

    使用is_ssl()

    set_url_scheme()的一个优点是,如果您处于SSL环境中,并且一切都正常工作,那么您不必定义scheme,因为set_url_scheme()将为您实现这一点。

    例如:

    $url = 'http://example.org/some/permalink';
    
    print_r( set_url_scheme( $url ) );
    // If is_ssl() is true:
    // Result: 'https://example.org/some/permalink
    //
    // If is_ssl() is false:
    // Result: 'http://example.org/some/permalink (no change)