_redirect_to_about_wordpress()
概述
_redirect_to_about_wordpress() 函数用于在 WordPress 成功升级后重定向到“关于 WordPress”页面。该函数仅适用于旧版本(低于 3.4.0)的安装。
关键要点
- 函数仅在 WordPress 版本低于 3.4-RC1 时执行,否则直接返回。
- 仅当在 update-core.php 页面且操作为 do-core-upgrade 或 do-core-reinstall 时触发。
- 函数加载默认文本本地化域,显示升级成功消息,并输出重定向提示。
- 使用 show_message() 和 sprintf() 函数生成用户界面消息。
代码示例
function _redirect_to_about_wordpress( $new_version ) {
global $wp_version, $pagenow, $action;
if ( version_compare( $wp_version, '3.4-RC1', '>=' ) ) {
return;
}
if ( 'update-core.php' !== $pagenow ) {
return;
}
if ( 'do-core-upgrade' !== $action && 'do-core-reinstall' !== $action ) {
return;
}
load_default_textdomain();
show_message( __( 'WordPress updated successfully.' ) );
show_message(
'' . sprintf(
__( 'Welcome to WordPress %1$s. You will be redirected to the About WordPress screen. If not, click here.' ),
$new_version,
'about.php?updated'
) . ''
);
echo '';
}注意事项
此函数主要用于向后兼容,现代 WordPress 版本(3.4 及以上)已内置类似功能,无需手动调用。
Redirect to the About WordPress page after a successful upgrade.
Description
This function is only needed when the existing installation is older than 3.4.0.
Parameters
$new_versionstringrequired
Source
function _redirect_to_about_wordpress( $new_version ) {
global $wp_version, $pagenow, $action;
if ( version_compare( $wp_version, '3.4-RC1', '>=' ) ) {
return;
}
// Ensure we only run this on the update-core.php page. The Core_Upgrader may be used in other contexts.
if ( 'update-core.php' !== $pagenow ) {
return;
}
if ( 'do-core-upgrade' !== $action && 'do-core-reinstall' !== $action ) {
return;
}
// Load the updated default text localization domain for new strings.
load_default_textdomain();
// See do_core_upgrade().
show_message( __( 'WordPress updated successfully.' ) );
// self_admin_url() won't exist when upgrading from <= 3.0, so relative URLs are intentional.
show_message(
''
);
show_message(
''
);
echo '