Tuesday, April 7, 2015

Tắt thông báo bản cập nhật mới của Wordpress và Plugin

Với các website xây dựng từ Wordpress, mỗi khi có phiên bản mới của Wordpress hoặc các Plugin đang sử dụng thì bạn sẽ nhận được các dạng thông báo như hình dưới đây:

Minh họa thông báo cập nhật của Wordpress & Plugin, source: wpoptimus.com
Nhiều khi những thông báo này khiến bạn khó chịu hay "ngứa mắt" và bạn muốn tắt chúng đi. Như vậy thì phải làm sao?

Dưới đây là một số cách bạn có thể tham khảo để thực hiện được "mong muốn" trên:

1. Viết thêm code trong theme hoặc plugin

Thêm đoạn mã sau vào theme hay plugin của bạn sẽ loại bỏ các thông báo cập nhật phiên bản mới, cài đặt mới của Wordpress

add_action('after_setup_theme','remove_core_updates');
function remove_core_updates()
{
 if(! current_user_can('update_core')){return;}
 add_action('init', create_function('$a',"remove_action( 'init', 'wp_version_check' );"),2);
 add_filter('pre_option_update_core','__return_null');
 add_filter('pre_site_transient_update_core','__return_null');
}

Thêm đoạn mã sau để loại bỏ hoàn toàn thông báo cập nhật của Plugin

remove_action('load-update-core.php','wp_update_plugins');
add_filter('pre_site_transient_update_plugins','__return_null');

Đoạn mã dưới sẽ loại bỏ toàn bộ các thông báo cập nhật bất kể của Wordpress Core, plugin hay theme

function remove_core_updates(){
global $wp_version;return(object) array('last_checked'=> time(),'version_checked'=> $wp_version,);
}
add_filter('pre_site_transient_update_core','remove_core_updates');
add_filter('pre_site_transient_update_plugins','remove_core_updates');
add_filter('pre_site_transient_update_themes','remove_core_updates');

Để tắt thông báo của chỉ 1 plugin cụ thể thì thêm vào plugin đó đoạn code sau:

function filter_plugin_updates( $value ) {
unset( $value->response['plugin_name/plugin_name.php'] );
return $value;
}
add_filter( 'site_transient_update_plugins', 'filter_plugin_updates' );

Trong đó plugin_name/plugin_name.php ta thay tương ứng với plugin đó. Ví dụ: better-wp-security/better-wp-security.php ứng với plugin Better Wordpress Security.

2. Sử dụng Plugin

Chúng ta có thể sử dụng các Plugin sẵn có để thực hiện việc bỏ thông báo cập nhật:
- Disable All WordPress Updates
- Disable WordPress Core Updates
- Disable WordPress Plugin Updates
- Disable WordPress Theme Updates

Bài viết tổng hợp từ Internet, nguồn: http://www.wpoptimus.com/626/7-ways-disable-update-wordpress-notifications/

No comments:

Post a Comment