函数文档

wp_direct_php_update_button()

💡 云策文档标注

概述

wp_direct_php_update_button() 函数用于显示一个直接链接到 PHP 更新过程的按钮,仅当 wp_get_direct_php_update_url() 返回有效 URL 时才会显示。

关键要点

  • 函数显示一个“Update PHP”按钮,链接到主机提供的 PHP 更新 URL。
  • 按钮显示依赖于 wp_get_direct_php_update_url() 返回非空 URL。
  • 函数使用 esc_url() 对 URL 进行清理,并使用 __() 进行国际化翻译。
  • 在 WordPress 5.1.1 版本中引入。

代码示例

function wp_direct_php_update_button() {
	$direct_update_url = wp_get_direct_php_update_url();

	if ( empty( $direct_update_url ) ) {
		return;
	}

	echo '';
	printf(
		'%2$s %3$s',
		esc_url( $direct_update_url ),
		__( 'Update PHP' ),
		/* translators: Hidden accessibility text. */
		__( '(opens in a new tab)' )
	);
	echo '';
}

注意事项

  • 按钮仅在 wp_get_direct_php_update_url() 返回有效 URL 时显示,否则函数直接返回。
  • URL 使用 esc_url() 进行清理以确保安全性。
  • 文本使用 __() 函数进行翻译,支持国际化。
  • 此函数由 wp_dashboard_php_nag() 调用,用于在仪表板显示 PHP 更新提醒。

📄 原文内容

Displays a button directly linking to a PHP update process.

Description

This provides hosts with a way for users to be sent directly to their PHP update process.

The button is only displayed if a URL is returned by wp_get_direct_php_update_url().

Source

function wp_direct_php_update_button() {
	$direct_update_url = wp_get_direct_php_update_url();

	if ( empty( $direct_update_url ) ) {
		return;
	}

	echo '<p class="button-container">';
	printf(
		'<a class="button button-primary" href="%1$s" target="_blank">%2$s<span class="screen-reader-text"> %3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>',
		esc_url( $direct_update_url ),
		__( 'Update PHP' ),
		/* translators: Hidden accessibility text. */
		__( '(opens in a new tab)' )
	);
	echo '</p>';
}

Changelog

Version Description
5.1.1 Introduced.