wpmu_admin_redirect_add_updated_param()
云策文档标注
概述
wpmu_admin_redirect_add_updated_param() 是一个已弃用的 WordPress 函数,用于向 URL 添加 'updated=true' 参数。自 3.3.0 版本起,建议使用 add_query_arg() 替代。
关键要点
- 函数功能:向指定 URL 添加 'updated=true' 查询参数,用于指示更新状态。
- 弃用状态:自 WordPress 3.3.0 版本起被弃用,推荐使用 add_query_arg() 函数。
- 参数:$url(可选字符串),默认值为空,表示重定向 URL。
- 返回值:返回添加参数后的 URL 字符串。
- 内部逻辑:检查 URL 是否已包含 'updated=true',若未包含则根据 URL 是否已有查询参数(?)来添加 '?updated=true' 或 '&updated=true'。
代码示例
function wpmu_admin_redirect_add_updated_param( $url = '' ) {
_deprecated_function( __FUNCTION__, '3.3.0', 'add_query_arg()' );
if ( ! str_contains( $url, 'updated=true' ) ) {
if ( ! str_contains( $url, '?' ) )
return $url . '?updated=true';
else
return $url . '&updated;=true';
}
return $url;
}注意事项
- 此函数已弃用,新代码中应避免使用,改用 add_query_arg() 以实现更灵活的参数添加。
- 函数内部使用 _deprecated_function() 标记弃用,调用时会触发弃用通知。
- 相关函数:wpmu_admin_do_redirect() 使用此函数进行重定向。
原文内容
Adds an ‘updated=true’ argument to a URL.
Description
See also
Parameters
$urlstringoptional-
Redirect URL. Default empty.
Source
function wpmu_admin_redirect_add_updated_param( $url = '' ) {
_deprecated_function( __FUNCTION__, '3.3.0', 'add_query_arg()' );
if ( ! str_contains( $url, 'updated=true' ) ) {
if ( ! str_contains( $url, '?' ) )
return $url . '?updated=true';
else
return $url . '&updated;=true';
}
return $url;
}
Changelog
| Version | Description |
|---|---|
| 3.3.0 | Deprecated. Use add_query_arg() |
| MU (3.0.0) | Introduced. |