PluginProbe
Button Generator – Easily Create Custom Buttons with Icons and Analytics / 3.0
Button Generator – Easily Create Custom Buttons with Icons and Analytics v3.0
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.0, at classes/Admin/SupportForm.php

211 lines 7.6 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>🔑</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 = esc_attr__( '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
116 </div>
117
118 <?php wp_nonce_field( WOWP_Plugin::PREFIX . '_nonce_action', WOWP_Plugin::PREFIX . '_nonce_name' ); ?>
119 </fieldset>
120
121
122 </form>
123
124 <?php
125
126
127 }
128
129 private static function send(): void {
130 if ( ! self::verify() ) {
131
132 return;
133 }
134
135
136 $error = self::error();
137 if ( ! empty( $error ) ) {
138 echo '<p class="notice notice-error">' . esc_html( $error ) . '</p>';
139
140 return;
141 }
142
143 $support = $_POST['support'];
144
145 $headers = array(
146 'From: ' . esc_attr( $support['name'] ) . ' <' . sanitize_email( $support['email'] ) . '>',
147 'content-type: text/html',
148 );
149
150
151 $message_mail = '<html>
152 <head></head>
153 <body>
154 <table>
155 <tr>
156 <td><strong>License Key:</strong></td>
157 <td>' . esc_attr( $support['license'] ) . '</td>
158 </tr>
159 <tr>
160 <td><strong>Plugin:</strong></td>
161 <td>' . esc_attr( $support['plugin'] ) . '</td>
162 </tr>
163 <tr>
164 <td><strong>Website:</strong></td>
165 <td><a href="' . esc_url( $support['link'] ) . '" target="_blank">' . esc_url( $support['link'] ) . '</a></td>
166 </tr>
167 </table>
168 <p/>
169 ' . nl2br( wp_kses_post( $support['message'] ) ) . '
170 </body>
171 </html>';
172 $type = sanitize_text_field( $support['type'] );
173 $to_mail = WOWP_Plugin::info( 'email' );
174 $send = wp_mail( $to_mail, 'August749 / Support Ticket: ' . $type, $message_mail, $headers );
175
176 if ( $send ) {
177 $text = __( 'Your message has been sent to the support team.', 'button-generation' );
178 echo '<p class="notice notice-success">' . esc_html( $text ) . '</p>';
179 } else {
180 $text = __( 'Sorry, but message did not send. Please, contact us via support page.', 'button-generation' );
181 echo '<p class="notice notice-error">' . esc_html( $text ) . '</p>';
182 }
183
184 }
185
186 private static function error(): ?string {
187 if ( ! self::verify() ) {
188 return '';
189 }
190 $support = $_POST['support'];
191 $fields = [ 'name', 'email', 'link', 'type', 'plugin', 'license', 'message' ];
192
193 foreach ( $fields as $field ) {
194 if ( empty( $support[ $field ] ) ) {
195 return __( 'Please fill in all the form fields below.', 'button-generation' );
196 }
197 }
198
199 return '';
200 }
201
202 private static function verify(): bool {
203 $support = $_POST['support'] ?? [];
204 $nonce_name = WOWP_Plugin::PREFIX . '_nonce_name';
205 $nonce_action = WOWP_Plugin::PREFIX . '_nonce_action';
206
207 return ! empty( $support ) && wp_verify_nonce( $_POST[ $nonce_name ], $nonce_action );
208 }
209
210 }
211