Skip to content

Commit

Permalink
Merge branch 'trunk' into add/revalidate-modal
Browse files Browse the repository at this point in the history
  • Loading branch information
dd32 committed Oct 8, 2024
2 parents 94e5764 + 3073543 commit 4e1490f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 35 deletions.
33 changes: 16 additions & 17 deletions settings/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function render_custom_ui() : void {
$block_attributes['isOnboarding'] = true;
}

$json_attrs = json_encode( $block_attributes );
$json_attrs = json_encode( $block_attributes );

$preload_paths = [
'/wp/v2/users/' . $user_id . '?context=edit',
Expand Down Expand Up @@ -205,22 +205,21 @@ function maybe_dequeue_stylesheet() {
* Add custom CSS for print styles.
*/
function maybe_add_custom_print_css() {

// Check if the current URL matches the specific condition
if ( page_has_2fa_component() ) {
?>
<style>
@media print {
#item-header,
#headline,
footer,
.button-nav {
display: none !important;
}
}
</style>
<?php
}
if ( ! page_has_2fa_component() ) {
return;
}
?>
<style>
@media print {
#item-header,
#headline,
footer,
.button-nav {
display: none !important;
}
}
</style>
<?php
}

/**
Expand Down
52 changes: 34 additions & 18 deletions wporg-two-factor.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,6 @@ function user_requires_2fa( $user ) : bool {
return false;
}

// @codeCoverageIgnoreStart
if ( ! array_key_exists( 'phpunit_version', $GLOBALS ) ) {
// 2FA is opt-in during beta testing.
// todo Remove this once we open it to all users.
if ( ! is_2fa_beta_tester( $user ) ) {
return false;
}
}
// @codeCoverageIgnoreEnd

$required = false;

if ( is_special_user( $user->ID ) ) {
Expand All @@ -247,6 +237,16 @@ function user_requires_2fa( $user ) : bool {
$required = true;
}

// If a user ... they have to have 2FA enabled.
if (
// Is (or was) a plugin committer
$user->has_plugins ||
// Has (or had) a live theme
$user->has_themes
) {
return true;
}

return $required;
}

Expand Down Expand Up @@ -274,19 +274,17 @@ function user_should_2fa( $user ) : bool {
return true;
}

/*
// If a user ... they should have 2FA enabled.
if (
// Is (or was) a plugin committer
$user->has_plugins ||
// Has (or had) a live theme
$user->has_themes ||
$user->has_themes /* ||
// Has (or had) an elevated role on a site (WordPress.org, BuddyPress.org, bbPress.org, WordCamp.org)
$user->has_elevated_role
$user->has_elevated_role */
) {
return true;
}
*/

return false;
}
Expand Down Expand Up @@ -369,18 +367,36 @@ function block_webauthn_settings_page() {
* Get the URL of the Edit Account screen.
*
* @codeCoverageIgnore
*
* @param int|WP_User $user Optional. The user to get the URL for. Default is the current user.
* @return string
*/
function get_edit_account_url() : string {
return 'https://profiles.wordpress.org/' . ( wp_get_current_user()->user_nicename ?? 'me' ) . '/profile/edit/group/3';
function get_edit_account_url( $user = false ) : string {
if ( ! $user ) {
$user = wp_get_current_user();
} elseif ( is_numeric( $user ) ) {
$user = get_user_by( 'id', $user );
}

return 'https://profiles.wordpress.org/' . ( $user->user_nicename ?? 'me' ) . '/profile/edit/group/3/';
}

/**
* Get the URL of the onboarding screen.
*
* @codeCoverageIgnore
*
* @param int|WP_User $user Optional. The user to get the URL for. Default is the current user.
* @return string
*/
function get_onboarding_account_url() : string {
return 'https://profiles.wordpress.org/' . ( wp_get_current_user()->user_nicename ?? 'me' ) . '/profile/security';
function get_onboarding_account_url( $user = false ) : string {
if ( ! $user ) {
$user = wp_get_current_user();
} elseif ( is_numeric( $user ) ) {
$user = get_user_by( 'id', $user );
}

return 'https://profiles.wordpress.org/' . ( $user->user_nicename ?? 'me' ) . '/profile/security';
}

/**
Expand Down

0 comments on commit 4e1490f

Please sign in to comment.