From cf9b93076446b0547779b7c3fe6a774b5df913f7 Mon Sep 17 00:00:00 2001 From: Igor Zinovyev Date: Mon, 30 Sep 2024 17:56:24 +0300 Subject: [PATCH 1/2] Added a check for wp_rand in case pluggables are not loaded yet. --- projects/packages/a8c-mc-stats/src/class-a8c-mc-stats.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/projects/packages/a8c-mc-stats/src/class-a8c-mc-stats.php b/projects/packages/a8c-mc-stats/src/class-a8c-mc-stats.php index 9e573cd7b15a1..53ab56182fcda 100644 --- a/projects/packages/a8c-mc-stats/src/class-a8c-mc-stats.php +++ b/projects/packages/a8c-mc-stats/src/class-a8c-mc-stats.php @@ -158,7 +158,8 @@ public function do_server_side_stat( $url ) { public function build_stats_url( $args ) { $defaults = array( 'v' => 'wpcom2', - 'rand' => md5( wp_rand( 0, 999 ) . time() ), + // phpcs:ignore WordPress.WP.AlternativeFunctions.rand_rand -- There can be a case where pluggables are not yet loaded. + 'rand' => md5( ( function_exists( 'wp_rand' ) ? wp_rand( 0, 999 ) : rand( 0, 999 ) ) . time() ), ); $args = wp_parse_args( $args, $defaults ); $gifname = true === $this->use_transparent_pixel ? 'b.gif' : 'g.gif'; From 5cc0737032f380bd62e2db18e7d64f13dac5cc5e Mon Sep 17 00:00:00 2001 From: Igor Zinovyev Date: Mon, 30 Sep 2024 17:57:33 +0300 Subject: [PATCH 2/2] Changelog. --- .../a8c-mc-stats/changelog/fix-mc-stats-wp-rand-undefined | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 projects/packages/a8c-mc-stats/changelog/fix-mc-stats-wp-rand-undefined diff --git a/projects/packages/a8c-mc-stats/changelog/fix-mc-stats-wp-rand-undefined b/projects/packages/a8c-mc-stats/changelog/fix-mc-stats-wp-rand-undefined new file mode 100644 index 0000000000000..d0956ce7ba9fa --- /dev/null +++ b/projects/packages/a8c-mc-stats/changelog/fix-mc-stats-wp-rand-undefined @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Added a check for function presence to avoid fatal errors.