Disable update one plugin, chặn thông báo update tự động wordpress

Thảo luận trong 'Mã nguồn mở Wordpress' bắt đầu bởi admin, 8/4/23.

  1. admin
    Tham gia ngày:
    22/5/13
    Bài viết:
    4,884
    Đã được thích:
    1,194
    Điểm thành tích:
    113
    Giới tính:
    Nam
    Mặc định của wordpress, các plugin mới ra, wordpress sẽ hiển thị thông số plugin mới cho mọi người update.

    Nhưng với 1 số plugin chúng ta đã edit trong đó rồi, việc update auto của người dùng sẽ làm mất hết mấy cái mình edit sửa trong plugin, hoặc mình đang xài bản cũ ổn định, update bản mới là bị lỗi web.

    Để chặn không cho update plugin auto tự động và hiển thị cái update này, không cho người dùng update plugin này thì làm như sau: như ví dụ dưới, mình đang muốn tắt, không cho hiển thị thông báo nâng cấp ngay, update auto plugin Customer Reviews for WooCommerce thì làm như thế nào?

    chan-auto-update-plugin-wordpress.jpg

    Để chặn update plugin trước tiên bạn vào function.php của themes chính chèn code sau vào.
    Mã:
    //disable 1 số plugin update đi, không cho hiển thị update
    function itseovn_disable_plugin_updates( $value ) {
      //$listplugin_link: danh sách url file tên chính của plugin
      //create an array of plugins you want to exclude from updates ( string composed by folder/main_file.php)
      $listplugin_link = array();
      //danh sách file name, tên plugin cần chặn update
      $pluginsNotUpdatable = [
        'YITH WooCommerce Brands Add-on Premium',
        'Customer Reviews for WooCommerce'
      ];
      $ii = 0;
      //lấy ra danh sách các plugin đang chạy, để lấy ra danh sách folder/main_file.php của plugin.
      require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
      $plugins = get_plugins();
      foreach( $plugins as $plugin_file => $plugin_info ) {
          foreach ($pluginsNotUpdatable as $plugin) {
            if($plugin_info['Name'] == $plugin)
            {
              $listplugin_link[$ii] = $plugin_file;
              $ii++;
            }
          }
      }
      //truyền vào chặn hiển thị và cho phép update plugin.
      if ( isset($value) && is_object($value) ) {
        foreach ($listplugin_link as $plugin) {
            if ( isset( $value->response[$plugin] ) ) {
                unset( $value->response[$plugin] );
            }
          }
      }
      return $value;
    }
    add_filter( 'site_transient_update_plugins', 'itseovn_disable_plugin_updates' );
    //end disable 1 số plugin update đi, không cho hiển thị update
    
    • Sửa tên: YITH WooCommerce Brands Add-on Premium, Customer Reviews for WooCommerce thành các plugin của bạn cần disable, tắt đi vào đây, và lưu lại, update lại file nhé (tên này bạn copy y chang ở trong mục Plugin trong admin bỏ vô nhé).
    Đây là kết quả:

    chan-update-pulugin-auto.png
     
    Cảm ơn đã xem bài:

    Disable update one plugin, chặn thông báo update tự động wordpress