Skip to content

Commit

Permalink
Moved workaround for bbPress frontend profile edit screen crash to tw…
Browse files Browse the repository at this point in the history
…o-factor-compat class;

Also changed function check from bbp_is_user_home_edit() to bbp_is_single_user_edit() as this is more generally used
  • Loading branch information
Zed committed Dec 23, 2021
1 parent 1f486c5 commit 98f8893
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
20 changes: 20 additions & 0 deletions class-two-factor-compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ public function init() {
* @see https://wordpress.org/plugins/jetpack/
*/
add_filter( 'two_factor_rememberme', array( $this, 'jetpack_rememberme' ) );

/**
* bbPress
*
* Workaround for profile page breakage
* @see https://github.com/WordPress/two-factor/issues/175
*/
add_action( 'wp', array( $this, 'bbpress_remove_twofactor' ) );
}

/**
Expand Down Expand Up @@ -52,4 +60,16 @@ public function jetpack_rememberme( $rememberme ) {
public function jetpack_is_sso_active() {
return ( method_exists( 'Jetpack', 'is_module_active' ) && Jetpack::is_module_active( 'sso' ) );
}

/**
* Helper function to apply bbPress workaround at the right time.
*
* @return void
*/
public function bbpress_remove_twofactor() {
if ( function_exists('bbp_is_single_user_edit') && bbp_is_single_user_edit() ) {
remove_action( 'show_user_profile', array( 'Two_Factor_Core', 'user_two_factor_options' ) );
remove_action( 'edit_user_profile', array( 'Two_Factor_Core', 'user_two_factor_options' ) );
}
}
}
6 changes: 1 addition & 5 deletions class-two-factor-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -932,11 +932,7 @@ public static function manage_users_custom_column( $output, $column_name, $user_
* @param WP_User $user WP_User object of the logged-in user.
*/
public static function user_two_factor_options( $user ) {

/* workaround for two factor options crashing bbpress' profile page */
if ( function_exists('bbp_is_user_home_edit') && bbp_is_user_home_edit() ) return;
/* end workaround */


wp_enqueue_style( 'user-edit-2fa', plugins_url( 'user-edit.css', __FILE__ ), array(), TWO_FACTOR_VERSION );

$enabled_providers = array_keys( self::get_available_providers_for_user( $user ) );
Expand Down

0 comments on commit 98f8893

Please sign in to comment.