Bỏ qua điều hướng

Open

Reported for: WPML Multilingual CMS 4.7.0

Topic Tags: Bug

Overview of the issue

WPML 4.7 has a compatibility issue with plugins that use PSR/Log 3.0, such as Rollbar. When WPML and Rollbar are both active, running WP-CLI commands (e.g., wp --info) triggers a fatal error due to method signature mismatches in the DebugFileLogger class.

PHP Fatal error:  Declaration of WPML\\PHP\\Logger\\DebugFileLogger::log($level, $message, array $context = []) must be compatible with Psr\\Log\\AbstractLogger::log($level, Stringable|string $message, array $context = []): void in ...\\wp-content\\plugins\\sitepress-multilingual-cms\\vendor\\wpml\\wpml\\lib\\Php\\Logger\\DebugFileLogger.php on line 8

Workaround

Please, make sure of having a full site backup of your site before proceeding.

  • Open …/wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/wpml/lib/Php/Logger/DebugFileLogger.php file.
  • Replace:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    namespace WPML\PHP\Logger;
     
    class DebugFileLogger extends \Psr\Log\AbstractLogger {
     
     
      public function log( $level, $message, array $context = array() ) {
        if ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) {
          return;
        }
     
        $log = date( 'Y-m-d H:i:s' ) . ' [' . $level . '] ' . $message . PHP_EOL;
        \error_log( $log );
      }
     
     
    }
  • With:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    namespace WPML\PHP\Logger;
     
    use Psr\Log\AbstractLogger;
    use Stringable;
     
    class DebugFileLogger extends AbstractLogger {
     
      public function log($level, $message, array $context = []): void {
        if ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) {
          return;
        }
     
        $log = date( 'Y-m-d H:i:s' ) . ' [' . $level . '] ' . (string) $message . PHP_EOL;
        \error_log( $log );
      }
     
    }

5 phản hồi đến “WPML 4.7 Conflict with Plugins Using PSR/Log 3.0 Causes Fatal Error in WP-CLI”

    • Hello there,
      If you can reproduce this error in a different way, we would appreciate if you can share the steps to reproduce it. In that way we will be able to check if there are other cases that need to be covered. Furthermore, if the workaround here provided doesn’t help, you can start a chat in our support forum.

  1. This worked for me:

    namespace WPML\PHP\Logger;

    class DebugFileLogger extends \Psr\Log\AbstractLogger {

    public function log( $level, $message, array $context = array() ) : void {
    if ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) {
    return;
    }

    $log = date( 'Y-m-d H:i:s' ) . ' [' . $level . '] ' . $message . PHP_EOL;
    \error_log( $log );
    }

    }

Để lại trả lời

Vui lòng bám sát chủ đề và tôn trọng người khác. Nếu bạn cần trợ giúp về các vấn đề không liên quan đến bài đăng này, hãy sử dụng Diễn đàn Hỗ trợ của chúng tôi để bắt đầu trò chuyện hoặc gửi yêu cầu hỗ trợ.

Bạn có thể sử dụng các thẻ này:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>