wp_register() WordPress Function

The wp_register() function allows you to register a user for your Wordpress site. This function takes two parameters: the username and the password. The username must be unique and the password must be at least 8 characters long.

wp_register( string $before = '<li>', string $after = '</li>', bool $echo = true ) #

Display 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.


Top ↑

Parameters

$before

(string)(Optional)Text to output before the link. Default <li>.

Default value: '<li>'

$after

(string)(Optional)Text to output after the link. Default </li>.

Default value: '</li>'

$echo

(bool)(Optional)Default to echo and not return the link.

Default value: true


Top ↑

Return

(void|string) Void if $echo argument is true, registration or admin link if $echo is false.


Top ↑

More Information

The “Register” link is not offered if the Administration > Settings > General > Membership: Anyone can register box is not checked.

 


Top ↑

Source

File: wp-includes/general-template.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;
	}
}


Top ↑

Changelog

Changelog
VersionDescription
1.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More