Using WordPress ‘password_reset_expiration’ PHP filter

The password_reset_expiration WordPress PHP filter allows you to modify the expiration time of password reset keys.

Usage

add_filter('password_reset_expiration', 'my_custom_expiration_time');

function my_custom_expiration_time($expiration) {
  // your custom code here
  return $expiration;
}

Parameters

  • $expiration (int) – The expiration time in seconds.

More information

See WordPress Developer Resources: password_reset_expiration

Examples

Extend the expiration time

To extend the expiration time of password reset keys to 48 hours:

add_filter('password_reset_expiration', 'extend_password_reset_expiration');

function extend_password_reset_expiration($expiration) {
  return 48 * 60 * 60; // 48 hours in seconds
}

Shorten the expiration time

To shorten the expiration time of password reset keys to 1 hour:

add_filter('password_reset_expiration', 'shorten_password_reset_expiration');

function shorten_password_reset_expiration($expiration) {
  return 60 * 60; // 1 hour in seconds
}

Make password reset keys never expire

To make password reset keys never expire:

add_filter('password_reset_expiration', '__return_zero');

Make password reset keys expire after 30 minutes

To make password reset keys expire after 30 minutes:

add_filter('password_reset_expiration', 'expire_after_thirty_minutes');

function expire_after_thirty_minutes($expiration) {
  return 30 * 60; // 30 minutes in seconds
}

Conditionally set expiration time based on user role

To set different expiration times for password reset keys based on user roles:

add_filter('password_reset_expiration', 'conditional_password_reset_expiration', 10, 2);

function conditional_password_reset_expiration($expiration, $user_data) {
  if (in_array('administrator', $user_data->roles)) {
    return 12 * 60 * 60; // 12 hours for administrators
  } else {
    return 24 * 60 * 60; // 24 hours for other users
  }
}