From 9a553e8bb775212c56b4107e9e520f944ff99d71 Mon Sep 17 00:00:00 2001 From: Stefan Kalscheuer Date: Fri, 10 Nov 2023 18:48:58 +0100 Subject: [PATCH] use `wp_json_encode()` in favor of `json_encode()` --- inc/class-antivirus-safebrowsing.php | 2 +- tests/bootstrap.php | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/inc/class-antivirus-safebrowsing.php b/inc/class-antivirus-safebrowsing.php index 3efd992..dc29bfd 100644 --- a/inc/class-antivirus-safebrowsing.php +++ b/inc/class-antivirus-safebrowsing.php @@ -38,7 +38,7 @@ public static function check_safe_browsing() { 'headers' => array( 'Content-Type' => 'application/json', ), - 'body' => json_encode( + 'body' => wp_json_encode( array( 'client' => array( 'clientId' => 'wpantivirus', diff --git a/tests/bootstrap.php b/tests/bootstrap.php index c5cb972..bbcb850 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -97,3 +97,18 @@ public function parent() { return $this->get( 'parent' ); } } + +// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed + +/** + * Encodes a variable into JSON, with some sanity checks. + * + * @param mixed $data Variable (usually an array or object) to encode as JSON. + * @param int $options Optional. Options to be passed to json_encode(). Default 0. + * @param int $depth Optional. Maximum depth to walk through $data. Must be + * greater than 0. Default 512. + * @return string|false The JSON encoded string, or false if it cannot be encoded. + */ +function wp_json_encode( $data, $options = 0, $depth = 512 ) { + return json_encode( $data, $options, $depth ); +}