PluginProbe
Floating Button – Easily Create Sticky, Fixed & Floating Buttons / 6.0.4
Floating Button – Easily Create Sticky, Fixed & Floating Buttons v6.0.4
trunk 2.0.2 3.0 4.0 4.1.2 4.3 5.0 5.0.1 5.1 5.1.1 5.2 5.3 5.3.1 6.0 6.0.1 6.0.10 6.0.11 6.0.12 6.0.13 6.0.2 6.0.3 6.0.4 6.0.5 6.0.6 6.0.7 All 31 releases
floating-button / classes / Dashboard / SupportForm.php

SupportForm.php in Floating Button – Easily Create Sticky, Fixed & Floating Buttons 6.0.4, at classes/Dashboard/SupportForm.php

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