wp_registration_url()
云策文档标注
概述
wp_registration_url() 函数返回用户注册页面的 URL,基于 site_url() 构建并可通过 'register_url' 过滤器进行自定义。
关键要点
- 函数返回字符串类型的用户注册 URL,默认格式为 site_url('wp-login.php?action=register', 'login')
- 提供 'register_url' 过滤器,允许开发者修改注册 URL,使用 apply_filters() 调用
- 相关函数包括 wp_register() 用于显示注册链接,redirect_canonical() 用于重定向处理
- 自 WordPress 3.6.0 版本引入,无参数,直接调用
代码示例
// 获取注册 URL
$register_url = wp_registration_url();
// 输出注册链接
echo '<a href="' . esc_url( $register_url ) . '">Register</a>';注意事项
- 确保站点已启用用户注册功能(在设置中勾选“任何人都可以注册”),否则 URL 可能无效
- 使用 esc_url() 对输出 URL 进行转义,以增强安全性
- 可通过 add_filter() 钩子自定义 'register_url' 过滤器来修改返回的 URL
原文内容
Returns the URL that allows the user to register on the site.
Source
function wp_registration_url() {
/**
* Filters the user registration URL.
*
* @since 3.6.0
*
* @param string $register The user registration URL.
*/
return apply_filters( 'register_url', site_url( 'wp-login.php?action=register', 'login' ) );
}
Hooks
- apply_filters( ‘register_url’, string $register )
-
Filters the user registration URL.
Changelog
| Version | Description |
|---|---|
| 3.6.0 | Introduced. |
Skip to note 2 content
Codex
Sample Registration Link
<a href="<?php echo esc_url( wp_registration_url() ); ?>"></a>