wp_update_php_annotation()
云策文档标注
概述
wp_update_php_annotation() 函数用于在 Web 主机修改了“更新 PHP”页面 URL 时,输出默认的注释信息。它通常与 wp_get_update_php_url() 配合使用,以确保注释显示的一致性。
关键要点
- 函数用途:输出 Web 主机修改“更新 PHP”页面 URL 的默认注释。
- 参数说明:$before(字符串,必需,默认空)用于指定注释前输出的标记;$after(字符串,必需,默认空)用于指定注释后输出的标记;$display(布尔值,可选,默认 true)控制是直接输出还是返回标记。
- 返回值:如果 $display 为 false,返回字符串;否则无返回值(void)。
- 相关函数:与 wp_get_update_php_annotation() 关联,后者返回注释字符串。
- 使用场景:在多个 WordPress 核心函数和类中调用,如 wp_dashboard_php_nag()、WP_Customize_Theme_Control 等。
- 版本历史:在 WordPress 5.1.0 中引入,5.2.0 添加 $before 和 $after 参数,6.4.0 添加 $display 参数。
代码示例
function wp_update_php_annotation( $before = '', $after = '', $display = true ) {
$annotation = wp_get_update_php_annotation();
if ( $annotation ) {
if ( $display ) {
echo $before . $annotation . $after;
} else {
return $before . $annotation . $after;
}
}
}
原文内容
Prints the default annotation for the web host altering the “Update PHP” page URL.
Description
This function is to be used after wp_get_update_php_url() to display a consistent annotation if the web host has altered the default “Update PHP” page URL.
Parameters
$beforestringrequired-
Markup to output before the annotation. Default
<p class="description">. $afterstringrequired-
Markup to output after the annotation. Default
</p>. $displaybooloptional-
Whether to echo or return the markup. Default
truefor echo.Default:
true
Source
function wp_update_php_annotation( $before = '<p class="description">', $after = '</p>', $display = true ) {
$annotation = wp_get_update_php_annotation();
if ( $annotation ) {
if ( $display ) {
echo $before . $annotation . $after;
} else {
return $before . $annotation . $after;
}
}
}