Hooks, Filters & Functions
Developer reference for customizing and integrating with ProfileSwitch. Add filter code to your theme’s functions.php or a site-specific plugin. Functions can be called anywhere after the plugin has loaded.
Filters
profileswitch_max_profiles
Filter the maximum number of profiles allowed per account. The default value comes from the General settings tab (default 10).
// Allow up to 20 profiles per account
add_filter( 'profileswitch_max_profiles', function( $max ) {
return 20;
} );
// Different limits per user role
add_filter( 'profileswitch_max_profiles', function( $max ) {
if ( current_user_can( 'manage_options' ) ) {
return 50;
}
return $max;
} );
profileswitch_max_pin_attempts
Filter the number of failed PIN attempts before lockout. Default: 5.
// Allow 10 attempts before lockout
add_filter( 'profileswitch_max_pin_attempts', function( $attempts ) {
return 10;
} );
profileswitch_pin_lockout_duration
Filter the lockout duration (in seconds) after too many failed PIN attempts. Default: 60 (1 minute).
// Lock out for 5 minutes instead of 1
add_filter( 'profileswitch_pin_lockout_duration', function( $duration ) {
return 5 * MINUTE_IN_SECONDS;
} );
profileswitch_pin_session_ttl
Filter how long a PIN verification session lasts before the user needs to re-enter their PIN for protected pages. Default: 3600 (1 hour).
// Require PIN re-entry every 15 minutes
add_filter( 'profileswitch_pin_session_ttl', function( $ttl ) {
return 15 * MINUTE_IN_SECONDS;
} );
profileswitch_settings_tabs
Filter the tabs shown on the ProfileSwitch settings page. You can add, remove, or reorder tabs.
// Add a custom settings tab
add_filter( 'profileswitch_settings_tabs', function( $tabs ) {
$tabs['my-custom-tab'] = 'My Custom Tab';
return $tabs;
} );
profileswitch_pin_override_allowed
Filter whether a primary profile or manager’s PIN can override a specific profile’s PIN. Receives the target profile ID and the primary profile ID. Return false to prevent the override. Default: true.
// Prevent PIN override for a specific profile
add_filter( 'profileswitch_pin_override_allowed', function( $allowed, $target_profile_id, $primary_id ) {
if ( $target_profile_id === 42 ) {
return false;
}
return $allowed;
}, 10, 3 );
profileswitch_can_set_pin
Filter whether a specific profile is allowed to set a PIN. Return false to hide the “Set a PIN” option and block the form handler. Default: true.
// Prevent a specific profile from setting a PIN
add_filter( 'profileswitch_can_set_pin', function( $allowed, $profile_id ) {
if ( $profile_id === 42 ) {
return false;
}
return $allowed;
}, 10, 2 );
Functions
These functions are available for use in themes, plugins, and custom integrations.
Profile queries
profileswitch_get_profiles( $user_id )
Returns an array of user IDs for all profiles in the account (including the primary). Pass any profile’s user ID — it will resolve to the full set.
$profiles = profileswitch_get_profiles( get_current_user_id() ); // Returns: [1, 23, 45, 67]
profileswitch_get_primary_profile_id( $profile_id )
Returns the primary profile’s user ID for any sub-profile. If the user is already the primary (or has no linked profiles), returns their own ID.
$primary_id = profileswitch_get_primary_profile_id( $user_id ); // Returns: 1
profileswitch_is_user_primary_profile( $user_id )
Returns true if the user is a primary profile (i.e. has sub-profiles linked to them).
if ( profileswitch_is_user_primary_profile( get_current_user_id() ) ) {
// Show admin-level controls
}
profileswitch_can_user_switch_to_profile( $user_id, $profile_id )
Returns true if the given user is allowed to switch to the specified profile (i.e. they belong to the same profile set).
if ( profileswitch_can_user_switch_to_profile( $current_user, $target_profile ) ) {
profileswitch_switch_to_profile( $target_profile );
}
Profile actions
profileswitch_switch_to_profile( $profile_id )
Programmatically switch the current user to the specified profile. Logs out of the current profile and logs into the target profile. Only works if the current user belongs to the same profile set.
profileswitch_switch_to_profile( $profile_id );
profileswitch_set_primary_profile( $profile_id, $primary_profile_id )
Link a user to a primary profile. This makes $profile_id a sub-profile of $primary_profile_id.
// Link user 23 as a sub-profile of user 1
profileswitch_set_primary_profile( 23, 1 );
profileswitch_get_switcher_url()
Returns the URL of the profile switcher page. Returns an empty string if no page is configured.
$url = profileswitch_get_switcher_url(); // Returns: "https://example.com/select-profile/"
PINs & parental controls
profileswitch_is_profile_pins_enabled()
Returns true if the Profile PINs feature is enabled globally in settings.
profileswitch_profile_has_pin( $profile_id )
Returns true if the specified profile has a PIN set.
if ( profileswitch_profile_has_pin( $profile_id ) ) {
// This profile requires a PIN to access
}
profileswitch_is_parental_controls_enabled()
Returns true if the Parental Controls feature is enabled globally in settings. This does not mean a specific account has activated it — use profileswitch_user_has_parental_controls() for that.
profileswitch_user_has_parental_controls( $user_id )
Returns true if the specified user’s account has parental controls actively enabled. Works with any profile in the set — it resolves to the primary automatically.
if ( profileswitch_user_has_parental_controls( get_current_user_id() ) ) {
// This user's account has parental controls active
}
profileswitch_is_protected_page( $page_id )
Returns true if the specified page is in the protected pages list (configured in PINs & Parental Controls settings).
if ( profileswitch_is_protected_page( get_the_ID() ) ) {
// This page requires a PIN for sub-profiles
}
profileswitch_is_pin_locked_out( $user_id )
Returns true if the account is currently locked out due to too many failed PIN attempts.
if ( profileswitch_is_pin_locked_out( get_current_user_id() ) ) {
// Account is temporarily locked
}
Profile managers
profileswitch_is_profile_managers_enabled()
Returns true if the Profile Managers feature is enabled in settings.
profileswitch_is_profile_manager( $user_id )
Returns true if the user is a primary profile or a designated manager. When the Profile Managers feature is disabled, this returns the same result as profileswitch_is_user_primary_profile().
if ( profileswitch_is_profile_manager( get_current_user_id() ) ) {
// User is the primary profile or a designated manager
}
Action hooks
These action hooks fire when profile relationships change. Use them to run custom logic when profiles are linked, unlinked, deleted, or when manager status changes.
profileswitch_profile_linked
Fires when a profile is linked to a primary account.
add_action( 'profileswitch_profile_linked', function( $profile_id, $primary_id ) {
// A profile was linked to a primary account
}, 10, 2 );
profileswitch_profile_unlinked
Fires when a profile is unlinked from a primary account (becomes standalone).
add_action( 'profileswitch_profile_unlinked', function( $profile_id, $old_primary_id ) {
// A profile was unlinked and is now standalone
}, 10, 2 );
profileswitch_profile_deleted
Fires before a profile is deleted from the account management panel.
add_action( 'profileswitch_profile_deleted', function( $profile_id, $primary_id ) {
// A profile is about to be deleted
}, 10, 2 );
profileswitch_manager_added
Fires when a profile is designated as a manager.
add_action( 'profileswitch_manager_added', function( $profile_id, $primary_id ) {
// Profile was made a manager
}, 10, 2 );
profileswitch_manager_removed
Fires when a profile’s manager status is removed.
add_action( 'profileswitch_manager_removed', function( $profile_id, $primary_id ) {
// Profile is no longer a manager
}, 10, 2 );
Frontend form hooks
These action hooks fire on the frontend profile switcher pages. Use them to render custom fields and save custom data when profiles are created or edited.
profileswitch_add_profile_form_fields
Fires after the name field on the Add Profile form. Use this to render additional input fields.
add_action( 'profileswitch_add_profile_form_fields', function() {
echo '<p>Nickname:</p>';
echo '<input type="text" name="my_nickname_field">';
} );
profileswitch_edit_profile_form_fields
Fires after the name field on the Edit Profile form. Receives the profile user ID.
add_action( 'profileswitch_edit_profile_form_fields', function( $profile_id ) {
$value = get_user_meta( $profile_id, 'my_nickname', true );
echo '<p>Nickname:</p>';
echo '<input type="text" name="my_nickname_field" value="' . esc_attr( $value ) . '">';
} );
profileswitch_add_profile_save
Fires after a new profile is created (before it is linked to the primary). Use this to save data from custom fields added via profileswitch_add_profile_form_fields.
add_action( 'profileswitch_add_profile_save', function( $profile_id ) {
if ( isset( $_POST['my_nickname_field'] ) ) {
update_user_meta( $profile_id, 'my_nickname', sanitize_text_field( $_POST['my_nickname_field'] ) );
}
} );
profileswitch_edit_profile_save
Fires after an existing profile is updated. Use this to save data from custom fields added via profileswitch_edit_profile_form_fields.
add_action( 'profileswitch_edit_profile_save', function( $profile_id ) {
if ( isset( $_POST['my_nickname_field'] ) ) {
update_user_meta( $profile_id, 'my_nickname', sanitize_text_field( $_POST['my_nickname_field'] ) );
}
} );
profileswitch_manage_account_after_managers
Fires after the Managers section on the Manage Account page. Receives the primary profile user ID.
add_action( 'profileswitch_manage_account_after_managers', function( $primary_id ) {
// Add custom content to the Manage Account page
} );
profileswitch_manage_account_after_profiles
Fires after the Linked Profiles section on the Manage Account page. Receives the primary profile user ID.
add_action( 'profileswitch_manage_account_after_profiles', function( $primary_id ) {
// Add custom content to the Manage Account page
} );
Account management
profileswitch_is_account_verified( $primary_id )
Returns true if the current session has been verified for the given primary profile via the account management email verification flow. The verified session lasts 30 minutes.
profileswitch_is_plus_addressed_email( $profile_email, $primary_email )
Returns true if the profile email is a plus-addressed version of the primary email (same local part and domain, with a +suffix). Useful for determining whether a profile was auto-generated or has custom credentials.
$primary_id = profileswitch_get_primary_profile_id( $user_id );
$primary = get_userdata( $primary_id );
if ( profileswitch_is_plus_addressed_email( $user->user_email, $primary->user_email ) ) {
// This profile uses an auto-generated email
}
profileswitch_update_managers( $primary_id, $manager_ids )
Updates the list of manager profiles for the given primary account. Pass an array of user IDs. Fires profileswitch_manager_added and profileswitch_manager_removed hooks as appropriate.
// Make user 23 and 45 managers of account 1
profileswitch_update_managers( 1, array( 23, 45 ) );
