Hooks & Filters
The Whitelabel Login plugin exposes a full set of hooks and filters for developers who need to extend login behavior, customize the access gate, modify emails, or integrate with third-party services.
Filters
wl_login_form_fields
Modify the fields displayed on the login form. Add custom fields, reorder them, or remove defaults.
add_filter( 'wl_login_form_fields', function( $fields ) {
// Add a "Company" field to the login form
$fields['company'] = array(
'label' => __( 'Company', 'my-theme' ),
'type' => 'text',
'required' => false,
'placeholder' => __( 'Your company name', 'my-theme' ),
);
return $fields;
} ); | Parameter | Type | Description |
|---|---|---|
$fields | array | Associative array of form field definitions |
wl_registration_fields
Add custom fields to the registration form. These fields are displayed on the Register tab and their values can be saved as user meta.
add_filter( 'wl_registration_fields', function( $fields ) {
$fields['phone'] = array(
'label' => __( 'Phone Number', 'my-theme' ),
'type' => 'tel',
'required' => true,
'meta_key' => 'phone_number',
);
return $fields;
} ); | Parameter | Type | Description |
|---|---|---|
$fields | array | Associative array of registration form fields |
wl_user_can_access
Override the access gate logic for any page or user. Return true to grant access, false to deny. This is the most powerful hook for implementing custom access rules.
add_filter( 'wl_user_can_access', function( $can_access, $post_id, $user ) {
// Grant access to users with a specific meta value
if ( get_user_meta( $user->ID, 'premium_member', true ) === 'yes' ) {
return true;
}
// Block access to a specific page for subscribers
if ( $post_id === 42 && in_array( 'subscriber', $user->roles ) ) {
return false;
}
return $can_access;
}, 10, 3 ); | Parameter | Type | Description |
|---|---|---|
$can_access | bool | Whether the user currently has access |
$post_id | int | The post/page ID being accessed |
$user | WP_User | The current user object |
wl_login_redirect
Customize where users are sent after a successful login. Use this for role-based redirects.
add_filter( 'wl_login_redirect', function( $redirect_url, $user ) {
if ( in_array( 'administrator', $user->roles ) ) {
return admin_url();
}
if ( in_array( 'member', $user->roles ) ) {
return home_url( '/member-dashboard/' );
}
return $redirect_url;
}, 10, 2 ); | Parameter | Type | Description |
|---|---|---|
$redirect_url | string | The URL to redirect to after login |
$user | WP_User | The user who just logged in |
wl_welcome_email_body
Modify the welcome email body sent to new users after registration.
add_filter( 'wl_welcome_email_body', function( $body, $user ) {
$body .= "\n\nNeed help getting started? Visit our FAQ: https://example.com/faq";
return $body;
}, 10, 2 ); | Parameter | Type | Description |
|---|---|---|
$body | string | The email body text |
$user | WP_User | The newly registered user |
wl_welcome_email_subject
Modify the welcome email subject line.
add_filter( 'wl_welcome_email_subject', function( $subject, $user ) {
return 'Welcome aboard, ' . $user->first_name . '!';
}, 10, 2 ); wl_login_page_title
Change the browser tab title on the login page.
add_filter( 'wl_login_page_title', function( $title ) {
return 'Member Portal — Sign In';
} ); wl_login_tab_labels
Customize the tab labels on the login page (Login, Register, Lost Password).
add_filter( 'wl_login_tab_labels', function( $labels ) {
$labels['login'] = __( 'Sign In', 'my-theme' );
$labels['register'] = __( 'Join Us', 'my-theme' );
$labels['lost_password'] = __( 'Reset Password', 'my-theme' );
return $labels;
} ); wl_public_pages
Programmatically add pages to the public pages list (pages that bypass the access gate).
add_filter( 'wl_public_pages', function( $page_ids ) {
// Always allow the "About" page
$about_page = get_page_by_path( 'about' );
if ( $about_page ) {
$page_ids[] = $about_page->ID;
}
return $page_ids;
} ); Actions
wl_before_login_form
Fires before the login form is rendered. Useful for adding notices, promotional banners, or custom HTML above the form.
add_action( 'wl_before_login_form', function() {
echo '<div class="wl-notice">';
echo '<p>Maintenance scheduled for Sunday 2am-4am.</p>';
echo '</div>';
} ); wl_after_login_form
Fires after the login form. Commonly used for social login buttons or additional links.
add_action( 'wl_after_login_form', function() {
echo '<div class="wl-social-login">';
echo '<hr><p>Or continue with:</p>';
echo '<a href="#" class="wl-btn-google">Google</a>';
echo '<a href="#" class="wl-btn-facebook">Facebook</a>';
echo '</div>';
} ); wl_user_registered
Fires after a new user registers through the plugin's registration form. Useful for CRM integrations, analytics, or sending data to external services.
add_action( 'wl_user_registered', function( $user_id, $data ) {
// Add user to CRM
wp_remote_post( 'https://api.crm.example.com/contacts', array(
'body' => array(
'email' => $data['email'],
'name' => $data['first_name'] . ' ' . $data['last_name'],
),
) );
}, 10, 2 ); | Parameter | Type | Description |
|---|---|---|
$user_id | int | The newly created user's ID |
$data | array | The registration form data submitted by the user |
wl_user_approved
Fires when an admin approves a pending user (in admin approval mode).
add_action( 'wl_user_approved', function( $user_id ) {
$user = get_user_by( 'id', $user_id );
// Send custom approval notification
wp_mail( $user->user_email, 'Account Approved!',
'Your account has been approved. You can now log in.' );
} ); wl_login_failed
Fires when a login attempt fails. Use for custom logging, security integrations, or notifications.
add_action( 'wl_login_failed', function( $username, $error ) {
error_log( sprintf( 'Failed login for "%s" from IP %s: %s',
$username, $_SERVER['REMOTE_ADDR'], $error->get_error_message() ) );
}, 10, 2 ); | Parameter | Type | Description |
|---|---|---|
$username | string | The username or email that was attempted |
$error | WP_Error | The error object with failure details |
wl_access_denied
Fires when a user is denied access to a page by the access gate. Useful for logging or analytics.
add_action( 'wl_access_denied', function( $post_id, $user_id ) {
// Track which pages are being blocked most often
$count = (int) get_post_meta( $post_id, '_wl_denied_count', true );
update_post_meta( $post_id, '_wl_denied_count', $count + 1 );
}, 10, 2 ); Quick Reference Table
| Hook Name | Type | Description |
|---|---|---|
wl_login_form_fields | Filter | Modify login form fields |
wl_registration_fields | Filter | Modify registration form fields |
wl_user_can_access | Filter | Override access gate logic |
wl_login_redirect | Filter | Customize post-login redirect URL |
wl_welcome_email_body | Filter | Modify welcome email body |
wl_welcome_email_subject | Filter | Modify welcome email subject |
wl_login_page_title | Filter | Change login page browser title |
wl_login_tab_labels | Filter | Customize tab labels |
wl_public_pages | Filter | Add pages to public access list |
wl_before_login_form | Action | Before login form render |
wl_after_login_form | Action | After login form render |
wl_user_registered | Action | After user registration |
wl_user_approved | Action | After admin approves a user |
wl_login_failed | Action | After failed login attempt |
wl_access_denied | Action | When access gate blocks a user |