PluginProbe
WP Coder – Insert & Manage Code Snippets / 4.1
WP Coder – Insert & Manage Code Snippets v4.1
4.5.1 1.1 2.3.1 2.3.2 2.4.1 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1 3.1.1 3.2 3.2.1 3.3 3.4 3.5 3.5.1 All 39 releases
wp-coder / classes / Dashboard / SupportForm.php

SupportForm.php in WP Coder – Insert & Manage Code Snippets 4.1, at classes/Dashboard/SupportForm.php

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