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