PluginProbe ʕ •ᴥ•ʔ
Hostinger Reach – AI-Powered Email Marketing for WordPress / trunk
Hostinger Reach – AI-Powered Email Marketing for WordPress vtrunk
1.8.0 1.7.2 1.7.1 1.7.0 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 / WPFormsLite / WpFormsLiteIntegration.php
hostinger-reach / src / Integrations / WPFormsLite Last commit date
WpFormsLiteIntegration.php 6 months ago
WpFormsLiteIntegration.php
86 lines
1 <?php
2
3 namespace Hostinger\Reach\Integrations\WPFormsLite;
4
5 use Hostinger\Reach\Integrations\Integration;
6 use Hostinger\Reach\Integrations\IntegrationInterface;
7 use Hostinger\Reach\Dto\PluginData;
8 use WP_Post;
9
10 if ( ! DEFINED( 'ABSPATH' ) ) {
11 exit;
12 }
13
14 class WpFormsLiteIntegration extends Integration implements IntegrationInterface {
15
16 public const INTEGRATION_NAME = 'wpforms-lite';
17
18 public function get_plugin_data(): PluginData {
19 return PluginData::from_array(
20 array(
21 'id' => self::INTEGRATION_NAME,
22 'folder' => 'wpforms-lite',
23 'file' => 'wpforms.php',
24 'admin_url' => 'admin.php?page=wpforms-overview',
25 'add_form_url' => 'admin.php?page=wpforms-builder',
26 'edit_url' => 'admin.php?page=wpforms-builder&view=fields&form_id={form_id}',
27 'url' => 'https://wordpress.org/plugins/wpforms-lite/',
28 'download_url' => 'https://downloads.wordpress.org/plugin/wpforms-lite.zip',
29 'title' => __( 'WP Forms Lite', 'hostinger-reach' ),
30 )
31 );
32 }
33
34 public static function get_name(): string {
35 return self::INTEGRATION_NAME;
36 }
37
38 public function get_post_type(): array {
39 return array( 'wpforms' );
40 }
41
42 public function active_integration_hooks(): void {
43 add_action( 'wpforms_process_complete', array( $this, 'handle_submission' ), 10, 3 );
44 }
45
46 public function is_form_valid( WP_Post $post ): bool {
47 $form_fields = wpforms_get_form_fields( $post->ID, array( 'email' ) );
48
49 return ! empty( $form_fields );
50 }
51
52 public function handle_submission( array $fields, array $entry, array $form_data ): void {
53 if ( ! $this->is_form_enabled( $form_data['id'] ) ) {
54 return;
55 }
56
57 $email = $this->find_field( $fields, 'email' );
58 if ( $email ) {
59 do_action(
60 'hostinger_reach_submit',
61 array(
62 // translators: %s - form id.
63 'group' => $form_data['settings']['form_title'] ?? sprintf( __( 'WP Forms Lite %s', 'hostinger-reach' ), $form_data['id'] ),
64 'email' => $email,
65 'metadata' => array(
66 'plugin' => self::INTEGRATION_NAME,
67 'form_id' => $form_data['id'],
68 ),
69 )
70 );
71 }
72 }
73
74 private function find_field( array $fields, string $type ): string {
75 foreach ( $fields as $field ) {
76 if ( isset( $field['type'] ) && $field['type'] === $type ) {
77 if ( isset( $field['value'] ) ) {
78 return $field['value'];
79 }
80 }
81 }
82
83 return '';
84 }
85 }
86