PluginProbe
Hostinger Reach – AI-Powered Email Marketing for WordPress / 1.5.8
Hostinger Reach – AI-Powered Email Marketing for WordPress v1.5.8
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 All 59 releases
hostinger-reach / src / Integrations / WPFormsLite / WpFormsLiteIntegration.php
WpFormsLiteIntegration.php
86 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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