assets
5 days ago
format
5 days ago
helpers
5 days ago
class-ajax-passkeys.php
5 days ago
class-api-register.php
5 days ago
class-api-signin.php
5 days ago
class-attestation-object.php
5 days ago
class-authenticate-server.php
5 days ago
class-authenticator-data.php
5 days ago
class-byte-buffer.php
5 days ago
class-chor-decoder.php
5 days ago
class-passkeys-endpoints.php
5 days ago
class-passkeys-user-profile.php
5 days ago
class-passkeys-wizard-steps.php
5 days ago
class-passkeys.php
5 days ago
class-pending-2fa-helper.php
5 days ago
class-source-repository.php
5 days ago
class-web-authn-exception.php
5 days ago
class-web-authn.php
5 days ago
index.php
5 days ago
class-passkeys-user-profile.php
118 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Responsible for the Passkeys extension plugin settings |
| 4 | * |
| 5 | * @package wp2fa |
| 6 | * @subpackage passkeys |
| 7 | * @since 3.0.0 |
| 8 | * @copyright 2026 Melapress |
| 9 | * @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 |
| 10 | * @link https://wordpress.org/plugins/wp-2fa/ |
| 11 | */ |
| 12 | |
| 13 | declare(strict_types=1); |
| 14 | |
| 15 | namespace WP2FA\Passkeys; |
| 16 | |
| 17 | use WP2FA\Methods\Passkeys; |
| 18 | use WP2FA\Admin\Helpers\User_Helper; |
| 19 | use WP2FA\Passkeys\Source_Repository; |
| 20 | use WP2FA\Passkeys\Helpers\Authenticators_Helper; |
| 21 | use WP2FA\WP2FA; |
| 22 | |
| 23 | defined( 'ABSPATH' ) || exit; // Exit if accessed directly. |
| 24 | |
| 25 | /** |
| 26 | * Passkeys user settings class |
| 27 | */ |
| 28 | if ( ! class_exists( '\WP2FA\Passkeys\Passkeys_User_Profile' ) ) { |
| 29 | |
| 30 | /** |
| 31 | * Responsible for setting different 2FA Passkeys settings |
| 32 | * |
| 33 | * @since 3.0.0 |
| 34 | */ |
| 35 | class Passkeys_User_Profile { |
| 36 | |
| 37 | /** |
| 38 | * Initialize the Passkeys_User_Profile class |
| 39 | * |
| 40 | * @since 3.0.0 |
| 41 | */ |
| 42 | public static function init() { |
| 43 | \add_filter( WP_2FA_PREFIX . 'append_to_profile_form_content', array( __CLASS__, 'add_user_profile_form' ), 10, 2 ); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Gives the ability to add more content to the profile page. |
| 48 | * |
| 49 | * @param string $content - The parsed HTML of the form. |
| 50 | * @param \WP_User $user - The user object. |
| 51 | * |
| 52 | * @since 3.0.0 |
| 53 | */ |
| 54 | public static function add_user_profile_form( $content, \WP_User $user ) { |
| 55 | |
| 56 | if ( ! Passkeys::is_enabled( User_Helper::get_user_role( $user ) ) ) { |
| 57 | return $content; |
| 58 | } |
| 59 | |
| 60 | $public_key_credentials = Source_Repository::find_all_for_user( $user ); |
| 61 | |
| 62 | $add_button = true; |
| 63 | |
| 64 | if ( 'free' === WP2FA::get_plugin_version() && ! empty( $public_key_credentials ) && \count( $public_key_credentials ) >= 1 ) { |
| 65 | $public_key_credentials = array( reset( $public_key_credentials ) ); |
| 66 | |
| 67 | $add_button = false; |
| 68 | } |
| 69 | |
| 70 | if ( ! class_exists( 'ParagonIE_Sodium_Core_Base64_UrlSafe', false ) ) { |
| 71 | require_once ABSPATH . WPINC . '/sodium_compat/src/Core/Base64/UrlSafe.php'; |
| 72 | require_once ABSPATH . WPINC . '/sodium_compat/src/Core/Util.php'; |
| 73 | } |
| 74 | |
| 75 | // Prepare template variables. |
| 76 | $section_title = \esc_html( WP2FA::get_wp2fa_white_label_setting( 'passkeys-option-label', true ) ) . __( ' - by WP2FA', 'wp-2fa' ); |
| 77 | |
| 78 | $section_description_html = sprintf( |
| 79 | \wp_kses( |
| 80 | /* translators: %s: link to the passkeys guide. */ |
| 81 | __( 'Passkeys make login easier and safer by replacing passwords with your fingerprint, face, or device PIN, reducing password risks and speeding up authentication. %s', 'wp-2fa' ), |
| 82 | array( 'a' => array( 'href' => array(), 'target' => array(), 'rel' => array() ) ) |
| 83 | ), |
| 84 | '<a href="' . \esc_url( 'https://melapress.com/support/kb/wp-2fa-activate-use-passkeys/?#utm_source=plugin&utm_medium=wp2fa&utm_campaign=passkeys_user' ) . '" target="_blank" rel="noopener noreferrer">' . \esc_html__( 'Learn more about Passkeys.', 'wp-2fa' ) . '</a>' |
| 85 | ); |
| 86 | |
| 87 | $date_format = \get_option( 'date_format' ) ?: 'F j, Y'; |
| 88 | $time_format = \get_option( 'time_format' ) ?: 'g:iA'; |
| 89 | |
| 90 | \ob_start(); |
| 91 | include WP_2FA_PATH . 'templates' . DIRECTORY_SEPARATOR . 'passkeys' . DIRECTORY_SEPARATOR . 'user-profile-table.php'; |
| 92 | $output = \ob_get_clean(); |
| 93 | |
| 94 | return $content . $output; |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Print passkey underscore templates in the admin footer. |
| 99 | * |
| 100 | * @since 4.0.0 |
| 101 | */ |
| 102 | public static function print_passkey_templates(): void { |
| 103 | $template_dir = WP_2FA_PATH . 'templates' . DIRECTORY_SEPARATOR . 'passkeys' . DIRECTORY_SEPARATOR; |
| 104 | |
| 105 | $templates = array( |
| 106 | 'setup-modal' => $template_dir . 'setup-modal.php', |
| 107 | 'success-modal' => $template_dir . 'success-modal.php', |
| 108 | ); |
| 109 | |
| 110 | foreach ( $templates as $name => $path ) { |
| 111 | if ( \file_exists( $path ) ) { |
| 112 | include $path; |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 |