Skip to content

Commit

Permalink
Fix a case where wp_rand is undefined. (#39581)
Browse files Browse the repository at this point in the history
* Added a check for wp_rand in case pluggables are not loaded yet.

* Changelog.
  • Loading branch information
zinigor authored Sep 30, 2024
1 parent e0ddd28 commit 02d0e6e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Added a check for function presence to avoid fatal errors.
3 changes: 2 additions & 1 deletion projects/packages/a8c-mc-stats/src/class-a8c-mc-stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 02d0e6e

Please sign in to comment.