魔扣论坛

魔扣源码论坛业务
查看: 2670|回复: 5

[经验交流] WordPress 关闭后台主题、插件、系统自动更新与提示

[复制链接]
  • TA的每日心情

    21 小时前
  • 签到天数: 2951 天

    [LV.Master]开坛老将

    7万

    主题

    227

    回帖

    27万

    积分

    管理员

    Rank: 30Rank: 30Rank: 30Rank: 30Rank: 30Rank: 30Rank: 30Rank: 30

    魔扣币
    745587
    贡献
    157871
    威望
    32799

    最佳新人活跃会员热心会员推广达人宣传达人突出贡献优秀版主荣誉管理论坛元老

    发表于 2017-6-15 17:49:52 | 显示全部楼层 |阅读模式
    魔扣币兑换比例:【 50以下 : ¥1 = 10 魔扣币 】丨【 50 - 100 :¥1 = 20 魔扣币】丨【 100以上:¥1 = 30 魔扣币 】

    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有账号?立即注册

    x

    有时候会发现wordperss后台越来越卡,是什么原因呢?原因可能很多,但是一些更新的获取可能是其中之一。那么可以按需关系这些更新。

    将以下代码加入主题的functions.php里(最后一个 ?> 之前):

    1. class OS_Disable_WordPress_Updates {
    2. private $__pluginsFiles;
    3. private $__themeFiles;

    4. /**
    5. * The OS_Disable_WordPress_Updates class constructor
    6. * initializing required stuff for the plugin
    7. *
    8. * PHP 5 Constructor
    9. *
    10. * @since 1.3
    11. * @author scripts@schloebe.de
    12. */
    13. function __construct() {
    14. $this->__pluginsFiles = array();
    15. $this->__themeFiles = array();

    16. add_action( 'admin_init', array(&$this, 'admin_init') );

    17. if( !function_exists( 'get_plugins' ) ) require_once ABSPATH . 'wp-admin/includes/plugin.php';

    18. if( count( get_plugins() ) > 0 ) foreach( get_plugins() as $file => $pl ) $this->__pluginsFiles[$file] = $pl['Version'];
    19. if( count( wp_get_themes() ) > 0 ) foreach( wp_get_themes() as $theme ) $this->__themeFiles[$theme->get_stylesheet()] = $theme->get('Version');

    20. /*
    21. * Disable Theme Updates
    22. * 2.8 to 3.0
    23. */
    24. add_filter( 'pre_transient_update_themes', array($this, 'last_checked_themes') );
    25. /*
    26. * 3.0
    27. */
    28. add_filter( 'pre_site_transient_update_themes', array($this, 'last_checked_themes') );


    29. /*
    30. * Disable Plugin Updates
    31. * 2.8 to 3.0
    32. */
    33. add_action( 'pre_transient_update_plugins', array(&$this, 'last_checked_plugins') );
    34. /*
    35. * 3.0
    36. */
    37. add_filter( 'pre_site_transient_update_plugins', array($this, 'last_checked_plugins') );


    38. /*
    39. * Disable Core Updates
    40. * 2.8 to 3.0
    41. */
    42. add_filter( 'pre_transient_update_core', array($this, 'last_checked_core') );
    43. /*
    44. * 3.0
    45. */
    46. add_filter( 'pre_site_transient_update_core', array($this, 'last_checked_core') );


    47. /*
    48. * Disable All Automatic Updates
    49. * 3.7+
    50. *
    51. * @author sLa NGjI's @ slangji.wordpress.com
    52. */
    53. add_filter( 'auto_update_translation', '__return_false' );
    54. add_filter( 'automatic_updater_disabled', '__return_true' );
    55. add_filter( 'allow_minor_auto_core_updates', '__return_false' );
    56. add_filter( 'allow_major_auto_core_updates', '__return_false' );
    57. add_filter( 'allow_dev_auto_core_updates', '__return_false' );
    58. add_filter( 'auto_update_core', '__return_false' );
    59. add_filter( 'wp_auto_update_core', '__return_false' );
    60. add_filter( 'auto_core_update_send_email', '__return_false' );
    61. add_filter( 'send_core_update_notification_email', '__return_false' );
    62. add_filter( 'auto_update_plugin', '__return_false' );
    63. add_filter( 'auto_update_theme', '__return_false' );
    64. add_filter( 'automatic_updates_send_debug_email', '__return_false' );
    65. add_filter( 'automatic_updates_is_vcs_checkout', '__return_true' );


    66. add_filter( 'automatic_updates_send_debug_email ', '__return_false', 1 );
    67. if( !defined( 'AUTOMATIC_UPDATER_DISABLED' ) ) define( 'AUTOMATIC_UPDATER_DISABLED', true );
    68. if( !defined( 'WP_AUTO_UPDATE_CORE') ) define( 'WP_AUTO_UPDATE_CORE', false );

    69. add_filter( 'pre_http_request', array($this, 'block_request'), 10, 3 );
    70. }


    71. /**
    72. * The OS_Disable_WordPress_Updates class constructor
    73. * initializing required stuff for the plugin
    74. *
    75. * PHP 4 Compatible Constructor
    76. *
    77. * @since 1.3
    78. * @author scripts@schloebe.de
    79. */
    80. function OS_Disable_WordPress_Updates() {
    81. $this->__construct();
    82. }


    83. /**
    84. * Initialize and load the plugin stuff
    85. *
    86. * @since 1.3
    87. * @author scripts@schloebe.de
    88. */
    89. function admin_init() {
    90. if ( !function_exists("remove_action") ) return;


    91. /*
    92. * Hide maintenance and update nag
    93. */
    94. remove_action( 'admin_notices', 'update_nag', 3 );
    95. remove_action( 'network_admin_notices', 'update_nag', 3 );
    96. remove_action( 'admin_notices', 'maintenance_nag' );
    97. remove_action( 'network_admin_notices', 'maintenance_nag' );


    98. /*
    99. * Disable Theme Updates
    100. * 2.8 to 3.0
    101. */
    102. remove_action( 'load-themes.php', 'wp_update_themes' );
    103. remove_action( 'load-update.php', 'wp_update_themes' );
    104. remove_action( 'admin_init', '_maybe_update_themes' );
    105. remove_action( 'wp_update_themes', 'wp_update_themes' );
    106. wp_clear_scheduled_hook( 'wp_update_themes' );


    107. /*
    108. * 3.0
    109. */
    110. remove_action( 'load-update-core.php', 'wp_update_themes' );
    111. wp_clear_scheduled_hook( 'wp_update_themes' );


    112. /*
    113. * Disable Plugin Updates
    114. * 2.8 to 3.0
    115. */
    116. remove_action( 'load-plugins.php', 'wp_update_plugins' );
    117. remove_action( 'load-update.php', 'wp_update_plugins' );
    118. remove_action( 'admin_init', '_maybe_update_plugins' );
    119. remove_action( 'wp_update_plugins', 'wp_update_plugins' );
    120. wp_clear_scheduled_hook( 'wp_update_plugins' );

    121. /*
    122. * 3.0
    123. */
    124. remove_action( 'load-update-core.php', 'wp_update_plugins' );
    125. wp_clear_scheduled_hook( 'wp_update_plugins' );


    126. /*
    127. * Disable Core Updates
    128. * 2.8 to 3.0
    129. */
    130. add_action( 'init', create_function( '', 'remove_action( \'init\', \'wp_version_check\' );' ), 2 );
    131. add_filter( 'pre_option_update_core', '__return_null' );

    132. remove_action( 'wp_version_check', 'wp_version_check' );
    133. remove_action( 'admin_init', '_maybe_update_core' );
    134. wp_clear_scheduled_hook( 'wp_version_check' );


    135. /*
    136. * 3.0
    137. */
    138. wp_clear_scheduled_hook( 'wp_version_check' );


    139. /*
    140. * 3.7+
    141. */
    142. remove_action( 'wp_maybe_auto_update', 'wp_maybe_auto_update' );
    143. remove_action( 'admin_init', 'wp_maybe_auto_update' );
    144. remove_action( 'admin_init', 'wp_auto_update_core' );
    145. wp_clear_scheduled_hook( 'wp_maybe_auto_update' );
    146. }


    147. /**
    148. * Check the outgoing request
    149. *
    150. * @since 1.4.4
    151. */
    152. public function block_request($pre, $args, $url) {
    153. /* Empty url */
    154. if( empty( $url ) ) {
    155. return $pre;
    156. }

    157. /* Invalid host */
    158. if( !$host = parse_url($url, PHP_URL_HOST) ) {
    159. return $pre;
    160. }

    161. $url_data = parse_url( $url );

    162. /* block request */
    163. if( false !== stripos( $host, 'api.wordpress.org' ) && (false !== stripos( $url_data['path'], 'update-check' ) || false !== stripos( $url_data['path'], 'browse-happy' )) ) {
    164. return true;
    165. }

    166. return $pre;
    167. }


    168. /**
    169. * Override core version check info
    170. *
    171. * @since 1.4.3
    172. */
    173. public function last_checked_core() {
    174. global $wp_version;

    175. return (object) array(
    176. 'last_checked' => time(),
    177. 'updates' => array(),
    178. 'version_checked' => $wp_version
    179. );
    180. }

    181. /**
    182. * Override themes version check info
    183. *
    184. * @since 1.4.3
    185. */
    186. public function last_checked_themes() {
    187. global $wp_version;

    188. return (object) array(
    189. 'last_checked' => time(),
    190. 'updates' => array(),
    191. 'version_checked' => $wp_version,
    192. 'checked' => $this->__themeFiles
    193. );
    194. }

    195. /**
    196. * Override plugins version check info
    197. *
    198. * @since 1.4.3
    199. */
    200. public function last_checked_plugins() {
    201. global $wp_version;

    202. return (object) array(
    203. 'last_checked' => time(),
    204. 'updates' => array(),
    205. 'version_checked' => $wp_version,
    206. 'checked' => $this->__pluginsFiles
    207. );
    208. }
    209. }

    210. if ( class_exists('OS_Disable_WordPress_Updates') ) {
    211. $OS_Disable_WordPress_Updates = new OS_Disable_WordPress_Updates();
    212. }
    复制代码

    以上代码是一个插件里的代码,插件名称好像是 disabled wordpress updates 。但是,我们能不用插件就尽量不用插件!


    会员购买:>> 点击购买 << | 魔扣币购买:>> 点击购买 <<
    承接业务:服务器代维丨网站托管丨SEO
    联系客服:微信:morko-net | QQ:1367681973

    该用户从未签到

    1

    主题

    240

    回帖

    484

    积分

    中级魔扣

    Rank: 3Rank: 3

    魔扣币
    242
    贡献
    242
    威望
    1
    发表于 2017-6-15 18:34:04 | 显示全部楼层
    呵呵。。。

    该用户从未签到

    2

    主题

    244

    回帖

    492

    积分

    中级魔扣

    Rank: 3Rank: 3

    魔扣币
    246
    贡献
    246
    威望
    0
    发表于 2017-6-16 05:52:19 来自手机 | 显示全部楼层
    OMG!介是啥东东!!!

    该用户从未签到

    5

    主题

    260

    回帖

    525

    积分

    高级魔扣

    Rank: 4

    魔扣币
    260
    贡献
    260
    威望
    0
    发表于 2017-10-29 18:59:10 | 显示全部楼层
    感谢您美好的祝福!懂得欣赏的人,找到的是感觉;懂得知足的人,找到的是快乐;懂得珍惜的人,找到的是幸福;懂得关怀的人,找到的是朋友;懂得抓机遇的人,找到的是成功路;魔扣源码论坛真心祝愿朋您的人生梦想全部实现!

    该用户从未签到

    2

    主题

    267

    回帖

    537

    积分

    高级魔扣

    Rank: 4

    魔扣币
    268
    贡献
    268
    威望
    0
    发表于 2018-4-26 23:08:47 | 显示全部楼层
    真诚的朋友虽然遥远还是心绪相牵!纯真的友谊即是难聚仍然温馨美甜!魔扣源码论坛祝福好朋友事事顺心如意快乐天天!远方的我时时为您衷心的祈祷祝愿!

    该用户从未签到

    1

    主题

    244

    回帖

    489

    积分

    中级魔扣

    Rank: 3Rank: 3

    魔扣币
    244
    贡献
    244
    威望
    0
    发表于 2018-10-5 16:01:05 | 显示全部楼层
    锄禾日当午,发帖真辛苦。谁知坛中餐,帖帖皆辛苦!
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    • 联系我们
    • 新浪微博 :
    • 在线客服 :魔扣科技 
    • 源码QQ群 :魔扣源码论坛官方总群
    • 联系邮箱 :charlin#morko.net
    • 微信扫一扫
    快速回复 返回顶部 返回列表