禁用 WordPress 核心版本 禁用所有主題 更新檢查與提示

// 1. 禁用 WordPress 核心版本更新檢查與提示
add_filter( 'pre_site_transient_update_core', '__return_null' );
remove_action( 'admin_notices', 'update_nag', 3 );

// 2. 禁用所有主題更新檢查
add_filter( 'pre_site_transient_update_themes', '__return_null' );

// 3. 禁用插件更新檢查 (如果也需要的話,可視情況保留)
// add_filter( 'pre_site_transient_update_plugins', '__return_null' );

在 WPCode(或 WPCode Lite)中添加這些代碼非常方便,因為你不需要手動修改 functions.php 文件,且更換主題時代碼依然有效。
請按照以下步驟操作:
步驟 1:新建代碼片段
進入 WordPress 後台,點擊左側選單的 Code Snippets -> + Add Snippet。
選擇 Add Your Custom Code (New Snippet)。
步驟 2:輸入禁用代碼
將 Code Type 下拉選單切換為 PHP Snippet,然後貼入以下代碼(這會同時禁用核心與主題更新提示):
php
// 1. 禁用 WordPress 核心版本更新檢查與提示
add_filter( 'pre_site_transient_update_core', '__return_null' );
remove_action( 'admin_notices', 'update_nag', 3 );

// 2. 禁用所有主題更新檢查
add_filter( 'pre_site_transient_update_themes', '__return_null' );

// 3. 禁用插件更新檢查 (如果也需要的話,可視情況保留)
// add_filter( 'pre_site_transient_update_plugins', '__return_null' );
請謹慎使用程式碼。
步驟 3:設置與啟用
Insertion (插入方式):保持默認的 Run Everywhere (全域運行)。
效果確認:將右上角的開關切換為 Active (啟用),然後點擊 Save Snippet。
⚠️ 特別注意
wp-config.php 代碼無法在這裡使用:WPCode 只能運行 PHP 邏輯,無法修改 wp-config.php 中的 define 常量。如果你之前想用 define( 'AUTOMATIC_UPDATER_DISABLED', true );,這必須透過 FTP 或主機文件管理器手動修改文件。
緩存延遲:儲存後,建議到「儀表板」->「更新」點擊一下「重新檢查」,原本的更新提示就會消失。
你需要我也提供禁用特定某個插件更新的代碼嗎?


 

Warning: Attempt to read property "current" on bool in /Users/mac/Local Sites/site/app/public/wp-admin/update-core.php on line 41

Warning: Attempt to read property "locale" on bool in /Users/mac/Local Sites/site/app/public/wp-admin/update-core.php on line 43

Warning: Attempt to read property "locale" on bool in /Users/mac/Local Sites/site/app/public/wp-admin/update-core.php on line 45

Warning: Attempt to read property "locale" on bool in /Users/mac/Local Sites/site/app/public/wp-admin/update-core.php on line 51

Warning: Attempt to read property "current" on bool in /Users/mac/Local Sites/site/app/public/wp-admin/update-core.php on line 67

Warning: Attempt to read property "response" on bool in /Users/mac/Local Sites/site/app/public/wp-admin/update-core.php on line 77

 

Warning: Attempt to read property "current" on bool in /Users/mac/Local Sites/site/app/public/wp-admin/update-core.php on line 163Warning: Attempt to read property "locale" on bool in /Users/mac/Local Sites/site/app/public/wp-admin/update-core.php on line 164

Warning: Attempt to read property "locale" on bool in /Users/mac/Local Sites/site/app/public/wp-admin/update-core.php on line 173


 

php
/**
 * 安全地禁用更新檢查並消除 update-core.php 報錯
 */
function my_custom_disable_updates() {
    global $wp_version;
    // 回傳一個對象而不是 null,避免系統讀取屬性時出錯
    return (object) array(
        'last_checked'    => time(),
        'version_checked' => $wp_version,
        'updates'         => array(),
        'translations'    => array(),
    );
}

// 核心更新
add_filter( 'pre_site_transient_update_core', 'my_custom_disable_updates' );
// 主題更新
add_filter( 'pre_site_transient_update_themes', 'my_custom_disable_updates' );
// 插件更新 (選用,若想保留插件更新可註釋掉下一行)
add_filter( 'pre_site_transient_update_plugins', 'my_custom_disable_updates' );

// 移除更新提示通知
remove_action( 'admin_notices', 'update_nag', 3 );

 

出現這些 Warning 是因為我們使用的 __return_null 代碼雖然能攔截更新提示,但在進入「儀表板 > 更新」頁面時,WordPress 核心代碼會嘗試讀取這些(現在是 null 的)更新數據,導致 PHP 報錯。
Stack Overflow
Stack Overflow
+2
請在 WPCode 中將原來的代碼替換為以下**「相容性更高」**的版本,它會回傳一個空的「偽造數據對象」,讓系統以為已經檢查過但沒有更新,從而消除報錯:
wp-kama.com
wp-kama.com
+4

為什麼這樣改有效?
避免空值引用:報錯提示 Attempt to read property ... on bool 是因為系統預期得到一個對象,但原本的代碼給了它 null(布林值的對等項)。新代碼提供了一個包含 current、locale 等屬性所需的基礎對象。
模擬「已檢查」狀態:代碼中設置了 last_checked 為當前時間,這告訴 WordPress 「剛剛才檢查過」,它就不會頻繁地在後台嘗試重新連接更新伺服器。
Stack Overflow
Stack Overflow
+2
設置建議
在 WPCode 中儲存並啟用後,請到後台**「儀表板」 > 「更新」,點擊一次「重新檢查」**按鈕,讓系統緩存重置,報錯通常就會消失。
如果你發現網站前台或後台仍有殘留的警告,請確認 wp-config.php 中的 WP_DEBUG 是否開啟。如果是開發環境,建議保留報錯顯示;如果是正式網站,建議在 wp-config.php 關閉 display_errors。
Stack Overflow
Stack Overflow
+3

 

 

 

 

阅读剩余
THE END