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 / ReachFormIntegration.php
hostinger-reach / src / Integrations Last commit date
Brave 5 months ago ContactForm7 4 months ago Elementor 2 months ago Forminator 2 months ago NinjaForms 5 months ago OptInMonster 5 months ago Reach 2 months ago SureForms 5 months ago ThriveLeads 5 months ago WPFormsLite 5 months ago WSForms 8 months ago WooCommerce 4 months ago ContactForm7Integration.php 10 months ago ImportManager.php 5 months ago Integration.php 5 months ago IntegrationInterface.php 9 months ago IntegrationWithForms.php 9 months ago PluginManager.php 9 months ago ReachFormIntegration.php 9 months ago WpFormsLiteIntegration.php 10 months ago
ReachFormIntegration.php
124 lines
1 <?php
2
3 namespace Hostinger\Reach\Integrations;
4
5 use Hostinger\Reach\Functions;
6 use Hostinger\Reach\Repositories\ContactListRepository;
7 use Hostinger\Reach\Repositories\FormRepository;
8 use WP_Post;
9
10 if ( ! DEFINED( 'ABSPATH' ) ) {
11 exit;
12 }
13
14 class ReachFormIntegration extends IntegrationWithForms implements IntegrationInterface {
15
16 public const INTEGRATION_NAME = 'hostinger-reach';
17
18 protected ContactListRepository $contact_list_repository;
19 protected Functions $functions;
20
21 public function __construct( FormRepository $form_repository, ContactListRepository $contact_list_repository, Functions $functions ) {
22 parent::__construct( $form_repository );
23 $this->contact_list_repository = $contact_list_repository;
24 $this->functions = $functions;
25 }
26
27 public function init(): void {
28 parent::init();
29 $this->init_default_forms();
30 add_action( 'transition_post_status', array( $this, 'handle_transition_post_status' ), 10, 3 );
31 add_action( 'hostinger_reach_contact_submitted', array( $this, 'handle_submission' ) );
32 }
33
34 public function init_default_forms(): void {
35 $form_ids = apply_filters( 'hostinger_reach_default_forms', array() );
36
37 foreach ( $form_ids as $form_id ) {
38 if ( ! $this->form_repository->exists( $form_id ) ) {
39 $this->form_repository->insert(
40 array(
41 'form_id' => $form_id,
42 )
43 );
44 }
45 }
46 }
47
48 public function handle_transition_post_status( string $new_status, string $old_status, WP_Post $post ): void {
49 if ( $new_status === 'publish' ) {
50 $this->set_forms( $post );
51 $this->maybe_unset_forms( $post );
52 } elseif ( $old_status === 'publish' ) {
53 $this->unset_all_forms( $post );
54 }
55 }
56
57 public function handle_submission( array $data ): void {
58 $this->form_repository->submit( $data );
59 }
60
61 public function get_plugin_data( array $plugin_data ): array {
62 $plugin_data[ self::INTEGRATION_NAME ] = array(
63 'is_active' => true,
64 'is_plugin_active' => true,
65 'title' => __( 'Hostinger Reach', 'hostinger-reach' ),
66 'admin_url' => 'admin.php?page=hostinger-reach',
67 'add_form_url' => 'post-new.php?post_type=page&hostinger_reach_add_block=1',
68 'edit_url' => 'post.php?post={post_id}&action=edit',
69 'url' => 'https://wordpress.org/plugins/hostinger-reach',
70 'is_view_form_hidden' => false,
71 'can_toggle_forms' => false,
72 );
73
74 return $plugin_data;
75 }
76
77 public static function get_name(): string {
78 return self::INTEGRATION_NAME;
79 }
80
81 public function get_form_ids( WP_Post $post ): array {
82 $blocks = $this->functions->get_reach_subscription_blocks( $post->ID );
83 $current_form_ids = array();
84
85 foreach ( $blocks as $block ) {
86 if ( empty( $block['formId'] ) ) {
87 continue;
88 }
89 $current_form_ids[] = $block['formId'];
90 }
91
92 return $current_form_ids;
93 }
94
95 private function set_contact_list( string $name ): array {
96 if ( ! $this->contact_list_repository->exists( $name ) ) {
97 $this->contact_list_repository->insert( array( 'name' => $name ) );
98 }
99
100 return $this->contact_list_repository->get( $name );
101 }
102
103 private function set_forms( WP_Post $post ): void {
104 $blocks = $this->functions->get_reach_subscription_blocks( $post->ID );
105 foreach ( $blocks as $block ) {
106 if ( empty( $block['formId'] ) ) {
107 continue;
108 }
109 $contact_list = $this->set_contact_list( $block['contactList'] ?? HOSTINGER_REACH_DEFAULT_CONTACT_LIST );
110 $form = array(
111 'form_id' => $block['formId'],
112 'contact_list_id' => $contact_list['id'],
113 'type' => self::INTEGRATION_NAME,
114 );
115
116 if ( $this->form_repository->exists( $block['formId'] ) ) {
117 $this->form_repository->update( $form );
118 } else {
119 $this->form_repository->insert( array_merge( $form, array( 'post_id' => $post->ID ) ) );
120 }
121 }
122 }
123 }
124