wp_get_direct_php_update_url()
云策文档标注
概述
wp_get_direct_php_update_url() 函数用于获取直接更新站点运行 PHP 版本的 URL。该 URL 仅在特定条件下返回,允许主机引导用户至 PHP 更新页面。
关键要点
- 函数返回一个字符串,表示直接更新 PHP 的 URL,若无则返回空字符串。
- URL 的获取依赖于环境变量 WP_DIRECT_UPDATE_PHP_URL 或通过 'wp_direct_php_update_url' 过滤器进行自定义。
- 此功能主要用于主机环境,方便用户快速访问 PHP 更新界面。
代码示例
function wp_get_direct_php_update_url() {
$direct_update_url = '';
if ( false !== getenv( 'WP_DIRECT_UPDATE_PHP_URL' ) ) {
$direct_update_url = getenv( 'WP_DIRECT_UPDATE_PHP_URL' );
}
/**
* Filters the URL for directly updating the PHP version the site is running on from the host.
*
* @since 5.1.1
*
* @param string $direct_update_url URL for directly updating PHP.
*/
$direct_update_url = apply_filters( 'wp_direct_php_update_url', $direct_update_url );
return $direct_update_url;
}注意事项
- 函数自 WordPress 5.1.1 版本引入,需确保环境兼容。
- 实际使用时,应检查返回的 URL 是否有效,避免空字符串导致链接失效。
- 通过过滤器 'wp_direct_php_update_url' 可以灵活修改 URL,适用于自定义主机配置。
原文内容
Gets the URL for directly updating the PHP version the site is running on.
Description
A URL will only be returned if the WP_DIRECT_UPDATE_PHP_URL environment variable is specified or by using the ‘wp_direct_php_update_url’ filter. This allows hosts to send users directly to the page where they can update PHP to a newer version.
Source
function wp_get_direct_php_update_url() {
$direct_update_url = '';
if ( false !== getenv( 'WP_DIRECT_UPDATE_PHP_URL' ) ) {
$direct_update_url = getenv( 'WP_DIRECT_UPDATE_PHP_URL' );
}
/**
* Filters the URL for directly updating the PHP version the site is running on from the host.
*
* @since 5.1.1
*
* @param string $direct_update_url URL for directly updating PHP.
*/
$direct_update_url = apply_filters( 'wp_direct_php_update_url', $direct_update_url );
return $direct_update_url;
}
Hooks
- apply_filters( ‘wp_direct_php_update_url’, string $direct_update_url )
-
Filters the URL for directly updating the PHP version the site is running on from the host.
Changelog
| Version | Description |
|---|---|
| 5.1.1 | Introduced. |