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 all commits
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
27 changes: 14 additions & 13 deletions src/Telemetry/Events/Event_Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
*/
class Event_Subscriber extends Abstract_Subscriber {

/**
* @var array
*/
private static $events = [];
Camwyn marked this conversation as resolved.
Show resolved Hide resolved

/**
* @inheritDoc
*
Expand All @@ -46,19 +51,11 @@ public function register() {
* @return void
*/
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 );
}

/**
Expand All @@ -69,7 +66,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 +79,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 +98,10 @@ 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 );
if ( empty( $events ) ) {
return;
}

$this->container->get( Event::class )->send_batch( (array) $events );
}
}
Loading