is_activated_after_another_deactivation() && ! $this->is_reporting_disabled() ) { $this->send_active_installation_request( true ); } if ( $route_detector->is_admin_route() ) { $this->set_admin_hooks(); } } public function send_do_not_track_request(): void { // in Pro, the setting controls the usage data, but the license key/domain pair is always sent, // so we mark as inactive only for the 'Lite' version. $is_active = $this->plugin->is_pro_version(); $this->send_active_installation_request( $is_active ); } public function send_new_license_request(): void { $this->send_active_installation_request( true ); } public function plugin_activated(): void { if ( ! $this->is_reporting_disabled() ) { $this->send_active_installation_request( true ); } } public function plugin_deactivated(): void { if ( ! $this->is_reporting_disabled() ) { $deactivation_survey_fields = array(); $deactivation_survey_fields['_deactivationReason'] = Query_Arguments::get_string_for_non_action( 'advanced-views-reason' ); $deactivation_survey_fields['_deactivationNotes'] = Query_Arguments::get_string_for_non_action( 'advanced-views-notes' ); if ( strlen( $deactivation_survey_fields['_deactivationNotes'] ) > 1000 ) { $deactivation_survey_fields['_deactivationNotes'] = substr( $deactivation_survey_fields['_deactivationNotes'], 0, 1000 ); } if ( 'compatibility_issues' === $deactivation_survey_fields['_deactivationReason'] ) { // @phpcs:ignore $deactivation_survey_fields['_debugDump'] = print_r( Environment_Detector::get_installation_data(), true ); } $this->send_active_installation_request( false, $deactivation_survey_fields ); } } /** * @return array */ public function get_primary_fields(): array { return array_merge( array( '_domain' => string( wp_parse_url( get_site_url(), PHP_URL_HOST ) ), '_version' => $this->plugin_meta->get_version(), '_isPro' => $this->plugin->is_pro_version(), ), Environment_Detector::get_theme_data() ); } public function bind_deactivation_survey_popup(): void { $plugin_slug = $this->plugin_meta->get_slug(); $data = array( 'plugin_slug' => $plugin_slug, 'message' => __( "We'd love to know why you're deactivating Advanced Views. Your feedback helps us improve (Optional)", 'acf-views' ), 'notes_label' => __( "Tell us a bit more about your situation - what didn't work or what you were hoping to achieve.", 'acf-views' ), 'cancel_label' => __( 'Cancel', 'acf-views' ), 'deactivate_label' => __( 'Deactivate', 'acf-views' ), 'deactivate_and_delete_label' => __( 'Delete data and deactivate', 'acf-views' ), 'options' => array( 'not_suit_my_case' => __( 'Setup was too complex for me', 'acf-views' ), 'compatibility_issues' => __( 'Plugin conflicted with my theme or another plugin', 'acf-views' ), 'requires_coding' => __( "Required coding or technical knowledge I don't have", 'acf-views' ), 'too_complex' => __( 'Found a plugin that better fits my workflow', 'acf-views' ), ), 'delete_data_option' => __( 'Delete all the plugin data (cannot be undone)', 'acf-views' ), 'is_with_survey' => false === $this->settings->is_automatic_reports_disabled(), ); ?> $deactivation_survey_fields */ protected function send_active_installation_request( bool $is_active, array $deactivation_survey_fields = array() ): void { $fields = array_merge( $this->get_primary_fields(), array( '_isActive' => $is_active, '_isDoNotTrackRequested' => $this->settings->is_automatic_reports_disabled(), ), $deactivation_survey_fields ); $this->send_json_request( self::STATE_ENDPOINT_URL, $fields ); } // logic is overridden in Pro. protected function is_reporting_disabled(): bool { return $this->settings->is_automatic_reports_disabled(); } protected function set_admin_hooks(): void { $request_uri = Query_Arguments::get_string_for_non_action( 'REQUEST_URI', 'server' ); // deactivation survey includes the 'delete data' option, which should be visible even if reports are off // (without the survey for sure). if ( false !== strpos( $request_uri, '/wp-admin/plugins.php' ) ) { self::add_action( 'admin_footer', array( $this, 'bind_deactivation_survey_popup' ) ); } } }