' . esc_html__( 'Two-Factor Settings', 'two-factor' ) . '

'; echo '

' . esc_html__( 'Settings not available.', 'two-factor' ) . '

'; } /** * Helper: retrieve the site-enabled providers option. * Returns null when the option has never been saved (meaning all providers are allowed). * Returns an array (possibly empty) when the admin has explicitly saved a selection. * * @since 0.16 * * @return array|null */ function two_factor_get_enabled_providers_option() { $enabled = get_option( 'two_factor_enabled_providers', null ); if ( null === $enabled ) { return null; // Never saved — allow everything. } return is_array( $enabled ) ? $enabled : array(); } /** * Filter the registered providers to only those in the site-enabled list. * This filter receives providers in core format: classname => path. * * @since 0.16 * * @param array $providers Registered providers in classname => path format. * @return array Filtered list of enabled providers. */ function two_factor_filter_enabled_providers( $providers ) { $site_enabled = two_factor_get_enabled_providers_option(); // null means the option was never saved — allow all providers. if ( null === $site_enabled ) { return $providers; } // On the settings page itself, show all providers so admins can change the selection. if ( is_admin() && isset( $_GET['page'] ) && 'two-factor-settings' === $_GET['page'] ) { return $providers; } foreach ( $providers as $key => $path ) { if ( ! in_array( $key, $site_enabled, true ) ) { unset( $providers[ $key ] ); } } return $providers; } /** * Filter enabled providers for a user (classnames array) to enforce the site-enabled list. * * @since 0.16 * * @param array $enabled Enabled provider classnames for the user. * @param int $user_id ID of the user being filtered. * @return array Filtered list of provider classnames allowed by the site. */ function two_factor_filter_enabled_providers_for_user( $enabled, $user_id ) { $site_enabled = two_factor_get_enabled_providers_option(); // null means the option was never saved — allow all. if ( null === $site_enabled ) { return $enabled; } return array_values( array_intersect( (array) $enabled, $site_enabled ) ); }