函数文档

wp_get_update_php_url()

💡 云策文档标注

概述

wp_get_update_php_url() 函数用于获取关于更新站点当前运行 PHP 版本的更多信息的 URL。该 URL 可通过环境变量或过滤器进行自定义,但空字符串会被忽略并回退到默认 URL。

关键要点

  • 函数返回一个字符串 URL,指向学习如何更新 PHP 的页面。
  • URL 可通过环境变量 WP_UPDATE_PHP_URL 或 'wp_update_php_url' 过滤器进行覆盖。
  • 如果提供的 URL 为空字符串,函数将使用默认 URL。
  • 建议链接页面本地化为站点语言。
  • 函数内部调用 wp_get_default_update_php_url() 获取默认 URL,并应用过滤器。

代码示例

// Get PHP update URL.
$php_update_url = wp_get_update_php_url();

📄 原文内容

Gets the URL to learn more about updating the PHP version the site is running on.

Description

This URL can be overridden by specifying an environment variable WP_UPDATE_PHP_URL or by using the ‘wp_update_php_url’ filter. Providing an empty string is not allowed and will result in the default URL being used. Furthermore the page the URL links to should preferably be localized in the site language.

Return

string URL to learn more about updating PHP.

Source

function wp_get_update_php_url() {
	$default_url = wp_get_default_update_php_url();

	$update_url = $default_url;
	if ( false !== getenv( 'WP_UPDATE_PHP_URL' ) ) {
		$update_url = getenv( 'WP_UPDATE_PHP_URL' );
	}

	/**
	 * Filters the URL to learn more about updating the PHP version the site is running on.
	 *
	 * Providing an empty string is not allowed and will result in the default URL being used. Furthermore
	 * the page the URL links to should preferably be localized in the site language.
	 *
	 * @since 5.1.0
	 *
	 * @param string $update_url URL to learn more about updating PHP.
	 */
	$update_url = apply_filters( 'wp_update_php_url', $update_url );

	if ( empty( $update_url ) ) {
		$update_url = $default_url;
	}

	return $update_url;
}

Hooks

apply_filters( ‘wp_update_php_url’, string $update_url )

Filters the URL to learn more about updating the PHP version the site is running on.

Changelog

Version Description
5.1.0 Introduced.

User Contributed Notes