wp_guess_url
函数
wp_guess_url ( No parameters )
- 返回值
-
- (string) The guessed URL.
- 定义位置
-
-
wp-includes/functions.php
, line 6038
-
wp-includes/functions.php
- 引入
- 2.6.0
- 弃用
- –
猜测网站的URL。
将删除wp-admin链接,只检索不在wp-admin目录中的URL。
function wp_guess_url() { if ( defined( 'WP_SITEURL' ) && '' !== WP_SITEURL ) { $url = WP_SITEURL; } else { $abspath_fix = str_replace( '', '/', ABSPATH ); $script_filename_dir = dirname( $_SERVER['SCRIPT_FILENAME'] ); // The request is for the admin. if ( strpos( $_SERVER['REQUEST_URI'], 'wp-admin' ) !== false || strpos( $_SERVER['REQUEST_URI'], 'wp-login.php' ) !== false ) { $path = preg_replace( '#/(wp-admin/?.*|wp-login.php.*)#i', '', $_SERVER['REQUEST_URI'] ); // The request is for a file in ABSPATH. } elseif ( $script_filename_dir . '/' === $abspath_fix ) { // Strip off any file/query params in the path. $path = preg_replace( '#/[^/]*$#i', '', $_SERVER['PHP_SELF'] ); } else { if ( false !== strpos( $_SERVER['SCRIPT_FILENAME'], $abspath_fix ) ) { // Request is hitting a file inside ABSPATH. $directory = str_replace( ABSPATH, '', $script_filename_dir ); // Strip off the subdirectory, and any file/query params. $path = preg_replace( '#/' . preg_quote( $directory, '#' ) . '/[^/]*$#i', '', $_SERVER['REQUEST_URI'] ); } elseif ( false !== strpos( $abspath_fix, $script_filename_dir ) ) { // Request is hitting a file above ABSPATH. $subdirectory = substr( $abspath_fix, strpos( $abspath_fix, $script_filename_dir ) + strlen( $script_filename_dir ) ); // Strip off any file/query params from the path, appending the subdirectory to the installation. $path = preg_replace( '#/[^/]*$#i', '', $_SERVER['REQUEST_URI'] ) . $subdirectory; } else { $path = $_SERVER['REQUEST_URI']; } } $schema = is_ssl() ? 'https://' : 'http://'; // set_url_scheme() is not defined yet. $url = $schema . $_SERVER['HTTP_HOST'] . $path; } return rtrim( $url, '/' ); }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。