函数文档

wp_get_update_php_annotation()

💡 云策文档标注

概述

wp_get_update_php_annotation() 函数用于在 web 主机修改了默认“更新 PHP”页面 URL 时,返回一致的注释文本。它通常与 wp_get_update_php_url() 配合使用,以提供用户友好的信息。

关键要点

  • 函数返回一个字符串,表示更新 PHP 页面的注释;如果无自定义 URL,则返回空字符串。
  • 通过比较 wp_get_update_php_url() 和 wp_get_default_update_php_url() 的返回值,判断是否需要生成注释。
  • 注释内容使用 sprintf() 和 __() 进行格式化和国际化,确保可翻译性。
  • 函数在 WordPress 5.2.0 版本中引入,主要用于插件验证和更新管理场景。

代码示例

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

    if ( $update_url === $default_url ) {
        return '';
    }

    $annotation = sprintf(
        /* translators: %s: Default Update PHP page URL. */
        __( 'This resource is provided by your web host, and is specific to your site. For more information, see the official WordPress documentation.' ),
        esc_url( $default_url )
    );

    return $annotation;
}

注意事项

  • 函数依赖于 wp_get_update_php_url() 和 wp_get_default_update_php_url() 来获取 URL,确保这些函数正常工作。
  • 注释文本包含占位符 %s,用于插入默认 URL,需通过 esc_url() 进行安全转义。
  • 在自定义主题或插件中调用时,注意处理返回的空字符串情况,以避免显示不必要的注释。

📄 原文内容

Returns the default annotation for the web hosting altering the “Update PHP” page URL.

Description

This function is to be used after wp_get_update_php_url() to return a consistent annotation if the web host has altered the default “Update PHP” page URL.

Return

string Update PHP page annotation. An empty string if no custom URLs are provided.

Source

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

	if ( $update_url === $default_url ) {
		return '';
	}

	$annotation = sprintf(
		/* translators: %s: Default Update PHP page URL. */
		__( 'This resource is provided by your web host, and is specific to your site. For more information, <a href="%s" target="_blank">see the official WordPress documentation</a>.' ),
		esc_url( $default_url )
	);

	return $annotation;
}

Changelog

Version Description
5.2.0 Introduced.