'User Deactivation Survey', 'popup_logo' => '', 'plugin_slug' => 'user-deactivation-survey', 'plugin_version' => '', 'popup_title' => __( 'Quick Feedback', 'astra' ), 'support_url' => 'https://brainstormforce.com/contact/', 'popup_reasons' => self::get_default_reasons(), 'popup_description' => __( 'If you have a moment, please share why you are deactivating the plugin.', 'astra' ), 'show_on_screens' => array( 'plugins' ), ); // Parse the arguments with defaults. $args = wp_parse_args( $args, $defaults ); $id = ''; // Set a default ID if none is provided. if ( empty( $args['id'] ) ) { $id = 'uds-feedback-form--wrapper'; } $id = sanitize_text_field( $args['id'] ); // Return if not on the allowed screen. if ( ! BSF_Analytics_Helper::is_allowed_screen() ) { return; } // Product slug used for input fields and labels in each plugin's deactivation survey. $product_slug = isset( $args['plugin_slug'] ) ? sanitize_text_field( $args['plugin_slug'] ) : 'bsf'; ?> esc_url( admin_url( 'admin-ajax.php' ) ), '_ajax_nonce' => wp_create_nonce( 'uds_plugin_deactivate_feedback' ), '_current_theme' => function_exists( 'wp_get_theme' ) ? wp_get_theme()->get_template() : '', '_plugin_slug' => array(), ) ); // Add localize JS. wp_localize_script( 'uds-feedback-script', 'udsVars', $data ); wp_enqueue_style( 'uds-feedback-style', $dir_path . 'assets/css/feedback' . $file_ext . '.css', array(), BSF_ANALYTICS_VERSION ); wp_style_add_data( 'uds-feedback-style', 'rtl', 'replace' ); } /** * Sends plugin deactivation feedback to the server. * * This function checks the user's permission and verifies the nonce for the request. * If the checks pass, it sends the feedback data to the server for processing. * * @return void */ public function send_plugin_deactivate_feedback() { $response_data = array( 'message' => __( 'Sorry, you are not allowed to do this operation.', 'astra' ) ); /** * Check permission */ if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( $response_data ); } /** * Nonce verification */ if ( ! check_ajax_referer( 'uds_plugin_deactivate_feedback', 'security', false ) ) { $response_data = array( 'message' => __( 'Nonce validation failed', 'astra' ) ); wp_send_json_error( $response_data ); } $feedback_data = array( 'reason' => isset( $_POST['reason'] ) ? sanitize_text_field( wp_unslash( $_POST['reason'] ) ) : '', 'feedback' => isset( $_POST['feedback'] ) ? sanitize_text_field( wp_unslash( $_POST['feedback'] ) ) : '', 'domain_name' => isset( $_POST['referer'] ) ? sanitize_text_field( wp_unslash( $_POST['referer'] ) ) : '', 'version' => isset( $_POST['version'] ) ? sanitize_text_field( wp_unslash( $_POST['version'] ) ) : '', 'plugin' => isset( $_POST['source'] ) ? sanitize_text_field( wp_unslash( $_POST['source'] ) ) : '', ); $api_args = array( 'body' => wp_json_encode( $feedback_data ), 'headers' => BSF_Analytics_Helper::get_api_headers(), 'timeout' => 90, //phpcs:ignore WordPressVIPMinimum.Performance.RemoteRequestTimeout.timeout_timeout ); $target_url = BSF_Analytics_Helper::get_api_url() . self::$feedback_api_endpoint; $response = wp_safe_remote_post( $target_url, $api_args ); $has_errors = BSF_Analytics_Helper::is_api_error( $response ); if ( $has_errors['error'] ) { wp_send_json_error( array( 'success' => false, 'message' => $has_errors['error_message'], ) ); } wp_send_json_success(); } /** * Get the array of default reasons. * * @return array Default reasons. */ public static function get_default_reasons() { return apply_filters( 'uds_default_deactivation_reasons', array( 'temporary_deactivation' => array( 'label' => esc_html__( 'This is a temporary deactivation for testing.', 'astra' ), 'placeholder' => esc_html__( 'How can we assist you?', 'astra' ), 'show_cta' => 'false', 'accept_feedback' => 'false', ), 'plugin_not_working' => array( 'label' => esc_html__( 'The plugin isn\'t working properly.', 'astra' ), 'placeholder' => esc_html__( 'Please tell us more about what went wrong?', 'astra' ), 'show_cta' => 'true', 'accept_feedback' => 'true', ), 'found_better_plugin' => array( 'label' => esc_html__( 'I found a better alternative plugin.', 'astra' ), 'placeholder' => esc_html__( 'Could you please specify which plugin?', 'astra' ), 'show_cta' => 'false', 'accept_feedback' => 'true', ), 'missing_a_feature' => array( 'label' => esc_html__( 'It\'s missing a specific feature.', 'astra' ), 'placeholder' => esc_html__( 'Please tell us more about the feature.', 'astra' ), 'show_cta' => 'false', 'accept_feedback' => 'true', ), 'other' => array( 'label' => esc_html__( 'Other', 'astra' ), 'placeholder' => esc_html__( 'Please tell us more details.', 'astra' ), 'show_cta' => 'false', 'accept_feedback' => 'true', ), ) ); } } Deactivation_Survey_Feedback::get_instance(); }