显示“注册”或“管理”链接。
原型
wp_register( string $before = '<li>', string $after = '</li>', bool $echo = true )
描述
显示一个链接,允许用户导航到注册页面,如果未登录并启用注册,或者如果已登录则导航到仪表板。
参数
$before
(string)
(Optional)
要在链接之前输出的文本。默认。
$after
(string)
(Optional)
链接后输出的文本。默认</ li>。
$echo
(bool)
(Optional)
默认为echo而不返回链接。
返回值
(string|void)
检索时的字符串。
源文件
路径:wp-includes/general-template.php
<?php
...
function wp_register( $before = '<li>', $after = '</li>', $echo = true ) {
if ( ! is_user_logged_in() ) {
if ( get_option('users_can_register') )
$link = $before . '<a href="' . esc_url( wp_registration_url() ) . '">' . __('Register') . '</a>' . $after;
else
$link = '';
} elseif ( current_user_can( 'read' ) ) {
$link = $before . '<a href="' . admin_url() . '">' . __('Site Admin') . '</a>' . $after;
} else {
$link = '';
}
/**
* 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.
*
* @since 1.5.0
*
* @param string $link The HTML code for the link to the Registration or Admin page.
*/
$link = apply_filters( 'register', $link );
if ( $echo ) {
echo $link;
} else {
return $link;
}
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/wp_register/