钩子文档

register

💡 云策文档标注

概述

本文档介绍了 WordPress 中的 'register' 钩子,用于过滤注册或管理页面的 HTML 链接。该钩子根据用户登录状态决定链接目标:已登录用户跳转至管理页面,未登录用户跳转至注册页面(如果启用)。

关键要点

  • 'register' 钩子过滤注册或管理页面的 HTML 链接,参数为 $link(链接的 HTML 代码)。
  • 用户状态决定链接行为:已登录用户导向管理页面,未登录用户导向注册页面(如果启用)。
  • 该钩子通过 apply_filters('register', $link) 调用,常用于自定义链接目标。
  • 相关函数 wp_register() 用于显示注册或管理链接。
  • 自 WordPress 1.5.0 版本引入。

代码示例

add_filter( 'register', 'my_register_link' );

function my_register_link( $link ) {
    return 'http://exampledomain.com/my_register_page/';
}

📄 原文内容

Filters the HTML link to the Registration or Admin page.

Description

Users are sent to the admin page if logged-in, or the registration page if enabled and logged-out.

Parameters

$linkstring
The HTML code for the link to the Registration or Admin page.

More Information

The hook filters the HTML link to the Registration or Admin page. Users are sent to the admin page if logged-in, or the registration page if enabled and logged-out.

Source

$link = apply_filters( 'register', $link );

Changelog

Version Description
1.5.0 Introduced.

User Contributed Notes