PluginProbe ʕ •ᴥ•ʔ
Hostinger Reach – AI-Powered Email Marketing for WordPress / 1.5.6
Hostinger Reach – AI-Powered Email Marketing for WordPress v1.5.6
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 / Blocks / SubscriptionFormBlock.php
hostinger-reach / src / Blocks Last commit date
Block.php 1 year ago SubscriptionFormBlock.php 4 months ago
SubscriptionFormBlock.php
135 lines
1 <?php
2
3 namespace Hostinger\Reach\Blocks;
4
5
6 use Hostinger\Reach\Integrations\Reach\ReachFormIntegration;
7 use Hostinger\Reach\Api\Handlers\ReachApiHandler;
8 use Hostinger\Reach\Setup\Assets;
9 use Hostinger\Reach\Functions;
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 die;
13 }
14
15 class SubscriptionFormBlock extends Block {
16 public string $name = 'subscription';
17 private ReachApiHandler $reach_api_handler;
18
19 public function __construct( Assets $assets, Functions $functions, ReachApiHandler $reach_api_handler ) {
20 parent::__construct( $assets, $functions );
21 $this->reach_api_handler = $reach_api_handler;
22 }
23
24 public function data(): array {
25 return array(
26 'endpoint' => esc_url_raw( rest_url() ) . 'hostinger-reach/v1/contact',
27 'nonce' => wp_create_nonce( 'wp_rest' ),
28 'translations' => array(
29 'thanks' => __( 'Thanks for subscribing.', 'hostinger-reach' ),
30 'error' => __( 'Something went wrong. Please try again.', 'hostinger-reach' ),
31 ),
32 );
33 }
34
35 public function autoloader(): void {
36 if ( ! is_admin() || empty( $_GET['hostinger_reach_add_block'] ) ) {
37 return;
38 }
39
40 if ( $this->functions->block_file_exists( "$this->name-autoloader.js" ) === false ) {
41 return;
42 }
43
44 $handler = parent::get_block_name() . '-autoloader';
45
46 wp_enqueue_script(
47 $handler,
48 $this->functions->get_blocks_url() . "$this->name-autoloader.js",
49 array( parent::get_block_name() . '-editor' ),
50 filemtime( $this->functions->get_block_file_name( "$this->name-autoloader.js" ) ),
51 array( 'in_footer' => true )
52 );
53 }
54
55 public function render( array $attributes ): bool|string {
56 ob_start();
57 $is_connected = $this->reach_api_handler->is_connected();
58 $this->render_block_html( $attributes, null, $is_connected );
59
60 return ob_get_clean();
61 }
62
63 public static function render_block_html( array $attributes, ?string $plugin = null, bool $is_connected = true ): void {
64 $form_id = $attributes['formId'] ?? '';
65 $show_name = $attributes['showName'] ?? false;
66 $show_surname = $attributes['showSurname'] ?? false;
67 $contact_list = $attributes['contactList'] ?? '';
68 $tags = $attributes['tags'] ?? array();
69 $layout = $attributes['layout'] ?? 'default';
70 $is_inline = $layout === 'inline';
71 $plugin = $plugin ?? ReachFormIntegration::INTEGRATION_NAME;
72 ?>
73 <div class="hostinger-reach-block-subscription-form-wrapper">
74
75 <form id="<?php echo esc_attr( $form_id ); ?>" class="hostinger-reach-block-subscription-form">
76 <input type="hidden" name="group" value="<?php echo esc_attr( $contact_list ); ?>">
77 <input type="hidden" name="id" value="<?php echo esc_attr( $form_id ); ?>">
78 <input type="hidden" name="tags" value="<?php echo esc_attr( implode( ',', $tags ) ); ?>">
79 <input type="hidden" name="metadata.plugin" value="<?php echo esc_attr( $plugin ); ?>">
80
81 <div
82 class="hostinger-reach-block-form-fields <?php echo esc_attr( $is_inline ? 'hostinger-reach-block-form-fields--inline' : '' ); ?>">
83 <div class="hostinger-reach-block-form-field">
84 <label
85 for="<?php echo esc_attr( $form_id ); ?>-email"><?php esc_html_e( 'Email', 'hostinger-reach' ); ?>
86 <span class="required">*</span></label>
87 <input type="email" id="<?php echo esc_attr( $form_id ); ?>-email" name="email" required>
88 </div>
89
90 <?php if ( $show_name ) : ?>
91 <div class="hostinger-reach-block-form-field">
92 <label
93 for="<?php echo esc_attr( $form_id ); ?>-name"><?php esc_html_e( 'Name', 'hostinger-reach' ); ?></label>
94 <input type="text" id="<?php echo esc_attr( $form_id ); ?>-name" name="name">
95 </div>
96 <?php endif; ?>
97
98 <?php if ( $show_surname ) : ?>
99 <div class="hostinger-reach-block-form-field">
100 <label
101 for="<?php echo esc_attr( $form_id ); ?>-surname"><?php esc_html_e( 'Surname', 'hostinger-reach' ); ?></label>
102 <input type="text" id="<?php echo esc_attr( $form_id ); ?>-surname" name="surname">
103 </div>
104 <?php endif; ?>
105
106 <button
107 type="submit"
108 class="hostinger-reach-block-submit has-light-color has-color-3-background-color has-text-color has-background has-link-color"
109 <?php echo $is_connected ? '' : 'disabled'; ?>>
110 <?php esc_html_e( 'Subscribe', 'hostinger-reach' ); ?>
111 </button>
112 </div>
113
114 <div class="reach-subscription-message" style="display: none;">
115 <div class="reach-subscription-message__icon" style="display: none;">
116 <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
117 <path d="M21.0455 5.95463C21.4848 6.39397 21.4848 7.10628 21.0455 7.54562L11.5076 17.0835C10.9511 17.64 10.0489 17.64 9.49237 17.0835L5.2045 12.7956C4.76517 12.3563 4.76517 11.644 5.2045 11.2046C5.64384 10.7653 6.35616 10.7653 6.7955 11.2046L10.5 14.9091L19.4545 5.95463C19.8938 5.51529 20.6062 5.51529 21.0455 5.95463Z" fill="#18181A"/>
118 </svg>
119 </div>
120 <div class="reach-subscription-message__text">
121 <?php
122 if ( ! $is_connected && current_user_can( 'manage_options' ) ) {
123 esc_html_e( 'Your site is not connected to Reach. Connect to Reach and try again.', 'hostinger-reach' );
124 } else {
125 esc_html_e( 'Subscription form is not available at the moment', 'hostinger-reach' );
126 }
127 ?>
128 </div>
129 </div>
130 </form>
131 </div>
132 <?php
133 }
134 }
135