PluginProbe ʕ •ᴥ•ʔ
Hostinger Reach – AI-Powered Email Marketing for WordPress / 1.5.9
Hostinger Reach – AI-Powered Email Marketing for WordPress v1.5.9
1.6.0 1.5.9 1.5.8 1.5.7 1.5.6 1.5.5 1.5.4 1.5.3 1.5.2 1.5.1 1.5.0 1.4.12 1.4.11 1.4.10 1.4.9 1.4.8 1.4.7 trunk 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6
hostinger-reach / src / Integrations / Brave / BraveIntegration.php
hostinger-reach / src / Integrations / Brave Last commit date
BraveIntegration.php 5 months ago
BraveIntegration.php
86 lines
1 <?php
2
3 namespace Hostinger\Reach\Integrations\Brave;
4
5 use Hostinger\Reach\Dto\PluginData;
6 use Hostinger\Reach\Integrations\Integration;
7 use Hostinger\Reach\Integrations\IntegrationInterface;
8
9 if ( ! DEFINED( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 class BraveIntegration extends Integration implements IntegrationInterface {
14
15 public const INTEGRATION_NAME = 'brave-popup-builder';
16
17 public function get_post_type(): array {
18 return array( 'popup' );
19 }
20
21 public static function get_name(): string {
22 return self::INTEGRATION_NAME;
23 }
24
25 public function get_plugin_data(): PluginData {
26 return PluginData::from_array(
27 array(
28 'id' => self::INTEGRATION_NAME,
29 'title' => __( 'Brave Popup Builder', 'hostinger-reach' ),
30 'folder' => 'brave-popup-builder',
31 'file' => 'index.php',
32 'admin_url' => 'admin.php?page=bravepop-submissions',
33 'add_form_url' => 'admin.php?page=bravepop',
34 'edit_url' => 'admin.php?page=bravepop&id={post_id}',
35 'url' => 'https://wordpress.org/plugins/brave-popup-builder/',
36 'download_url' => 'https://downloads.wordpress.org/plugin/brave-popup-builder.zip',
37 'icon' => 'https://ps.w.org/brave-popup-builder/assets/icon-256x256.gif',
38 'is_view_form_hidden' => true,
39 'can_toggle_forms' => true,
40 )
41 );
42 }
43
44 public function active_integration_hooks(): void {
45 add_action( 'bravepop_user_submitted_form', array( $this, 'handle_form_submission' ), 10, 2 );
46 }
47
48 public function handle_form_submission( string $popup_id, array $form_settings ): void {
49 if ( ! $this->is_form_enabled( $popup_id ) ) {
50 return;
51 }
52
53 $post = get_post( $popup_id );
54 $email = $this->find_email( $form_settings );
55 if ( $email ) {
56 do_action(
57 'hostinger_reach_submit',
58 array(
59 'group' => $post ? $post->post_title : self::INTEGRATION_NAME,
60 'email' => $email,
61 'metadata' => array(
62 'plugin' => self::INTEGRATION_NAME,
63 'form_id' => $popup_id,
64 ),
65 )
66 );
67 }
68 }
69
70 private function find_email( array $form_settings ): string {
71 if ( ! isset( $form_settings['fields'] ) ) {
72 return '';
73 }
74
75 foreach ( $form_settings['fields'] as $field ) {
76 $value = $field?->value ?? '';
77 $sanitized_value = sanitize_email( $value );
78 if ( filter_var( $sanitized_value, FILTER_VALIDATE_EMAIL ) ) {
79 return $value;
80 }
81 }
82
83 return '';
84 }
85 }
86