@@ -80,6 +80,18 @@ public function render_exit_interview() {
8080 * @return void
8181 */
8282 public function ajax_exit_interview () {
83+ $ nonce = filter_input ( INPUT_POST , 'nonce ' , FILTER_SANITIZE_SPECIAL_CHARS );
84+ $ nonce = ! empty ( $ nonce ) ? $ nonce : '' ;
85+
86+ if ( ! wp_verify_nonce ( $ nonce , self ::AJAX_ACTION ) ) {
87+ wp_send_json_error ( 'Invalid nonce ' );
88+ }
89+
90+ // Check if the user has the necessary permissions.
91+ if ( ! current_user_can ( 'manage_options ' ) ) {
92+ wp_send_json_error ( 'User does not have proper permissions plugins ' );
93+ }
94+
8395 $ uninstall_reason_id = filter_input ( INPUT_POST , 'uninstall_reason_id ' , FILTER_SANITIZE_SPECIAL_CHARS );
8496 $ uninstall_reason_id = ! empty ( $ uninstall_reason_id ) ? $ uninstall_reason_id : false ;
8597 if ( ! $ uninstall_reason_id ) {
@@ -97,13 +109,6 @@ public function ajax_exit_interview() {
97109 $ comment = filter_input ( INPUT_POST , 'comment ' , FILTER_SANITIZE_SPECIAL_CHARS );
98110 $ comment = ! empty ( $ comment ) ? $ comment : '' ;
99111
100- $ nonce = filter_input ( INPUT_POST , 'nonce ' , FILTER_SANITIZE_SPECIAL_CHARS );
101- $ nonce = ! empty ( $ nonce ) ? $ nonce : '' ;
102-
103- if ( ! wp_verify_nonce ( $ nonce , self ::AJAX_ACTION ) ) {
104- wp_send_json_error ( 'Invalid nonce ' );
105- }
106-
107112 $ telemetry = $ this ->container ->get ( Telemetry::class );
108113 $ telemetry ->send_uninstall ( $ plugin_slug , $ uninstall_reason_id , $ uninstall_reason , $ comment );
109114
0 commit comments