wp_is_password_reset_allowed_for_user( int|WP_User $user ): bool|WP_Error

Checks if password reset is allowed for a specific user.

Parameters

$userint|WP_Userrequired
The user to check.

Return

bool|WP_Error True if allowed, false or WP_Error otherwise.

Source

/*
 * Create a meta key that incorporates the blog prefix so that each site
 * on a multisite can have distinct user preferences.
 */
global $wpdb;
$meta_key = $wpdb->get_blog_prefix() . 'persisted_preferences';

register_meta(
	'user',
	$meta_key,
	array(
		'type'         => 'object',
		'single'       => true,
		'show_in_rest' => array(
			'name'   => 'persisted_preferences',
			'type'   => 'object',
			'schema' => array(
				'type'                 => 'object',
				'context'              => array( 'edit' ),
				'properties'           => array(
					'_modified' => array(
						'description' => __( 'The date and time the preferences were updated.' ),
						'type'        => 'string',

Changelog

VersionDescription
6.3.0Introduced.

User Contributed Notes

  1. Skip to note 2 content

    You can prevent specific user roles from reseting passwords using this filter like below

    add_filter( 'allow_password_reset', 'wpdocs_disallow_password_reset' );
    
    function wpdocs_disallow_password_reset( $allow, $user_id ) {
    	$user = get_userdata( $user_id );
    	
    	if ( in_array( 'author', (array) $user->roles ) ) {
    		return false;
    	} 
    
    	return $allow;
    }

You must log in before being able to contribute a note or feedback.