PluginProbe
Booking Calendar / 10.15.7
Booking Calendar v10.15.7
11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 10.11 10.11.2 10.11.3 All 202 releases
booking / includes / _feedback_deactivation / feedback.php

feedback.php in Booking Calendar 10.15.7, at includes/_feedback_deactivation/feedback.php

258 lines 8.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Booking Calendar Admin Deactivation Feedback Class
4 *
5 * @package Booking Calendar Admin
6 * @version 1.0.0
7 */
8
9 defined( 'ABSPATH' ) || exit;
10
11 if ( ! class_exists( 'WPBC_Admin_Deactivation_Feedback', false ) ) :
12
13 /**
14 * WPBC_Admin_Deactivation_Feedback Class
15 */
16 class WPBC_Admin_Deactivation_Feedback {
17
18 const FEEDBACK_URL = 'https://wpbookingcalendar.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_wpbc_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 $suffix = '';
50
51 wp_enqueue_script( 'wpbc-admin-deactivation-feedback',
52 wpbc_plugin_url( '/includes/_feedback_deactivation/_out/feedback.js' ),
53 array( 'jquery' ),
54 WP_BK_VERSION_NUM,
55 array( 'in_footer' => WPBC_JS_IN_FOOTER )
56 );
57 wp_localize_script( 'wpbc-admin-deactivation-feedback', 'wpbc_plugins_params', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
58
59 wp_enqueue_style( 'wpbc-admin-deactivation-feedback', trailingslashit( plugins_url( '', __FILE__ ) ) . '_out/feedback.css', array(), WP_BK_VERSION_NUM );
60 }
61
62
63 /**
64 * Deactivation Feedback HTML.
65 *
66 * @return void
67 */
68 public function feedback_html() {
69 $wpbc_deactivate_reasons = array(
70 'feature_unavailable' => array(
71 'title' => esc_html__( 'Missing important features', 'booking' ),
72 ),
73 'complex_to_use' => array(
74 'title' => esc_html__( 'I found the plugin complex to use.', 'booking' ),
75 ),
76 'temporary_deactivation' => array(
77 'title' => esc_html__( 'Temporary deactivation', 'booking' ),
78 ),
79 'found_a_better_plugin' => array(
80 'title' => esc_html__( 'I found a better alternative', 'booking' ),
81 ),
82 'no_longer_needed' => array(
83 'title' => esc_html__( 'I no longer need the plugin', 'booking' ),
84 ),
85 'setup_confusing' => array(
86 'title' => esc_html__( 'Plugin setup process is confusing', 'booking' ),
87 ),
88 'no_documentation' => array(
89 'title' => esc_html__( 'Lack of documentation or tutorials', 'booking' ),
90 ),
91 'other' => array(
92 'title' => esc_html__( 'Technical issues / Bugs', 'booking' ),
93 ),
94 );
95
96 require_once WPBC_PLUGIN_DIR . '/includes/_feedback_deactivation/feedback_view.php'; // API
97 }
98
99 /**
100 * Send API Request.
101 *
102 * @return void
103 */
104 public function send() {
105 if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['_wpnonce'] ), '_wpbc_deactivate_feedback_nonce' ) ) {
106 wp_send_json_error();
107 }
108
109 $reason_text = '---';
110 $reason_slug = '';
111
112 if ( ! empty( $_POST['reason_slug'] ) ) {
113 $reason_slug = sanitize_text_field( wp_unslash( $_POST['reason_slug'] ) );
114 }
115
116 if ( ! empty( $_POST[ "wpbc_deactivate-feedback-more-details" ] ) ) {
117 $reason_text = sanitize_textarea_field( wp_unslash( $_POST[ "wpbc_deactivate-feedback-more-details" ] ) );
118 }
119
120 $deactivation_data = array(
121 'reason_text' => $reason_text,
122 'reason_slug' => $reason_slug,
123 'admin_email' => get_bloginfo( 'admin_email' ),
124 'website_url' => esc_url_raw( get_bloginfo( 'url' ) ),
125 'base_product' => is_plugin_active( 'booking-calendar-com/booking-calendar-com.php' ) ? 'booking-calendar-com/booking-calendar-com.php' : 'booking/wpdev-booking.php',
126 );
127
128 // TODO: Make in future API request.
129 // $this->send_api_request( $deactivation_data );
130
131 wpbc_feedback_deactivation__send_email( $reason_slug, implode( " \n\n", $deactivation_data ) );
132
133 wp_send_json_success();
134 }
135
136 /**
137 * Sends an API request with deactivation data.
138 *
139 * @param array $deactivation_data Deactivation Data.
140 * @return string The response body from the API request.
141 */
142 private function send_api_request( $deactivation_data ) {
143 $headers = array(
144 'user-agent' => 'BookingCalendar/' . WP_BK_VERSION_NUM . '; ' . get_bloginfo( 'url' ),
145 );
146
147 $response = wp_remote_post(
148 self::FEEDBACK_URL,
149 array(
150 'method' => 'POST',
151 'timeout' => 45,
152 'redirection' => 5,
153 'httpversion' => '1.0',
154 'blocking' => true,
155 'headers' => $headers,
156 'body' => array( 'deactivation_data' => $deactivation_data ),
157 )
158 );
159 return wp_remote_retrieve_body( $response );
160 }
161
162 /**
163 * Check if the current screen is the plugins screen and returns a boolean.
164 *
165 * @return boolean
166 */
167 private function is_plugins_screen() {
168 return in_array( get_current_screen()->id, array( 'plugins', 'plugins-network' ), true );
169 }
170 }
171
172 new WPBC_Admin_Deactivation_Feedback();
173 endif;
174
175
176
177
178 /**
179 * Send email with feedback
180 *
181 * @param $uninstall_slug
182 * @param $feedback_description
183 *
184 * @return void
185 */
186 function wpbc_feedback_deactivation__send_email( $uninstall_slug, $feedback_description ) {
187
188 $us_data = wp_get_current_user();
189
190 $fields_values = array();
191 $fields_values['from_email'] = get_option( 'admin_email' );
192 $fields_values['from_name'] = $us_data->display_name;
193 $fields_values['from_name'] = wp_specialchars_decode( esc_html( stripslashes( $fields_values['from_name'] ) ), ENT_QUOTES );
194 $fields_values['from_email'] = sanitize_email( $fields_values['from_email'] );
195
196 $subject = 'WPBC Uninstall: ' . $uninstall_slug . '';
197
198
199 $message = '';
200 $message .= $feedback_description . "\n";
201 $message .= '=====' . "\n";
202
203 $cleaned_data_booking_feedback_arr = get_bk_option( 'booking_feedback__after_send' );
204 if ( ( ! empty( $cleaned_data_booking_feedback_arr ) ) && ( is_array( $cleaned_data_booking_feedback_arr ) ) ) {
205 $feedback_description_setup = implode( "\n", $cleaned_data_booking_feedback_arr );
206 $message .= $feedback_description_setup . "\n";
207 $message .= '=====' . "\n";
208 }
209
210
211 $message .="\n";
212
213 $message .= $fields_values['from_name'] . "\n";
214 $message .="\n";
215 $message .= '---------------------------------------------' . "\n";
216
217 $message .= 'Booking Calendar ' . wpbc_feedback_01_get_version() . "\n";
218
219 $how_old_info_arr = wpbc_get_info__about_how_old();
220 if ( ! empty( $how_old_info_arr ) ) {
221 $message .= "\n";
222 $message .= 'From: ' . $how_old_info_arr['date_echo'];
223 $message .= ' - ' . $how_old_info_arr['days'] . ' days ago.';
224 }
225
226 $message .="\n";
227 $message .= '---------------------------------------------' . "\n";
228 $message .= '[' . date_i18n( get_bk_option( 'booking_date_format' ) ) . ' ' . date_i18n( get_bk_option( 'booking_time_format' ) ) . ']'. "\n";
229 $message .= home_url() ;
230
231
232 $headers = '';
233
234 if ( ! empty( $fields_values['from_email'] ) ) {
235
236 $headers .= 'From: ' . $fields_values['from_name'] . ' <' . $fields_values['from_email'] . '> ' . "\r\n";
237 } else {
238 /* If we don't have an email from the input headers default to wordpress@$sitename
239 * Some hosts will block outgoing mail from this address if it doesn't exist but
240 * there's no easy alternative. Defaulting to admin_email might appear to be another
241 * option but some hosts may refuse to relay mail from an unknown domain. See
242 * https://core.trac.wordpress.org/ticket/5007.
243 */
244 }
245 $headers .= 'Content-Type: ' . 'text/plain' . "\r\n" ; // 'text/html'
246
247 $attachments = '';
248
249
250 $to = 'feedback_uninstall@wpbookingcalendar.com';
251
252 // debuge('In email', htmlentities($to), $subject, htmlentities($message), $headers, $attachments) ;
253 // debuge( '$to, $subject, $message, $headers, $attachments',htmlspecialchars($to), htmlspecialchars($subject), htmlspecialchars($message), htmlspecialchars($headers), htmlspecialchars($attachments));
254 if ( wpbc_email_api_is_allow_send( true, '', '' ) ) {
255 $return = wp_mail( $to, $subject, $message, $headers, $attachments );
256 }
257 }
258