useDeactivationFeedback(); /** * Fire-and-forget lifecycle event to PackEdge (install/uninstall counts). * Carries the site host and the plugin/WP/PHP versions. Sent only when the * admin has allowed diagnostics; otherwise nothing leaves the site. * Non-blocking; never affects activation. * * @param string $event Event name (e.g. product.installed). * @param array $properties Optional extra properties. * @return void */ if ( ! function_exists( 'ajaxpress_packedge_event' ) ) { function ajaxpress_packedge_event( $event, $properties = array() ) { if ( 'allowed' !== get_option( 'ajaxpress_diagnostic_permission', '' ) ) { return; } wp_remote_post( AJAXPRESS_PACKEDGE_API . '/public/v1/event', array( 'timeout' => 4, 'blocking' => false, 'headers' => array( 'Content-Type' => 'application/json' ), 'body' => wp_json_encode( array( 'public_key' => AJAXPRESS_PACKEDGE_PUBLIC_KEY, 'event' => $event, 'slug' => AJAXPRESS_PACKEDGE_SLUG, 'site' => wp_parse_url( home_url(), PHP_URL_HOST ), 'properties' => array_merge( array( 'version' => AJAXPRESS_VERSION, 'wp_version' => get_bloginfo( 'version' ), 'php_version' => phpversion(), ), (array) $properties ), ) ), ) ); } } /** * Plugin activation hook. * Reset diagnostic permission on activation. * * @return void */ if ( ! function_exists( 'ajaxpress_plugin_activation' ) ) { function ajaxpress_plugin_activation() { // Ask for diagnostics consent again on every activation. The install is // counted once the admin allows it (see the diagnostic-permission route). delete_option( 'ajaxpress_diagnostic_permission' ); // Reset tour state for all users on activation. delete_metadata( 'user', 0, 'ajaxpress_tour_completed', '', true ); delete_metadata( 'user', 0, 'ajaxpress_tour_mode', '', true ); delete_metadata( 'user', 0, 'ajaxpress_tour_dismissed_at', '', true ); } } register_activation_hook( AJAXPRESS, 'ajaxpress_plugin_activation' ); /** * Plugin deactivation hook - lifecycle uninstall count, sent only when * diagnostics are allowed. The PackEdge deactivation modal handles the * optional reason, which the admin chooses to submit. * * @return void */ if ( ! function_exists( 'ajaxpress_plugin_deactivation' ) ) { function ajaxpress_plugin_deactivation() { // The SDK deactivation modal appends ?packedge_dm=1 and sends its own // (richer) uninstalled event; skip here to avoid double-counting. if ( isset( $_REQUEST['packedge_dm'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only marker, not a state change. return; } ajaxpress_packedge_event( 'product.uninstalled' ); } } register_deactivation_hook( AJAXPRESS, 'ajaxpress_plugin_deactivation' );