PluginProbe
Button Generator – Easily Create Custom Buttons with Icons and Analytics / 3.2.2
Button Generator – Easily Create Custom Buttons with Icons and Analytics v3.2.2
trunk 1.1.1 2.0 2.1 2.2 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 3.0 3.0.1 3.0.2 3.0.3 3.1 3.1.1 3.1.2 3.1.3 3.2 3.2.1 3.2.2 3.2.3 All 28 releases
button-generation / classes / Admin / SupportForm.php

SupportForm.php in Button Generator – Easily Create Custom Buttons with Icons and Analytics 3.2.2, at classes/Admin/SupportForm.php

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