From 1f486c51ca8d95722bfcda598decfb9e8279203f Mon Sep 17 00:00:00 2001 From: Zed Date: Sat, 17 Jul 2021 17:06:47 +0300 Subject: [PATCH 1/3] add workaround for bbpress frontend profile edit screen crash --- class-two-factor-core.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/class-two-factor-core.php b/class-two-factor-core.php index d9a85af7..fb688f25 100644 --- a/class-two-factor-core.php +++ b/class-two-factor-core.php @@ -932,6 +932,11 @@ 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 ) ); From 98f8893ed5ffc893c13bba9eaa1e45f42f40ec53 Mon Sep 17 00:00:00 2001 From: Zed Date: Thu, 23 Dec 2021 22:34:15 +0200 Subject: [PATCH 2/3] Moved workaround for bbPress frontend profile edit screen crash to two-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 --- class-two-factor-compat.php | 20 ++++++++++++++++++++ class-two-factor-core.php | 6 +----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/class-two-factor-compat.php b/class-two-factor-compat.php index b578c847..1ba0b90b 100644 --- a/class-two-factor-compat.php +++ b/class-two-factor-compat.php @@ -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' ) ); } /** @@ -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' ) ); + } + } } diff --git a/class-two-factor-core.php b/class-two-factor-core.php index fb688f25..426ee6b1 100644 --- a/class-two-factor-core.php +++ b/class-two-factor-core.php @@ -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 ) ); From 54dacbec4b7478c1d63435637dd9b5b6c058b5de Mon Sep 17 00:00:00 2001 From: Cryout Creations Date: Sun, 4 Aug 2024 00:39:16 +0300 Subject: [PATCH 3/3] Update class-two-factor-core.php --- class-two-factor-core.php | 1 - 1 file changed, 1 deletion(-) diff --git a/class-two-factor-core.php b/class-two-factor-core.php index 46556ee9..c5864340 100644 --- a/class-two-factor-core.php +++ b/class-two-factor-core.php @@ -1686,7 +1686,6 @@ 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 ) { - 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 ) );