builder
2 years ago
plugin-updates
8 years ago
settings
2 years ago
views
2 years ago
class-evf-admin-addons.php
4 years ago
class-evf-admin-assets.php
2 years ago
class-evf-admin-builder.php
7 years ago
class-evf-admin-deactivation-feedback.php
3 years ago
class-evf-admin-editor.php
4 years ago
class-evf-admin-entries-table-list.php
3 years ago
class-evf-admin-entries.php
4 years ago
class-evf-admin-form-templates.php
3 years ago
class-evf-admin-forms-table-list.php
3 years ago
class-evf-admin-forms.php
3 years ago
class-evf-admin-import-export.php
4 years ago
class-evf-admin-menus.php
2 years ago
class-evf-admin-notices.php
3 years ago
class-evf-admin-settings.php
2 years ago
class-evf-admin-tools.php
4 years ago
class-evf-admin-welcome.php
2 years ago
class-evf-admin.php
2 years ago
evf-admin-functions.php
3 years ago
class-evf-admin-deactivation-feedback.php
191 lines
| 1 | <?php |
| 2 | /** |
| 3 | * EverestForms Admin Deactivation Feedback Class |
| 4 | * |
| 5 | * @package EverestForms\Admin |
| 6 | * @version 1.9.8 |
| 7 | */ |
| 8 | |
| 9 | defined( 'ABSPATH' ) || exit; |
| 10 | |
| 11 | if ( ! class_exists( 'EVF_Admin_Deactivation_Feedback', false ) ) : |
| 12 | |
| 13 | /** |
| 14 | * EVF_Admin_Deactivation_Feedback Class |
| 15 | */ |
| 16 | class EVF_Admin_Deactivation_Feedback { |
| 17 | |
| 18 | const FEEDBACK_URL = 'https://stats.wpeverest.com/wp-json/tgreporting/v1/deactivation/'; |
| 19 | |
| 20 | /** |
| 21 | * Class constructor. |
| 22 | * Attaches the necessary actions and filters for the deactivate feedback feature. |
| 23 | * Adds an action to enqueue scripts on the plugins screen. |
| 24 | * Adds an action to handle the AJAX request for sending deactivate feedback. |
| 25 | */ |
| 26 | public function __construct() { |
| 27 | add_action( |
| 28 | 'current_screen', |
| 29 | function () { |
| 30 | if ( ! $this->is_plugins_screen() ) { |
| 31 | return; |
| 32 | } |
| 33 | |
| 34 | add_action( 'admin_enqueue_scripts', array( $this, 'scripts' ) ); |
| 35 | } |
| 36 | ); |
| 37 | |
| 38 | // Ajax. |
| 39 | add_action( 'wp_ajax_evf_deactivate_feedback', array( $this, 'send' ) ); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Enqueue scripts. |
| 44 | */ |
| 45 | public function scripts() { |
| 46 | add_action( 'admin_footer', array( $this, 'feedback_html' ) ); |
| 47 | |
| 48 | $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
| 49 | |
| 50 | wp_enqueue_script( |
| 51 | 'evf-admin-deactivation-feedback', |
| 52 | evf()->plugin_url() . '/assets/js/admin/deactivation-feedback' . $suffix . '.js', |
| 53 | array( |
| 54 | 'jquery' |
| 55 | ), |
| 56 | EVF_VERSION, |
| 57 | true |
| 58 | ); |
| 59 | |
| 60 | wp_enqueue_style( |
| 61 | 'evf-admin-deactivation-feedback', |
| 62 | evf()->plugin_url() . '/assets/css/deactivation-feedback.css', |
| 63 | array(), |
| 64 | EVF_VERSION |
| 65 | ); |
| 66 | |
| 67 | wp_localize_script( |
| 68 | 'evf-admin-deactivation-feedback', |
| 69 | 'evf_plugins_params', |
| 70 | array( |
| 71 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 72 | ) |
| 73 | ); |
| 74 | |
| 75 | } |
| 76 | |
| 77 | |
| 78 | /** |
| 79 | * Deactivation Feedback HTML. |
| 80 | * |
| 81 | * @return void |
| 82 | */ |
| 83 | public function feedback_html() { |
| 84 | $deactivate_reasons = array( |
| 85 | 'feature_unavailable' => array( |
| 86 | 'title' => esc_html__( 'I didn’t find the feature I was looking for', 'everest-forms' ), |
| 87 | 'input_placeholder' => esc_html__( 'If possible, please elaborate on this', 'everest-forms' ), |
| 88 | ), |
| 89 | 'complex_to_use' => array( |
| 90 | 'title' => esc_html__( 'I found the plugin complex to use', 'everest-forms' ), |
| 91 | 'input_placeholder' => esc_html__( 'If possible, please elaborate on this', 'everest-forms' ), |
| 92 | ), |
| 93 | 'couldnt_build_the_form' => array( |
| 94 | 'title' => esc_html__( 'I couldn\'t build the form', 'everest-forms' ), |
| 95 | 'input_placeholder' => esc_html__( 'If possible, please elaborate on this', 'everest-forms' ), |
| 96 | ), |
| 97 | 'found_a_better_plugin' => array( |
| 98 | 'title' => esc_html__( 'I found better alternative', 'everest-forms' ), |
| 99 | 'input_placeholder' => esc_html__( 'If possible, please mention the alternatives', 'everest-forms' ), |
| 100 | ), |
| 101 | 'temporary_deactivation' => array( |
| 102 | 'title' => esc_html__( 'Temporary deactivation', 'everest-forms' ), |
| 103 | 'input_placeholder' => '', |
| 104 | ), |
| 105 | 'no_longer_needed' => array( |
| 106 | 'title' => esc_html__( 'I no longer need the plugin', 'everest-forms' ), |
| 107 | 'input_placeholder' => '', |
| 108 | ), |
| 109 | 'other' => array( |
| 110 | 'title' => esc_html__( 'Other', 'everest-forms' ), |
| 111 | 'input_placeholder' => esc_html__( 'If possible, please elaborate on this', 'everest-forms' ), |
| 112 | ), |
| 113 | ); |
| 114 | |
| 115 | include_once EVF_ABSPATH . 'includes/admin/views/html-deactivation-popup.php'; |
| 116 | |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Send API Request. |
| 121 | * |
| 122 | * @return void |
| 123 | */ |
| 124 | public function send() { |
| 125 | if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['_wpnonce'] ), '_evf_deactivate_feedback_nonce' ) ) { |
| 126 | wp_send_json_error(); |
| 127 | } |
| 128 | |
| 129 | $reason_text = ''; |
| 130 | $reason_slug = ''; |
| 131 | |
| 132 | if ( ! empty( $_POST['reason_slug'] ) ) { |
| 133 | $reason_slug = sanitize_text_field( wp_unslash( $_POST['reason_slug'] ) ); |
| 134 | } |
| 135 | |
| 136 | if ( ! empty( $_POST[ "reason_{$reason_slug}" ] ) ) { |
| 137 | $reason_text = sanitize_text_field( wp_unslash( $_POST[ "reason_{$reason_slug}" ] ) ); |
| 138 | } |
| 139 | |
| 140 | $deactivation_data = array( |
| 141 | 'reason_slug' => $reason_slug, |
| 142 | 'reason_text' => $reason_text, |
| 143 | 'admin_email' => get_bloginfo( 'admin_email' ), |
| 144 | 'website_url' => esc_url_raw( get_bloginfo( 'url' ) ), |
| 145 | 'base_product' => 'everest-forms/everest-forms.php', |
| 146 | ); |
| 147 | |
| 148 | $this->send_api_request( $deactivation_data ); |
| 149 | |
| 150 | wp_send_json_success(); |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * Sends an API request with deactivation data. |
| 155 | * |
| 156 | * @param array $deactivation_data Deactivation Data. |
| 157 | * @return string The response body from the API request. |
| 158 | */ |
| 159 | private function send_api_request( $deactivation_data ) { |
| 160 | $headers = array( |
| 161 | 'user-agent' => 'EverestForms/' . evf()->version . '; ' . get_bloginfo( 'url' ), |
| 162 | ); |
| 163 | |
| 164 | $response = wp_remote_post( |
| 165 | self::FEEDBACK_URL, |
| 166 | array( |
| 167 | 'method' => 'POST', |
| 168 | 'timeout' => 45, |
| 169 | 'redirection' => 5, |
| 170 | 'httpversion' => '1.0', |
| 171 | 'blocking' => true, |
| 172 | 'headers' => $headers, |
| 173 | 'body' => array( 'deactivation_data' => $deactivation_data ) |
| 174 | ) |
| 175 | ); |
| 176 | return wp_remote_retrieve_body( $response ); |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * Check if the current screen is the plugins screen and returns a boolean. |
| 181 | * |
| 182 | * @return boolean |
| 183 | */ |
| 184 | private function is_plugins_screen() { |
| 185 | return in_array( get_current_screen()->id, array( 'plugins', 'plugins-network' ), true ); |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | new EVF_Admin_Deactivation_Feedback(); |
| 190 | endif; |
| 191 |