On this page
wp_register( string $before = '<li>', string $after = '</li>', bool $echo = true ): void|string
Displays the Registration or Admin link.
Description
Display a link which allows the user to navigate to the registration page if not logged in and registration is enabled or to the dashboard if logged in.
Parameters
$beforestring Optional-
Text to output before the link. Default
<li>.Default:
'<li>' $afterstring Optional-
Text to output after the link. Default
</li>.Default:
'</li>' $echobool Optional-
Default to echo and not return the link.
Default:
true
Return
void|string Void if $echo argument is true, registration or admin link if $echo is false.
More Information
The “Register” link is not offered if the Administration > Settings > General > Membership: Anyone can register box is not checked.
Source
File: wp-includes/general-template.php. View all references
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;
}
}
Hooks
- apply_filters( 'register',
string $link ) -
Filters the HTML link to the Registration or Admin page.
Related
Uses
| Uses | Description |
|---|---|
| wp_registration_url() wp-includes/general-template.php | Returns the URL that allows the user to register on the site. |
| current_user_can() wp-includes/capabilities.php | Returns whether the current user has the specified capability. |
| __() wp-includes/l10n.php | Retrieves the translation of $text. |
| esc_url() wp-includes/formatting.php | Checks and cleans a URL. |
| is_user_logged_in() wp-includes/pluggable.php | Determines whether the current visitor is a logged in user. |
| admin_url() wp-includes/link-template.php | Retrieves the URL to the admin area for the current site. |
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
| get_option() wp-includes/option.php | Retrieves an option value based on an option name. |
Used By
| Used By | Description |
|---|---|
| WP_Widget_Meta::widget() wp-includes/widgets/class-wp-widget-meta.php | Outputs the content for the current Meta widget instance. |
Changelog
| Version | Description |
|---|---|
| 1.5.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_register