| @@ -39,5 +39,27 @@ | ||
| 39 | 39 | self::REGISTER_FORM => esc_html__( 'Registration', 'defender-security' ), |
| 40 | 40 | self::NEW_GROUP_FORM => esc_html__( 'Add new group', 'defender-security' ), |
| 41 | 41 | ); |
| 42 | 42 | } |
| 43 | + | |
| 44 | + /** | |
| 45 | + * Detects if the request is coming from a BuddyPress login/registration context. | |
| 46 | + * | |
| 47 | + * @return bool | |
| 48 | + */ | |
| 49 | + public function is_login_context(): bool { | |
| 50 | + if ( ! $this->is_activated() ) { | |
| 51 | + return false; | |
| 52 | + } | |
| 53 | + | |
| 54 | + // Check if this is a POST request with form data. | |
| 55 | + $post_data = defender_get_data_from_request( null, 'p' ); | |
| 56 | + if ( 0 === count( $post_data ) ) { | |
| 57 | + return false; | |
| 58 | + } | |
| 59 | + | |
| 60 | + // Check referer against BuddyPress root URL. | |
| 61 | + $referer = wp_get_referer(); | |
| 62 | + $redirect_to = defender_get_data_from_request( 'redirect_to', 'p' ); | |
| 63 | + return $referer === $redirect_to; | |
| 64 | + } | |
| 43 | 65 | } |