問題描述

WordPress 3.7 添加了自動更新。這是如何工作的,如何配置此功能?

最佳解決方案

自動更新是自動的。

WordPress 3.7 中的基本默認行為是對次要版本 (即 X.Y.ZX.Y.Z+1) 的內核的自動更新。

沒有配置選項在 UI 中公開。要更改行為,您需要修改 wp-config.php 文件,或添加一些過濾器:

輕鬆禁用

將以下內容添加到 wp_config.php 中:

define( 'AUTOMATIC_UPDATER_DISABLED', true );

或者,添加以下過濾器:

add_filter( 'automatic_updater_disabled', '__return_true' );

核心更新控制

通過 wp-config.php

// Update core - development, major, and minor versions
define( 'WP_AUTO_UPDATE_CORE', true );

// Update core - minor versions
define( 'WP_AUTO_UPDATE_CORE', 'minor' );

// Core update disabled
define( 'WP_AUTO_UPDATE_CORE', false );

通過過濾器

// Enable nightlies (dev updates):
add_filter( 'allow_dev_auto_core_updates', '__return_true' );

// Enable major version updates:
add_filter( 'allow_major_auto_core_updates', '__return_true' );

// Disable minor updates
add_filter( 'allow_minor_auto_core_updates', '__return_false' );

主題和插件

All-or-Nothing Auto-Update 主題和插件:

默認情況下禁用主題和插件更新。通過 vilter 啓用:

add_filter( 'auto_update_plugin', '__return_true' );
add_filter( 'auto_update_theme', '__return_true' );

這些過濾器通過更新對象; 所以有可能操縱該對象來定位要更新的特定主題或插件,要麼將自動更新列入白名單 (包括) 或排除。

翻譯文件

默認情況下啓用翻譯文件更新。通過過濾器禁用

// Disable translation updates
add_filter( 'auto_update_translation', '__return_false' );

更新結果電子郵件

更新程序發送成功,失敗或嚴重錯誤的結果電子郵件。通過過濾器禁用

// Disable update emails
add_filter( 'auto_core_update_send_email', '__return_false' );

此過濾器還可用於根據電子郵件 $type(成功,失敗,關鍵),更新類型對象 $core_update$result 操作更新電子郵件:

/* @param bool   $send        Whether to send the email. Default true.
 * @param string $type        The type of email to send.
 *                            Can be one of 'success', 'fail', 'critical'.
 * @param object $core_update The update offer that was attempted.
 * @param mixed  $result      The result for the core update. Can be WP_Error.
 */
apply_filters( 'auto_core_update_send_email', true, $type, $core_update, $result );

進一步閲讀

食品進口 here 。更多信息 here

參考文獻

注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。