settings = Plugin::get_settings( 'users' ); add_filter( 'adminease_settings_fields', [ $this, 'adminease_settings_fields' ] ); if ( ! $this->is_available() ) { Utils::keep_hidden_settings( 'users', [ 'disable_application_passwords' ] ); return; } if ( ! empty( $this->settings['disable_application_passwords'] ) ) { add_filter( 'wp_is_application_passwords_available', '__return_false' ); } } /** * Checks if this WordPress has application passwords at all (5.6 and newer). * * @return bool True when the switch applies. */ private function is_available(): bool { return Utils::wp_at_least( '5.6' ); } /** * Adds the switch to the Users tab, unless this WordPress has no application passwords. * * @param array $fields The settings fields keyed by tab. * * @return array The modified settings fields. */ public function adminease_settings_fields( array $fields ): array { if ( ! $this->is_available() ) { return $fields; } $fields['users']['fields'][] = [ 'type' => 'switch', 'id' => 'disable-application-passwords', 'name' => 'adminease[users][disable_application_passwords]', 'value' => $this->settings['disable_application_passwords'] ?? '', 'label_class' => 'pwp-switch', 'input_class' => 'pwp-field-input', 'label' => __( 'Turn off application passwords', 'adminease' ), 'risk' => 'careful', 'breaks' => __( 'Apps that sign in with an application password stop working.', 'adminease' ), 'description' => esc_html__( 'Application passwords let apps log in to your site through the API. Most sites never use them. This turns the feature off and removes it from user profiles.', 'adminease' ) . ' ' . esc_html__( 'Warning: every existing application password stops working. The WordPress mobile app, Jetpack and other tools that log in this way will be locked out. Leave this off if you use any of them.', 'adminease' ) . '', ]; return $fields; } }