Feedback.php
78 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPStaging\Backend\Feedback; |
| 4 | |
| 5 | use WP_User; |
| 6 | |
| 7 | class Feedback |
| 8 | { |
| 9 | |
| 10 | /** |
| 11 | * Current page is plugins.php |
| 12 | * @global array $pagenow |
| 13 | * @return bool |
| 14 | */ |
| 15 | private function isPluginsPage() |
| 16 | { |
| 17 | global $pagenow; |
| 18 | return ( $pagenow === 'plugins.php' ); |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * Load feedback form |
| 23 | * |
| 24 | * @todo check if this is being used, remove otherwise. |
| 25 | */ |
| 26 | public function loadForm() |
| 27 | { |
| 28 | |
| 29 | $screen = get_current_screen(); |
| 30 | if (!is_admin() && !$this->isPluginsPage()) { |
| 31 | return; |
| 32 | } |
| 33 | |
| 34 | $current_user = wp_get_current_user(); |
| 35 | if (!($current_user instanceof WP_User)) { |
| 36 | $email = ''; |
| 37 | } else { |
| 38 | $email = trim($current_user->user_email); |
| 39 | } |
| 40 | |
| 41 | include WPSTG_PLUGIN_DIR . 'Backend/views/feedback/deactivate-feedback.php'; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * @return void |
| 46 | */ |
| 47 | public function sendMail() |
| 48 | { |
| 49 | |
| 50 | if (!empty($_POST['data'])) { |
| 51 | // phpcs:ignore |
| 52 | parse_str($_POST['data'], $form); // This is a js serialised string. It needs to be parsed first. It will be sanitised on the next lines after parsing it. |
| 53 | } |
| 54 | |
| 55 | $text = ''; |
| 56 | if (!empty($form['wpstg_disable_text'])) { |
| 57 | $text = sanitize_text_field(implode("\n\r", (array)$form['wpstg_disable_text'])); |
| 58 | } |
| 59 | |
| 60 | $headers = []; |
| 61 | |
| 62 | $from = isset($form['wpstg_disable_from']) ? sanitize_email($form['wpstg_disable_from']) : ''; |
| 63 | if ($from) { |
| 64 | $headers[] = "From: $from"; |
| 65 | $headers[] = "Reply-To: $from"; |
| 66 | } |
| 67 | |
| 68 | $subject = isset($form['wpstg_disable_reason']) ? 'WP Staging Free: ' . sanitize_text_field($form['wpstg_disable_reason']) : 'WP Staging Free: (no reason given)'; |
| 69 | |
| 70 | $success = wp_mail('feedback@wp-staging.com', $subject, $text, $headers); |
| 71 | |
| 72 | if ($success) { |
| 73 | wp_die(1); |
| 74 | } |
| 75 | wp_die(0); |
| 76 | } |
| 77 | } |
| 78 |