Skip to content

Commit

Permalink
Merge branch 'main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
borkweb committed Jan 8, 2024
2 parents 788a638 + 79f7a04 commit 7db92eb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Plugin Name: Telemetry Library
* Description: A plugin for working on the telemetry library directly.
* Version: 1.0
* Version: 2.3.0-rc.01
* Author: StellarWP
*/

Expand Down
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 = [];

/**
* @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 );
}
}

0 comments on commit 7db92eb

Please sign in to comment.