settings = Plugin::get_settings( 'users' ); add_filter( 'adminease_settings_fields', [ $this, 'adminease_settings_fields' ] ); if( !empty( $this->settings['password_reset_expiration'] ) ) { add_filter( 'password_reset_expiration', [ $this, 'password_reset_expiration' ] ); } } /** * Adds or modifies the settings fields for the AdminEase settings page. * * @param array $fields The existing settings fields structured by categories, with each category containing field definitions. * * @return array The modified settings fields with added or updated configurations for the password reset expiration options. */ public function adminease_settings_fields( array $fields ): array { $fields['users']['fields'][] = [ 'type' => 'switch', 'id' => 'password-reset-expiration', 'name' => 'adminease[users][password_reset_expiration]', 'value' => $this->settings['password_reset_expiration'] ?? '', 'label_class' => 'pwp-switch', 'input_class' => 'pwp-field-input toggle-field', 'label' => __( 'Password reset link expiration', 'adminease' ), 'description' => __( 'WordPress keeps a password reset link valid for 24 hours after it is requested. Shortening this limits how long a reset link sitting in an old or compromised mailbox can still be used to take over an account. Keep it at one hour or more, because slow mail delivery can otherwise invalidate the link before it reaches the user.', 'adminease' ), 'child_fields' => [ [ 'type' => 'select', 'id' => 'password-reset-expiration-time', 'name' => 'adminease[users][password_reset_expiration_time]', 'value' => $this->settings['password_reset_expiration_time'] ?? '', 'options' => [ '' => __( 'Select', 'adminease' ), /* translators: %s: number of hours the password reset link stays valid */ '3600' => sprintf( __( '%s hour', 'adminease' ), '1' ), /* translators: %s: number of hours the password reset link stays valid */ '7200' => sprintf( __( '%s hours', 'adminease' ), '2' ), /* translators: %s: number of hours the password reset link stays valid */ '21600' => sprintf( __( '%s hours', 'adminease' ), '6' ), /* translators: %s: number of hours the password reset link stays valid */ '43200' => sprintf( __( '%s hours', 'adminease' ), '12' ), /* translators: %s: number of hours the password reset link stays valid */ '86400' => sprintf( __( '%s hours (default)', 'adminease' ), '24' ), /* translators: %s: number of hours the password reset link stays valid */ '172800' => sprintf( __( '%s hours', 'adminease' ), '48' ), ], 'label_class' => 'pwp-field-label', 'input_class' => 'pwp-field-input', 'wrapper_class' => 'form-group-child', 'label' => __( 'Reset link valid for', 'adminease' ), 'field_description' => __( 'Select how long a password reset link remains usable.', 'adminease' ), 'attributes' => [ 'data-parent' => 'password-reset-expiration', ], ], ], ]; return $fields; } /** * Filters how long a password reset key remains valid. * * WordPress passes no user context to this filter, so the value cannot be varied per user or role. * * @param int $expiration The default expiration time of the password reset key in seconds. * * @return int The modified or original expiration time of the password reset key in seconds. */ public function password_reset_expiration( int $expiration ): int { $timeout = $this->settings['password_reset_expiration_time'] ?? ''; if( empty( $timeout ) ) { return $expiration; } return apply_filters( 'adminease_password_reset_expiration', (int) $timeout, $expiration ); } }