PluginProbe
Bubble Menu – Floating Button Menu with Sticky Navigation / trunk
Bubble Menu – Floating Button Menu with Sticky Navigation vtrunk
trunk 1.3 2.0 2.2 2.2.1 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1 3.1.1 4.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.1 4.1.1
bubble-menu / classes / Admin / SupportForm.php

SupportForm.php in Bubble Menu – Floating Button Menu with Sticky Navigation trunk, at classes/Admin/SupportForm.php

191 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 namespace BubbleMenu\Admin;
4
5 defined( 'ABSPATH' ) || exit;
6
7 use BubbleMenu\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', 'bubble-menu' ); ?>
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', 'bubble-menu' ); ?></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', 'bubble-menu' ); ?></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', 'bubble-menu' ); ?></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', 'bubble-menu' ); ?></div>
59 <label class="wpie-field__label">
60 <select name="support[type]" id="support-type">
61 <option value="Issue"><?php esc_html_e( 'Issue', 'bubble-menu' ); ?></option>
62 <option value="Idea"><?php esc_html_e( 'Idea', 'bubble-menu' ); ?></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', 'bubble-menu' ); ?></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', 'bubble-menu' ); ?></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', 'bubble-menu' );
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', 'bubble-menu' ), '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 = isset( $_POST['support']['name'] ) ? sanitize_text_field( wp_unslash( $_POST['support']['name'] ) ) : '';
129 $email = isset( $_POST['support']['email'] ) ? sanitize_email( wp_unslash( $_POST['support']['email'] ) ) : '';
130 $license = isset( $_POST['support']['license'] ) ? sanitize_text_field( wp_unslash( $_POST['support']['license'] ) ) : '';
131 $plugin = isset( $_POST['support']['plugin'] ) ? sanitize_text_field( wp_unslash( $_POST['support']['plugin'] ) ) : '';
132 $link = isset( $_POST['support']['link'] ) ? sanitize_url( wp_unslash( $_POST['support']['link'] ) ) : '';
133 $message = isset( $_POST['support']['message'] ) ? wp_kses_post( wp_unslash( $_POST['support']['message'] ) ) : '';
134 $type = isset( $_POST['support']['type'] ) ? sanitize_text_field( wp_unslash( $_POST['support']['type'] ) ) : '';
135
136 $headers = array(
137 'From: ' . esc_attr( $from ) . ' <' . esc_attr( $email ) . '>',
138 'content-type: text/html',
139 );
140
141
142 $message_mail = '<html>
143 <head></head>
144 <body>
145 <table>
146 <tr>
147 <td><strong>License Key:</strong></td>
148 <td>' . esc_attr( $license ) . '</td>
149 </tr>
150 <tr>
151 <td><strong>Plugin:</strong></td>
152 <td>' . esc_attr( $plugin ) . '</td>
153 </tr>
154 <tr>
155 <td><strong>Website:</strong></td>
156 <td><a href="' . esc_url( $link ) . '" target="_blank">' . esc_url( $link ) . '</a></td>
157 </tr>
158 </table>
159 <p/>
160 ' . nl2br( wp_kses_post( $message ) ) . '
161 </body>
162 </html>';
163 $to_mail = WOWP_Plugin::info( 'email' );
164 $send = wp_mail( $to_mail, 'Support Request: ' . $type, $message_mail, $headers );
165
166 if ( $send ) {
167 $text = __( 'Your message has been sent to the support team.', 'bubble-menu' );
168 echo '<p class="notice notice-success">' . esc_html( $text ) . '</p>';
169 } else {
170 $text = __( 'Sorry, but message did not send. Please, contact us via support page.', 'bubble-menu' );
171 echo '<p class="notice notice-error">' . esc_html( $text ) . '</p>';
172 }
173
174 }
175
176 private static function error(): ?string {
177
178 $fields = [ 'name', 'email', 'link', 'type', 'plugin', 'license', 'message' ];
179
180 foreach ( $fields as $field ) {
181 if ( empty( $_POST['support'][ $field ] ) ) {
182 return __( 'Please fill in all the form fields below.', 'bubble-menu' );
183 }
184 }
185
186 return '';
187 }
188
189
190 }
191