| 1 |
<?php |
| 2 |
/** |
| 3 |
* Handles interactions with BuddyPress plugin. |
| 4 |
* |
| 5 |
* @package WP_Defender\Integrations |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace WP_Defender\Integrations; |
| 9 |
|
| 10 |
if ( ! defined( 'ABSPATH' ) ) { |
| 11 |
die; |
| 12 |
} |
| 13 |
|
| 14 |
/** |
| 15 |
* Buddypress integration module. |
| 16 |
* |
| 17 |
* @since 3.3.0 |
| 18 |
*/ |
| 19 |
class Buddypress { |
| 20 |
|
| 21 |
public const REGISTER_FORM = 'buddypress_register', NEW_GROUP_FORM = 'buddypress_new group'; |
| 22 |
|
| 23 |
/** |
| 24 |
* Check if Buddypress is activated. |
| 25 |
* |
| 26 |
* @return bool |
| 27 |
*/ |
| 28 |
public function is_activated(): bool { |
| 29 |
return class_exists( 'buddypress' ); |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Get the Defender forms. |
| 34 |
* |
| 35 |
* @return array |
| 36 |
*/ |
| 37 |
public static function get_forms(): array { |
| 38 |
return array( |
| 39 |
self::REGISTER_FORM => esc_html__( 'Registration', 'defender-security' ), |
| 40 |
self::NEW_GROUP_FORM => esc_html__( 'Add new group', 'defender-security' ), |
| 41 |
); |
| 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 |
} |
| 65 |
} |
| 66 |
|