public function run( $arguments ) { $itsec_two_factor = new ITSEC_Two_Factor(); $two_factor_users = array(); $users = get_users(); foreach ( $users as $user ) { $enabled = $itsec_two_factor->is_user_using_two_factor( $user->ID ); $override = intval( get_user_option( 'itsec_two_factor_override', $user->ID ) ) === 1 ? true : false; $override_expires = intval( get_user_option( 'itsec_two_factor_override_expires', $user->ID ) ); if ( $enabled == 'on' ) { $two_factor_users[$user->user_login] = array( 'ID' => $user->ID, 'user_login' => $user->user_login, 'override' => $override, 'override_expires' => $override_expires, ); } } return $two_factor_users; }
public static function is_user_using_two_factor( $user_id = null ) { if ( ! class_exists( 'ITSEC_Two_Factor' ) ) { require_once( 'class-itsec-two-factor.php' ); } $itsec_two_factor = new ITSEC_Two_Factor(); return $itsec_two_factor->is_user_using_two_factor( $user_id ); }
/** * Display the application password section in a users profile. * * This executes during the `show_user_security_settings` action. * * @since 0.1-dev * * @access public * @static * * @param WP_User $user WP_User object of the logged-in user. */ public static function show_user_profile( $user ) { wp_nonce_field( "user_application_passwords-{$user->ID}", '_nonce_user_application_passwords' ); $new_password = null; $new_password_name = null; $application_passwords = self::get_user_application_passwords( $user->ID ); if ( $application_passwords ) { foreach ( $application_passwords as &$application_password ) { if ( ! empty( $application_password['raw'] ) ) { $new_password = $application_password['raw']; $new_password_name = $application_password['name']; unset( $application_password['raw'] ); } } unset( $application_password ); } else { // If there are no application passwords, see if there are providers enabled. Don't show UI if there aren't any if ( ! class_exists( 'ITSEC_Two_Factor' ) ) { require_once( 'class-itsec-two-factor.php' ); } $itsec_two_factor = new ITSEC_Two_Factor(); $providers = $itsec_two_factor->get_enabled_providers_for_user( $user ); if ( empty( $providers ) ) { return; } } // If we've got a new one, update the db record to not save it there any longer. if ( $new_password ) { self::set_user_application_passwords( $user->ID, $application_passwords ); } ?> <div class="application-passwords" id="application-passwords-section"> <h3><?php esc_html_e( 'Application Passwords', 'it-l10n-ithemes-security-pro' ); ?></h3> <p><?php esc_html_e( 'Application Passwords are used to allow authentication via non-interactive systems, such as XMLRPC, where you would not otherwise be able to use your normal password due to the inability to complete the second factor of authentication.', 'it-l10n-ithemes-security-pro' ); ?></p> <div class="create-application-password"> <input type="text" size="30" name="new_application_password_name" placeholder="<?php esc_attr_e( 'New Application Password Name', 'it-l10n-ithemes-security-pro' ); ?>" /> <?php submit_button( __( 'Add New', 'it-l10n-ithemes-security-pro' ), 'secondary', 'do_new_application_password', false ); ?> </div> <?php if ( $new_password ) : ?> <p class="new-application-password"> <?php printf( esc_html_x( 'Your new password for %1$s is %2$s.', 'application, password' ), '<strong>' . esc_html( $new_password_name ) . '</strong>', '<kbd>' . esc_html( self::chunk_password( $new_password ) ) . '</kbd>' ); ?> </p> <?php endif; ?> <?php require( dirname( __FILE__ ) . '/class.application-passwords-list-table.php' ); // @todo Isn't this class already loaded in Two_Factor_Core::get_providers()? $application_passwords_list_table = new Application_Passwords_List_Table(); $application_passwords_list_table->items = $application_passwords; $application_passwords_list_table->prepare_items(); $application_passwords_list_table->display(); ?> </div> <?php }