Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep di52 compatibility #102

Merged
merged 6 commits into from
Nov 9, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions src/Telemetry/Events/Event_Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
*/
class Event_Subscriber extends Abstract_Subscriber {

private static $events = [];
Camwyn marked this conversation as resolved.
Show resolved Hide resolved

/**
* @inheritDoc
*
Expand Down Expand Up @@ -48,17 +50,13 @@ public function register() {
public function cache_event( $name, $data ) {
$events = [];

if ( $this->container->has( 'events' ) ) {
$events = $this->container->get( 'events' );
}

$events[] = [
self::$events[] = [
'name' => $name,
'data' => wp_json_encode( $data ),
'stellar_slug' => Config::get_stellar_slug(),
];

$this->container->bind( 'events', $events );
self::$events = $events;
}

/**
Expand All @@ -69,7 +67,7 @@ public function cache_event( $name, $data ) {
* @return void
*/
public function send_cached_events() {
if ( ! $this->container->has( 'events' ) ) {
if ( empty( self::$events ) ) {
return;
}

Expand All @@ -82,12 +80,12 @@ public function send_cached_events() {
'sslverify' => false,
'body' => [
'action' => Event::AJAX_ACTION,
'events' => $this->container->get( 'events' ),
'events' => self::$events,
],
]
);

$this->container->bind( 'events', [] );
self::$events = [];
}

/**
Expand All @@ -101,6 +99,6 @@ public function send_events() {
// Get the passed event array.
$events = filter_input( INPUT_POST, 'events', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); // phpcs:ignore WordPressVIPMinimum.Security.PHPFilterFunctions.RestrictedFilter

$this->container->get( Event::class )->send_batch( $events );
$this->container->get( Event::class )->send_batch( $events ?: [] );
Camwyn marked this conversation as resolved.
Show resolved Hide resolved
}
}
Loading