PluginProbe
Counter Box – Add Countdowns, Timers & Dynamic Counters to WordPress / 2.0
Counter Box – Add Countdowns, Timers & Dynamic Counters to WordPress v2.0
2.0.14 trunk 1.0 1.2 1.2.1 1.2.2 1.2.3 1.2.4 2.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9
counter-box / classes / Admin / SupportForm.php

SupportForm.php in Counter Box – Add Countdowns, Timers & Dynamic Counters to WordPress 2.0, at classes/Admin/SupportForm.php

190 lines 7.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace CounterBox\Admin;
4
5 defined( 'ABSPATH' ) || exit;
6
7 use CounterBox\WOWP_Plugin;
8
9 class SupportForm {
10
11 public static function init(): void {
12
13 $plugin = WOWP_Plugin::info( 'name' ) . ' v.' . WOWP_Plugin::info( 'version' );
14 $license = get_option( 'wow_license_key_' . WOWP_Plugin::PREFIX, 'no' );
15
16 self::send();
17
18 ?>
19
20 <form method="post">
21
22 <fieldset class="wpie-fieldset">
23 <legend>
24 <?php esc_html_e( 'Support Form', 'counter-box' ); ?>
25 </legend>
26
27 <div class="wpie-fields is-column-2">
28 <div class="wpie-field">
29 <div class="wpie-field__title"><?php esc_html_e( 'Your Name', 'counter-box' ); ?></div>
30 <label class="wpie-field__label has-icon">
31 <span class="dashicons dashicons-admin-users"></span>
32 <input type="text" name="support[name]" id="support-name" value="">
33 </label>
34 </div>
35
36 <div class="wpie-field">
37 <div class="wpie-field__title"><?php esc_html_e( 'Contact email', 'counter-box' ); ?></div>
38 <label class="wpie-field__label has-icon">
39 <span class="dashicons dashicons-email"></span>
40 <input type="email" name="support[email]" id="support-email"
41 value="<?php echo esc_attr( get_option( 'admin_email' ) ); ?>">
42 </label>
43 </div>
44 </div>
45
46 <div class="wpie-fields is-column-2">
47
48 <div class="wpie-field">
49 <div class="wpie-field__title"><?php esc_html_e( 'Link to the issue', 'counter-box' ); ?></div>
50 <label class="wpie-field__label has-icon">
51 <span class="dashicons dashicons-admin-links"></span>
52 <input type="url" name="support[link]" id="support-link"
53 value="<?php echo esc_url( get_option( 'home' ) ); ?>">
54 </label>
55 </div>
56
57 <div class="wpie-field" data-field-box="menu_open">
58 <div class="wpie-field__title"><?php esc_html_e( 'Message type', 'counter-box' ); ?></div>
59 <label class="wpie-field__label">
60 <select name="support[type]" id="support-type">
61 <option value="Issue"><?php esc_html_e( 'Issue', 'counter-box' ); ?></option>
62 <option value="Idea"><?php esc_html_e( 'Idea', 'counter-box' ); ?></option>
63 </select>
64 </label>
65 </div>
66
67 </div>
68 <div class="wpie-fields is-column-2">
69 <div class="wpie-field">
70 <div class="wpie-field__title"><?php esc_html_e( 'Plugin', 'counter-box' ); ?></div>
71 <label class="wpie-field__label has-icon">
72 <span class="dashicons dashicons-admin-plugins"></span>
73 <input type="text" readonly name="support[plugin]" id="support-plugin"
74 value="<?php echo esc_attr( $plugin ); ?>">
75 </label>
76 </div>
77
78 <div class="wpie-field">
79 <div class="wpie-field__title"><?php esc_html_e( 'License Key', 'counter-box' ); ?></div>
80 <label class="wpie-field__label has-icon">
81 <span>🔑</span>
82 <input type="text" readonly name="support[license]" id="support-license"
83 value="<?php echo esc_attr( $license ); ?>">
84 </label>
85 </div>
86
87 </div>
88 <div class="wpie-fields is-column">
89 <?php
90 $content = esc_attr__( 'Enter Your Message', 'counter-box' );
91 $editor_id = 'support-message';
92 $settings = array(
93 'textarea_name' => 'support[message]',
94 );
95 wp_editor( $content, $editor_id, $settings ); ?>
96 </div>
97
98 <div class="wpie-fields is-column">
99
100 <div class="wpie-field">
101 <?php submit_button( __( 'Send to Support', 'counter-box' ), 'primary', 'submit', false ); ?>
102 </div>
103 </div>
104 <?php wp_nonce_field( WOWP_Plugin::PREFIX . '_nonce', WOWP_Plugin::PREFIX . '_support' ); ?>
105 </fieldset>
106
107 </form>
108
109 <?php
110
111
112 }
113
114 private static function send(): void {
115 $verify = AdminActions::verify( WOWP_Plugin::PREFIX . '_support' );
116
117 if ( ! $verify ) {
118 return;
119 }
120
121 $error = self::error();
122 if ( ! empty( $error ) ) {
123 echo '<p class="notice notice-error">' . esc_html( $error ) . '</p>';
124
125 return;
126 }
127
128 $from = sanitize_text_field( $_POST['support']['name'] );
129 $email = sanitize_email( $_POST['support']['email'] );
130 $license = sanitize_text_field( $_POST['support']['license'] );
131 $plugin = sanitize_text_field( $_POST['support']['plugin'] );
132 $link = sanitize_url( $_POST['support']['link'] );
133
134 $headers = array(
135 'From: ' . esc_attr( $from ) . ' <' . esc_attr( $email ) . '>',
136 'content-type: text/html',
137 );
138
139
140 $message_mail = '<html>
141 <head></head>
142 <body>
143 <table>
144 <tr>
145 <td><strong>License Key:</strong></td>
146 <td>' . esc_attr( $license ) . '</td>
147 </tr>
148 <tr>
149 <td><strong>Plugin:</strong></td>
150 <td>' . esc_attr( $plugin ) . '</td>
151 </tr>
152 <tr>
153 <td><strong>Website:</strong></td>
154 <td><a href="' . esc_url( $link ) . '" target="_blank">' . esc_url( $link ) . '</a></td>
155 </tr>
156 </table>
157 <p/>
158 ' . nl2br( wp_kses_post( $_POST['support']['message'] ) ) . '
159 </body>
160 </html>';
161 $type = sanitize_text_field( $_POST['support']['type'] );
162 $to_mail = WOWP_Plugin::info( 'email' );
163 $send = wp_mail( $to_mail, 'Support Request: ' . $type, $message_mail, $headers );
164
165 if ( $send ) {
166 $text = __( 'Your message has been sent to the support team.', 'counter-box' );
167 echo '<p class="notice notice-success">' . esc_html( $text ) . '</p>';
168 } else {
169 $text = __( 'Sorry, but message did not send. Please, contact us via support page.', 'counter-box' );
170 echo '<p class="notice notice-error">' . esc_html( $text ) . '</p>';
171 }
172
173 }
174
175 private static function error(): ?string {
176
177 $fields = [ 'name', 'email', 'link', 'type', 'plugin', 'license', 'message' ];
178
179 foreach ( $fields as $field ) {
180 if ( empty( $_POST['support'][ $field ] ) ) {
181 return __( 'Please fill in all the form fields below.', 'counter-box' );
182 }
183 }
184
185 return '';
186 }
187
188
189 }
190