: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
if ( ! empty( $array ) && is_string( $array ) ) {
if ( strpos( $array, '\"' ) >= 0 ) {
$array = stripslashes( $array );
$array = json_decode( $array );
$array = self::from_object( $array );
$array = self::fix_json_boolean_values( $array );
* Ensures proper encoding for strings before json_encode is used.
* @param array|string $data
public static function safe_json_encode( $data = [] ) {
return wp_json_encode( self::make_safe_for_json_encode( $data ) );
* json_encode only accepts valid UTF8 characters, thus we need to properly convert translations and other data to proper utf.
* This function does that recursively.
* @param array|string $data
public static function make_safe_for_json_encode( $data = [] ) {
if ( is_scalar( $data ) ) {
return html_entity_decode( (string) $data, ENT_QUOTES, 'UTF-8' );
if ( is_array( $data ) ) {
foreach ( (array) $data as $key => $value ) {
if ( is_scalar( $value ) && ! is_bool( $value ) ) {
$data[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
} elseif ( is_array( $value ) ) {
$data[ $key ] = self::make_safe_for_json_encode( $value );
public static function utf8_encode_recursive( $d ) {
foreach ( $d as $k => $v ) {
$d[ $k ] = self::utf8_encode_recursive( $v );
} elseif ( is_string( $d ) ) {
return utf8_encode( $d );
public static function maybe_json_attr( $value, $encode = false ) {
if ( is_object( $value ) || is_array( $value ) ) {
return $encode ? htmlspecialchars( json_encode( $value ) ) : json_encode( $value );
* @param array $array an array values.
* @param array $remap_array an array of $old_key => $new_key values.
public static function remap_keys( $array, $remap_array = [] ) {
foreach ( $remap_array as $old_key => $new_key ) {
$value = isset( $array[ $old_key ] ) ? $array[ $old_key ] : false;
if ( ! empty( $value ) ) {
$array[ $new_key ] = $value;
unset( $array[ $old_key ] );