Skip to content

utf8_encode Issue #678

@ravimallya

Description

@ravimallya

Install php version 8.2 in a LAMP server and define WP_STATELESS_CONSOLE_LOG as true. You will receive the below error while uploading a image in 'stateless' mode after manual setup of the plugin:

Deprecated: Function utf8_encode() is deprecated in /var/www/html/wp-content/plugins/wp-stateless/lib/classes/class-logger.php on line 391
Deprecated: Function utf8_encode() is deprecated in /var/www/html/wp-content/plugins/wp-stateless/lib/classes/class-logger.php on line 391
Deprecated: Creation of dynamic property wpCloud\StatelessMedia\GS_Client::$key_json is deprecated in /var/www/html/wp-content/plugins/wp-stateless/lib/classes/class-gs-client.php on line 66
 PHP Warning:  Cannot modify header information - headers already sent in /var/www/html/wp-content/plugins/wp-stateless/lib/classes/class-logger.php on line 381

Also, I'm getting 404 errors for the images that I uploaded after setting up the plugin, and no images being displayed that I uploaded prior the activation of plugin as well as after I synced existing to cloud.

The `utf8_encode' is deprecated since PHP 8.2.0 and will be removed in PHP 9 PHP Watch.

This error can be fixed by replacing the below lines in /classes/class-logger.php on line 390:

  protected function _encode( $data ) {
    return base64_encode( utf8_encode( json_encode( $data ) ) );
  }

with:

  protected function _encode($data) {
    $utf8Data = json_encode($data);
    if ($utf8Data === false) {
        // Handle JSON encoding error
        return false;
    }
    $utf8Data = mb_convert_encoding($utf8Data, 'UTF-8', 'UTF-8');
    if ($utf8Data === false) {
        // Handle conversion error
        return false;
    }
    return base64_encode($utf8Data);
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions