PluginProbe
Float menu – awesome floating side menu / 6.1.4
Float menu – awesome floating side menu v6.1.4
7.2.5 trunk 2.1 2.2 3.0.1 3.1 3.2.2 3.3.1 3.5 3.5.1 3.5.2 3.5.3. 3.5.4 4.0 4.1 4.1.1 4.2 4.3 4.3.1 4.3.2 5.0 5.0.1 5.0.2 5.0.3 5.1 All 57 releases
float-menu / classes / Admin / SupportForm.php

SupportForm.php in Float menu – awesome floating side menu 6.1.4, at classes/Admin/SupportForm.php

203 lines 7.8 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 FloatMenuLite\Admin;
16
17 defined( 'ABSPATH' ) || exit;
18
19 use FloatMenuLite\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', 'float-menu' ); ?>
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', 'float-menu' ); ?></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', 'float-menu' ); ?></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', 'float-menu' ); ?></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', 'float-menu' ); ?></div>
71 <label class="wpie-field__label">
72 <select name="support[type]" id="support-type">
73 <option value="Issue"><?php esc_html_e( 'Issue', 'float-menu' ); ?></option>
74 <option value="Idea"><?php esc_html_e( 'Idea', 'float-menu' ); ?></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', 'float-menu' ); ?></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', 'float-menu' ); ?></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', 'float-menu' );
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', 'float-menu' ), '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 $from = isset( $_POST['support']['name'] ) ? sanitize_text_field( wp_unslash( $_POST['support']['name'] ) ) : '';
141 $email = isset( $_POST['support']['email'] ) ? sanitize_email( wp_unslash( $_POST['support']['email'] ) ) : '';
142 $license = isset( $_POST['support']['license'] ) ? sanitize_text_field( wp_unslash( $_POST['support']['license'] ) ) : '';
143 $plugin = isset( $_POST['support']['plugin'] ) ? sanitize_text_field( wp_unslash( $_POST['support']['plugin'] ) ) : '';
144 $link = isset( $_POST['support']['link'] ) ? sanitize_url( wp_unslash( $_POST['support']['link'] ) ) : '';
145 $message = isset( $_POST['support']['message'] ) ? wp_kses_post( wp_unslash( $_POST['support']['message'] ) ) : '';
146 $type = isset( $_POST['support']['type'] ) ? sanitize_text_field( wp_unslash( $_POST['support']['type'] ) ) : '';
147
148 $headers = array(
149 'From: ' . esc_attr( $from ) . ' <' . esc_attr( $email ) . '>',
150 'content-type: text/html',
151 );
152
153
154 $message_mail = '<html>
155 <head></head>
156 <body>
157 <table>
158 <tr>
159 <td><strong>License Key:</strong></td>
160 <td>' . esc_attr( $license ) . '</td>
161 </tr>
162 <tr>
163 <td><strong>Plugin:</strong></td>
164 <td>' . esc_attr( $plugin ) . '</td>
165 </tr>
166 <tr>
167 <td><strong>Website:</strong></td>
168 <td><a href="' . esc_url( $link ) . '" target="_blank">' . esc_url( $link ) . '</a></td>
169 </tr>
170 </table>
171 <p/>
172 ' . nl2br( wp_kses_post( $message ) ) . '
173 </body>
174 </html>';
175 $to_mail = WOWP_Plugin::info( 'email' );
176 $send = wp_mail( $to_mail, 'Support Request: ' . $type, $message_mail, $headers );
177
178 if ( $send ) {
179 $text = __( 'Your message has been sent to the support team.', 'float-menu' );
180 echo '<p class="notice notice-success">' . esc_html( $text ) . '</p>';
181 } else {
182 $text = __( 'Sorry, but message did not send. Please, contact us via support page.', 'float-menu' );
183 echo '<p class="notice notice-error">' . esc_html( $text ) . '</p>';
184 }
185
186 }
187
188 private static function error(): ?string {
189
190 $fields = [ 'name', 'email', 'link', 'type', 'plugin', 'license', 'message' ];
191
192 foreach ( $fields as $field ) {
193 if ( empty( $_POST['support'][ $field ] ) ) {
194 return __( 'Please fill in all the form fields below.', 'float-menu' );
195 }
196 }
197
198 return '';
199 }
200
201
202 }
203