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 / ContactForm7 / ContactForm7Integration.php
hostinger-reach / src / Integrations / ContactForm7 Last commit date
ContactForm7Integration.php 4 months ago
ContactForm7Integration.php
123 lines
1 <?php
2
3 namespace Hostinger\Reach\Integrations\ContactForm7;
4
5 use Hostinger\Reach\Dto\PluginData;
6 use Hostinger\Reach\Integrations\Integration;
7 use Hostinger\Reach\Integrations\IntegrationInterface;
8 use WP_Post;
9 use WPCF7_ContactForm;
10 use WPCF7_FormTag;
11 use WPCF7_Submission;
12
13 if ( ! DEFINED( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 class ContactForm7Integration extends Integration implements IntegrationInterface {
18
19 public const INTEGRATION_NAME = 'contact-form-7';
20
21 public function active_integration_hooks(): void {
22 add_action( 'wpcf7_mail_sent', array( $this, 'handle_submission' ), 10, 1 );
23 }
24
25 public function handle_submission( WPCF7_ContactForm $contact_form ): void {
26 if ( ! $this->is_form_enabled( $contact_form->id() ) ) {
27 return;
28 }
29
30 $contact_list = $contact_form->title();
31 $email = $this->get_field_data( $contact_form, array( 'basetype' => 'email' ) );
32 $name = $this->get_name_field( $contact_form );
33 if ( $email ) {
34 do_action(
35 'hostinger_reach_submit',
36 array(
37 'group' => $contact_list,
38 'email' => $email,
39 'name' => $name,
40 'metadata' => array(
41 'plugin' => self::INTEGRATION_NAME,
42 'form_id' => $contact_form->id(),
43 ),
44 )
45 );
46 }
47 }
48
49 public function get_field_data( WPCF7_ContactForm $contact_form, array $condition ): string {
50 $tag = $this->find_field( $contact_form, $condition );
51
52 if ( ! is_null( $tag ) ) {
53 $submission = WPCF7_Submission::get_instance();
54
55 return $submission->get_posted_data( $tag->name );
56 }
57
58 return '';
59 }
60
61 public function find_field( WPCF7_ContactForm $contact_form, array $condition ): ?WPCF7_FormTag {
62 $tags = $contact_form->scan_form_tags( $condition );
63 if ( ! empty( $tags ) ) {
64 return $tags[0];
65 }
66
67 return null;
68 }
69
70 public function get_name_field( WPCF7_ContactForm $contact_form ): string {
71 $tags = $contact_form->scan_form_tags( array( 'basetype' => 'text' ) );
72 $name_tag = null;
73 foreach ( $tags as $tag ) {
74 if ( str_contains( $tag->name, 'name' ) ) {
75 $name_tag = $tag;
76 break;
77 }
78 }
79
80 if ( ! is_null( $name_tag ) ) {
81 $submission = WPCF7_Submission::get_instance();
82
83 return $submission->get_posted_data( $name_tag->name );
84 }
85
86 return '';
87 }
88
89 public function get_post_type(): array {
90 return array( 'wpcf7_contact_form' );
91 }
92
93 public static function get_name(): string {
94 return self::INTEGRATION_NAME;
95 }
96
97
98 public function is_form_valid( WP_Post $post ): bool {
99 $contact_form = WPCF7_ContactForm::get_instance( $post->ID );
100 if ( is_null( $contact_form ) ) {
101 return false;
102 }
103
104 return ! is_null( $this->find_field( $contact_form, array( 'basetype' => 'email' ) ) );
105 }
106
107 public function get_plugin_data(): PluginData {
108 return PluginData::from_array(
109 array(
110 'id' => self::INTEGRATION_NAME,
111 'title' => __( 'Contact Form 7', 'hostinger-reach' ),
112 'folder' => 'contact-form-7',
113 'file' => 'wp-contact-form-7.php',
114 'admin_url' => 'admin.php?page=wpcf7',
115 'add_form_url' => 'admin.php?page=wpcf7-new',
116 'edit_url' => 'admin.php?page=wpcf7&post={form_id}&action=edit',
117 'url' => 'https://wordpress.org/plugins/contact-form-7/',
118 'download_url' => 'https://downloads.wordpress.org/plugin/contact-form-7.zip',
119 )
120 );
121 }
122 }
123