Update Control - Version 1.3.1

Version Description

  • Bugfix. Correct filter name.
Download this release

Release Info

Developer chipbennett
Plugin Icon wp plugin Update Control
Version 1.3.1
Comparing to
See all releases

Code changes from version 1.3 to 1.3.1

Files changed (2) hide show
  1. readme.txt +113 -110
  2. update-control.php +384 -384
readme.txt CHANGED
@@ -1,110 +1,113 @@
1
- === Update Control ===
2
- Contributors: georgestephanis, chipbennett
3
- Tags: automatic updates, updates
4
- Requires at least: 3.7
5
- Tested up to: 3.7
6
- Stable tag: 1.3
7
- License: GPLv2 or later
8
- License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
-
10
- This adds some options to your Settings > General page that let you tweak auto-updates.
11
-
12
- == Description ==
13
-
14
- This plugin adds some options to your Settings > General page, letting you specify how auto-upgrades should function, without the need to specify constants or add filters by hand.
15
-
16
- == Installation ==
17
-
18
- Installation using "Add New Plugin"
19
-
20
- 1. From your Admin UI (Dashboard), use the menu to select Plugins -> Add New
21
- 2. Search for 'Update Control'
22
- 3. Click the 'Install' button to open the plugin's repository listing
23
- 4. Click the 'Install' button
24
-
25
- Activiation and Use
26
-
27
- 1. Activate the plugin through the 'Plugins' menu in WordPress
28
- 2. From your Admin UI (Dashboard), use the menu to select Settings -> General
29
- 3. Configure settings, and save
30
-
31
- == Frequently Asked Questions ==
32
-
33
- = Why doesn't this Plugin have its own settings page? =
34
-
35
- Plugin settings can be found under Settings -> General.
36
-
37
- Not having a separate settings page is a decision based on UI philosophy. The Plugin simply isn't complex enough to warrant a separate settings page. Perhaps a different admin page, such as Dashboard -> Updates, would be more appropriate; however, core does not provide a way to hook into that page to add settings sections.
38
-
39
- This Plugin is intentionally very simple. If you want a Plugin with more complexity and its own settings page, you might want to check out [Automatic Updater](http://wordpress.org/plugins/automatic-updater).
40
-
41
- = How do I use this Plugin in a multisite network? =
42
-
43
- Activate the Plugin on the main network site, and configure options via Settings -> General.
44
-
45
- = What do "Minor", "Major", and "Development" core updates mean? =
46
-
47
- * "Minor": minor versions will be updated automatically. Minor versions in WordPress are "X.Y.Z". A minor-version update is a change from "X.Y.Z" to "X.Y.Z+1". This is the default core behavior.
48
- * "Major": major versions will be updated automatically. Major versiosn in WordPress are "X.Y". A major-version update is a change from "X.Y" to "X.Y+1".
49
- * "Development": development versions will be updated automatically. Development versions, also referred to as "bleeding-edge nightlies", are daily updates in the current development branch. While usually quite stable, this option should be used only if you're comfortable with using potentially unstable, development software. This option should only be used on production sites if your name is "Otto".
50
-
51
- = Which setting should I use? =
52
-
53
- Core Updates:
54
-
55
- * If you want minor versions to update automatically (default WordPress core behavior): leave "Automatic Core Update Level?" set to "Minor".
56
- * If you want both minor and major versions to update automatically: set "Automatic Core Update Level?" to "Major".
57
- * If you want bleeding-edge nightlies: set "Automatic Core Update Level?" to "Development"
58
- * If you want to disable core updates altogether: set "Automatic Updates Enabled?" to "no"
59
-
60
- Plugin/Theme/Translation Updates:
61
-
62
- * If you disable updates, Plugin, Theme, and Translation updates will also be disabled
63
- * Separately enable Plugin, Theme, and Translation updates via the appropriate checkboxes
64
-
65
- = What are advanced settings? =
66
-
67
- Disable VCS Check
68
-
69
- * By default, WordPress will check for the existence of VCS (version control system) files, and if any are found, will not perform automatic updates. Selecting "Disable VCS Check?" will force WordPress to bypass this check, and perform updates regardless of the existence of VCS files.
70
-
71
- Update Result Emails
72
-
73
- * By default, WordPress sends an update result email for successful, failed, and critically failed updates
74
- * Selectively disable emails for each result type via the appropriate checkboxes
75
-
76
- Debug Email
77
-
78
- * Enable this option to enable the debug email. This email is sent after ever occurrence of an attempted update, for core, Plugins, Themes, and translation files; and whether the attempt succeeds, fails, or fails critically.
79
-
80
- = Why don't automatic updates happen right away? =
81
-
82
- You may find that you receive an update notification, but automatic updates don't happen right away. That's okay! WordPress performs automatic updates according to timing based on certain transient values, and it is possible for the update check to happen some time before the automatic update routine executes. The Plugin doesn't modify the timing of the automatic update routine; rather, it just tells WordPress which update types are enabled.
83
-
84
- Also, core now has two separate types of updates: manual updates and automatic updates. When you see the manual upgrade notice, WordPress has received the manual update offer, but has not yet received the automatic update offer. The two offers are fetched based on two different transients, and do not happen at the same time. Automatic core updates are served on a staggered rollout, which means that it may take up to 36 hours for the automatic update to execute after receiving the manual upgrade notice. For Plugins and Themes, you should normally see the automatic update routine execute within 12 hours of receiving the manual upgrade notice.
85
-
86
- == Changelog ==
87
-
88
- = 1.3 =
89
- * Maintenance Update. Add multisite awareness, more FAQs.
90
-
91
- = 1.2.1 =
92
- * Make Advanced Settings UI a bit more intuitive.
93
-
94
- = 1.2 =
95
- * Feature Update. Add advanced options toggle, and options for VCS check disabling and debug email.
96
-
97
- = 1.1.3 =
98
- * Bugfix. Declare static functions to eliminate e-strict PHP notice.
99
-
100
- = 1.1.2 =
101
- * Bugfix. Use selected() instead of checked() in select form fields.
102
-
103
- = 1.1.1 =
104
- * Bugfix. Correct variable name typo
105
-
106
- = 1.1 =
107
- * Update for WordPress 3.7 final, add update email options.
108
-
109
- = 1.0 =
110
- * Initial Release.
 
 
 
1
+ === Update Control ===
2
+ Contributors: georgestephanis, chipbennett
3
+ Tags: automatic updates, updates
4
+ Requires at least: 3.7
5
+ Tested up to: 3.8.1
6
+ Stable tag: 1.3.1
7
+ License: GPLv2 or later
8
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
+
10
+ This adds some options to your Settings > General page that let you tweak auto-updates.
11
+
12
+ == Description ==
13
+
14
+ This plugin adds some options to your Settings > General page, letting you specify how auto-upgrades should function, without the need to specify constants or add filters by hand.
15
+
16
+ == Installation ==
17
+
18
+ Installation using "Add New Plugin"
19
+
20
+ 1. From your Admin UI (Dashboard), use the menu to select Plugins -> Add New
21
+ 2. Search for 'Update Control'
22
+ 3. Click the 'Install' button to open the plugin's repository listing
23
+ 4. Click the 'Install' button
24
+
25
+ Activiation and Use
26
+
27
+ 1. Activate the plugin through the 'Plugins' menu in WordPress
28
+ 2. From your Admin UI (Dashboard), use the menu to select Settings -> General
29
+ 3. Configure settings, and save
30
+
31
+ == Frequently Asked Questions ==
32
+
33
+ = Why doesn't this Plugin have its own settings page? =
34
+
35
+ Plugin settings can be found under Settings -> General.
36
+
37
+ Not having a separate settings page is a decision based on UI philosophy. The Plugin simply isn't complex enough to warrant a separate settings page. Perhaps a different admin page, such as Dashboard -> Updates, would be more appropriate; however, core does not provide a way to hook into that page to add settings sections.
38
+
39
+ This Plugin is intentionally very simple. If you want a Plugin with more complexity and its own settings page, you might want to check out [Automatic Updater](http://wordpress.org/plugins/automatic-updater).
40
+
41
+ = How do I use this Plugin in a multisite network? =
42
+
43
+ Activate the Plugin on the main network site, and configure options via Settings -> General.
44
+
45
+ = What do "Minor", "Major", and "Development" core updates mean? =
46
+
47
+ * "Minor": minor versions will be updated automatically. Minor versions in WordPress are "X.Y.Z". A minor-version update is a change from "X.Y.Z" to "X.Y.Z+1". This is the default core behavior.
48
+ * "Major": major versions will be updated automatically. Major versiosn in WordPress are "X.Y". A major-version update is a change from "X.Y" to "X.Y+1".
49
+ * "Development": development versions will be updated automatically. Development versions, also referred to as "bleeding-edge nightlies", are daily updates in the current development branch. While usually quite stable, this option should be used only if you're comfortable with using potentially unstable, development software. This option should only be used on production sites if your name is "Otto".
50
+
51
+ = Which setting should I use? =
52
+
53
+ Core Updates:
54
+
55
+ * If you want minor versions to update automatically (default WordPress core behavior): leave "Automatic Core Update Level?" set to "Minor".
56
+ * If you want both minor and major versions to update automatically: set "Automatic Core Update Level?" to "Major".
57
+ * If you want bleeding-edge nightlies: set "Automatic Core Update Level?" to "Development"
58
+ * If you want to disable core updates altogether: set "Automatic Updates Enabled?" to "no"
59
+
60
+ Plugin/Theme/Translation Updates:
61
+
62
+ * If you disable updates, Plugin, Theme, and Translation updates will also be disabled
63
+ * Separately enable Plugin, Theme, and Translation updates via the appropriate checkboxes
64
+
65
+ = What are advanced settings? =
66
+
67
+ Disable VCS Check
68
+
69
+ * By default, WordPress will check for the existence of VCS (version control system) files, and if any are found, will not perform automatic updates. Selecting "Disable VCS Check?" will force WordPress to bypass this check, and perform updates regardless of the existence of VCS files.
70
+
71
+ Update Result Emails
72
+
73
+ * By default, WordPress sends an update result email for successful, failed, and critically failed updates
74
+ * Selectively disable emails for each result type via the appropriate checkboxes
75
+
76
+ Debug Email
77
+
78
+ * Enable this option to enable the debug email. This email is sent after ever occurrence of an attempted update, for core, Plugins, Themes, and translation files; and whether the attempt succeeds, fails, or fails critically.
79
+
80
+ = Why don't automatic updates happen right away? =
81
+
82
+ You may find that you receive an update notification, but automatic updates don't happen right away. That's okay! WordPress performs automatic updates according to timing based on certain transient values, and it is possible for the update check to happen some time before the automatic update routine executes. The Plugin doesn't modify the timing of the automatic update routine; rather, it just tells WordPress which update types are enabled.
83
+
84
+ Also, core now has two separate types of updates: manual updates and automatic updates. When you see the manual upgrade notice, WordPress has received the manual update offer, but has not yet received the automatic update offer. The two offers are fetched based on two different transients, and do not happen at the same time. Automatic core updates are served on a staggered rollout, which means that it may take up to 36 hours for the automatic update to execute after receiving the manual upgrade notice. For Plugins and Themes, you should normally see the automatic update routine execute within 12 hours of receiving the manual upgrade notice.
85
+
86
+ == Changelog ==
87
+
88
+ = 1.3.1 =
89
+ * Bugfix. Correct filter name.
90
+
91
+ = 1.3 =
92
+ * Maintenance Update. Add multisite awareness, more FAQs.
93
+
94
+ = 1.2.1 =
95
+ * Make Advanced Settings UI a bit more intuitive.
96
+
97
+ = 1.2 =
98
+ * Feature Update. Add advanced options toggle, and options for VCS check disabling and debug email.
99
+
100
+ = 1.1.3 =
101
+ * Bugfix. Declare static functions to eliminate e-strict PHP notice.
102
+
103
+ = 1.1.2 =
104
+ * Bugfix. Use selected() instead of checked() in select form fields.
105
+
106
+ = 1.1.1 =
107
+ * Bugfix. Correct variable name typo
108
+
109
+ = 1.1 =
110
+ * Update for WordPress 3.7 final, add update email options.
111
+
112
+ = 1.0 =
113
+ * Initial Release.
update-control.php CHANGED
@@ -1,385 +1,385 @@
1
- <?php
2
- /*
3
- * Plugin Name: Update Control
4
- * Plugin URI: http://github.com/georgestephanis/update-control/
5
- * Description: Adds a manual toggle to the WordPress Admin Interface for managing auto-updates.
6
- * Author: George Stephanis
7
- * Version: 1.3
8
- * Author URI: http://stephanis.info/
9
- */
10
-
11
- /**
12
- * Update Control Class
13
- */
14
- class Stephanis_Update_Control {
15
-
16
- public static function go() {
17
- if ( is_multisite() && ! is_main_site() ) {
18
- // Multisite check
19
- // only run on the main site of a multisite network
20
- return;
21
- } else {
22
- // Let's roll!
23
- add_action( 'admin_init', array( __CLASS__, 'register_settings' ) );
24
- add_action( 'init', array( __CLASS__, 'setup_upgrade_filters' ) );
25
- }
26
- }
27
-
28
- public static function setup_upgrade_filters() {
29
- $options = self::get_options();
30
-
31
- // Do these at priority 1, so other folks can easily override it.
32
-
33
- if ( 'no' == $options['active'] ) {
34
-
35
- add_filter( 'auto_upgrader_disabled', '__return_true', 1 );
36
-
37
- } else {
38
-
39
- if ( in_array( $options['core'], array( 'dev', 'major', 'minor' ) ) ) {
40
- add_filter( 'allow_' . $options['core'] . '_auto_core_updates', '__return_true', 1 );
41
- }
42
-
43
- if ( $options['plugin'] ) {
44
- add_filter( 'auto_update_plugin', '__return_true', 1 );
45
- }
46
-
47
- if ( $options['theme'] ) {
48
- add_filter( 'auto_update_theme', '__return_true', 1 );
49
- }
50
-
51
- if ( ! $options['translation'] ) {
52
- add_filter( 'auto_update_translation', '__return_false', 1 );
53
- }
54
-
55
- if ( $options['vcscheck'] ) {
56
- add_filter( 'automatic_updates_is_vcs_checkout', '__return_true', 1 );
57
- }
58
-
59
- if ( 'no' == $options['emailactive'] || ! ( $options['successemail'] || $options['failureemail'] || $options['criticalemail'] ) ) {
60
- add_filter( 'auto_core_update_send_email', '__return_false', 1 );
61
- } else {
62
- add_filter( 'auto_core_update_send_email', array( __CLASS__, 'filter_email' ), 1, 2 );
63
- }
64
-
65
- if ( $options['debugemail'] ) {
66
- add_filter( 'automatic_updates_send_debug_email ', '__return_true', 1 );
67
- }
68
-
69
- }
70
-
71
- }
72
-
73
- public static function filter_email( $bool, $type ) {
74
- $options = self::get_options();
75
-
76
- if ( 'success' == $type && ! $options['successemail'] )
77
- return false;
78
-
79
- if ( 'fail' == $type && ! $options['failureemail'] )
80
- return false;
81
-
82
- if ( 'critical' == $type && ! $options['criticalemail'] )
83
- return false;
84
-
85
- return $bool;
86
- }
87
-
88
- public static function get_options() {
89
- $defaults = array(
90
- 'active' => 'yes',
91
- 'core' => 'minor',
92
- 'plugin' => false,
93
- 'theme' => false,
94
- 'translation' => true,
95
- 'toggleadvanced' => 'hide',
96
- 'vcscheck' => true,
97
- 'emailactive' => 'yes',
98
- 'successemail' => true,
99
- 'failureemail' => true,
100
- 'criticalemail' => true,
101
- 'debugemail' => false,
102
- );
103
- $args = get_option( 'update_control_options', array() );
104
- return wp_parse_args( $args, $defaults );
105
- }
106
-
107
- public static function get_option( $key ) {
108
- $options = self::get_options();
109
- if ( isset( $options[ $key ] ) ) {
110
- return $options[ $key ];
111
- }
112
- return null;
113
- }
114
-
115
- public static function register_settings() {
116
- add_settings_section(
117
- 'update-control',
118
- esc_html__( 'Automatic Updates', 'update-control' ),
119
- array( __CLASS__, 'update_control_settings_section' ),
120
- 'general'
121
- );
122
-
123
- if ( defined( 'AUTOMATIC_UPDATER_DISABLED' ) && AUTOMATIC_UPDATER_DISABLED ) {
124
- return;
125
- }
126
-
127
- add_settings_field(
128
- 'update_control_active',
129
- sprintf( '<label for="update_control_active">%1$s</label>', __( 'Automatic Updates Enabled?', 'update-control' ) ),
130
- array( __CLASS__, 'update_control_active_cb' ),
131
- 'general',
132
- 'update-control'
133
- );
134
-
135
- add_settings_field(
136
- 'update_control_core',
137
- sprintf( '<label for="update_control_core">%1$s</label>', __( 'Automatic Core Update Level?', 'update-control' ) ),
138
- array( __CLASS__, 'update_control_core_cb' ),
139
- 'general',
140
- 'update-control'
141
- );
142
-
143
- add_settings_field(
144
- 'update_control_plugin',
145
- sprintf( '<label for="update_control_plugin">%1$s</label>', __( 'Permit Automatic Plugin Updates?', 'update-control' ) ),
146
- array( __CLASS__, 'update_control_plugin_cb' ),
147
- 'general',
148
- 'update-control'
149
- );
150
-
151
- add_settings_field(
152
- 'update_control_theme',
153
- sprintf( '<label for="update_control_theme">%1$s</label>', __( 'Permit Automatic Theme Updates?', 'update-control' ) ),
154
- array( __CLASS__, 'update_control_theme_cb' ),
155
- 'general',
156
- 'update-control'
157
- );
158
-
159
- add_settings_field(
160
- 'update_control_translation',
161
- sprintf( '<label for="update_control_translation">%1$s</label>', __( 'Permit Automatic Translation Updates?', 'update-control' ) ),
162
- array( __CLASS__, 'update_control_translation_cb' ),
163
- 'general',
164
- 'update-control'
165
- );
166
-
167
- add_settings_field(
168
- 'update_control_toggleadvanced',
169
- sprintf( '<label for="update_control_toggleadvanced">%1$s</label>', __( 'Advanced Settings', 'update-control' ) ),
170
- array( __CLASS__, 'update_control_toggleadvanced_cb' ),
171
- 'general',
172
- 'update-control'
173
- );
174
-
175
- add_settings_field(
176
- 'update_control_vcscheck',
177
- sprintf( '<label for="update_control_vcscheck">%1$s</label>', __( 'Disable VCS Check?', 'update-control' ) ),
178
- array( __CLASS__, 'update_control_vcscheck_cb' ),
179
- 'general',
180
- 'update-control'
181
- );
182
-
183
- add_settings_field(
184
- 'update_control_email_active',
185
- sprintf( '<label for="update_control_email_active">%1$s</label>', __( 'Update Emails Enabled?', 'update-control' ) ),
186
- array( __CLASS__, 'update_control_email_active_cb' ),
187
- 'general',
188
- 'update-control'
189
- );
190
-
191
- add_settings_field(
192
- 'update_control_email_success',
193
- sprintf( '<label for="update_control_email_success">%1$s</label>', __( 'Send Emails for Successful Updates?', 'update-control' ) ),
194
- array( __CLASS__, 'update_control_email_success_cb' ),
195
- 'general',
196
- 'update-control'
197
- );
198
-
199
- add_settings_field(
200
- 'update_control_email_failure',
201
- sprintf( '<label for="update_control_email_failure">%1$s</label>', __( 'Send Emails for Failed Updates?', 'update-control' ) ),
202
- array( __CLASS__, 'update_control_email_failure_cb' ),
203
- 'general',
204
- 'update-control'
205
- );
206
-
207
- add_settings_field(
208
- 'update_control_email_critical',
209
- sprintf( '<label for="update_control_email_critical">%1$s</label>', __( 'Send Emails for Critically Failed Updates?', 'update-control' ) ),
210
- array( __CLASS__, 'update_control_email_critical_cb' ),
211
- 'general',
212
- 'update-control'
213
- );
214
-
215
- add_settings_field(
216
- 'update_control_email_debug',
217
- sprintf( '<label for="update_control_email_debug">%1$s</label>', __( 'Send Update Debug Emails?', 'update-control' ) ),
218
- array( __CLASS__, 'update_control_email_debug_cb' ),
219
- 'general',
220
- 'update-control'
221
- );
222
-
223
- register_setting( 'general', 'update_control_options', array( __CLASS__, 'sanitize_options' ) );
224
- }
225
-
226
- public static function update_control_settings_section() {
227
- if ( defined( 'AUTOMATIC_UPDATER_DISABLED' ) && AUTOMATIC_UPDATER_DISABLED ) : ?>
228
- <p id="update-control-settings-section">
229
- <?php _e( 'You have the <code>AUTOMATIC_UPDATER_DISABLED</code> constant set. Automatic updates are disabled.', 'update-control' ); ?>
230
- </p>
231
- <?php else : ?>
232
- <p id="update-control-settings-section">
233
- <?php _e( 'This section lets you specify what areas of your WordPress install will be permitted to auto-update.', 'update-control' ); ?>
234
- </p>
235
- <?php
236
- $update_core_obj = get_site_transient( 'update_core' );
237
- $last_checked = $update_core_obj->last_checked;
238
- ?>
239
- <script>
240
- jQuery(document).ready(function($){
241
- $('#update_control_active').change(function(){
242
- if ( 'yes' != $(this).val() ) {
243
- $('.update_control_dependency').attr( 'readonly', 'readonly' );
244
- $('#update_control_toggleadvanced').val('no');
245
- $('.update_control_advanced' ).parent().parent().css( 'display', 'none' );
246
- } else {
247
- $('.update_control_dependency' ).removeAttr( 'readonly' );
248
- }
249
- }).trigger('change');
250
-
251
- $('#update_control_toggleadvanced').change(function(){
252
- if ( 'hide' != $(this).val() ) {
253
- $('.update_control_advanced').parent().parent().css( { 'display' : 'table-row' } );
254
- $('.update_control_advanced').parent().siblings( 'th' ).css( { 'display' : 'block', 'padding-left' : '20px' } );
255
- } else {
256
- $('.update_control_advanced' ).parent().parent().css( 'display', 'none' );
257
- }
258
- }).trigger('change');
259
-
260
- $('#update_control_email_active').change(function(){
261
- if ( 'yes' != $(this).val() ) {
262
- $('.update_control_email_dependency.update_control_advanced').attr( 'readonly', 'readonly' );
263
- $('.update_control_email_dependency.update_control_advanced').parent().siblings( 'th' ).children().css( { 'padding-left' : '20px', 'display' : 'block' } );
264
- } else {
265
- $('.update_control_email_dependency.update_control_advanced' ).removeAttr( 'readonly' );
266
- $('.update_control_email_dependency.update_control_advanced').parent().siblings( 'th' ).children().css( { 'padding-left' : '20px', 'display' : 'block' } );
267
- }
268
- }).trigger('change');
269
- });
270
- </script>
271
- <style>
272
- .update_control_dependency[readonly],
273
- .update_control_email_dependency[readonly] {
274
- opacity: 0.4;
275
- }
276
- </style>
277
- <?php endif;
278
- }
279
-
280
- public static function update_control_active_cb() {
281
- ?>
282
- <select id="update_control_active" name="update_control_options[active]">
283
- <option <?php selected( 'yes' == self::get_option( 'active' ) ); ?> value="yes"><?php _e( 'Yes', 'update-control' ); ?></option>
284
- <option <?php selected( 'no' == self::get_option( 'active' ) ); ?> value="no"><?php _e( 'No', 'update-control' ); ?></option>
285
- </select>
286
- <?php
287
- }
288
-
289
- public static function update_control_core_cb() {
290
- ?>
291
- <select class="update_control_dependency" id="update_control_core" name="update_control_options[core]">
292
- <option <?php selected( 'minor' == self::get_option( 'core' ) ); ?> value="minor"><?php _e( 'Minor Updates', 'update-control' ); ?></option>
293
- <option <?php selected( 'major' == self::get_option( 'core' ) ); ?> value="major"><?php _e( 'Major Updates', 'update-control' ); ?></option>
294
- <option <?php selected( 'dev' == self::get_option( 'core' ) ); ?> value="dev"><?php _e( 'Development Updates', 'update-control' ); ?></option>
295
- </select>
296
- <?php
297
- }
298
-
299
- public static function update_control_plugin_cb() {
300
- ?>
301
- <input type="checkbox" class="update_control_dependency" id="update_control_plugin" name="update_control_options[plugin]" <?php checked( self::get_option( 'plugin' ) ); ?> />
302
- <?php
303
- }
304
-
305
- public static function update_control_theme_cb() {
306
- ?>
307
- <input type="checkbox" class="update_control_dependency" id="update_control_theme" name="update_control_options[theme]" <?php checked( self::get_option( 'theme' ) ); ?> />
308
- <?php
309
- }
310
-
311
- public static function update_control_translation_cb() {
312
- ?>
313
- <input type="checkbox" class="update_control_dependency" id="update_control_translation" name="update_control_options[translation]" <?php checked( self::get_option( 'translation' ) ); ?> />
314
- <?php
315
- }
316
-
317
- public static function update_control_toggleadvanced_cb() {
318
- ?>
319
- <select class="update_control_dependency" id="update_control_toggleadvanced" name="update_control_options[toggleadvanced]">
320
- <option <?php selected( 'show' == self::get_option( 'toggleadvanced' ) ); ?> value="show"><?php _e( 'Show', 'update-control' ); ?></option>
321
- <option <?php selected( 'hide' == self::get_option( 'toggleadvanced' ) ); ?> value="hide"><?php _e( 'Hide', 'update-control' ); ?></option>
322
- </select>
323
- <?php
324
- }
325
-
326
- public static function update_control_vcscheck_cb() {
327
- ?>
328
- <input type="checkbox" class="update_control_advanced" id="update_control_vcscheck" name="update_control_options[vcscheck]" <?php checked( self::get_option( 'vcscheck' ) ); ?> />
329
- <?php
330
- }
331
-
332
- public static function update_control_email_active_cb() {
333
- ?>
334
- <select class="update_control_advanced" id="update_control_email_active" name="update_control_options[emailactive]">
335
- <option <?php selected( 'yes' == self::get_option( 'emailactive' ) ); ?> value="yes"><?php _e( 'Yes', 'update-control' ); ?></option>
336
- <option <?php selected( 'no' == self::get_option( 'emailactive' ) ); ?> value="no"><?php _e( 'No', 'update-control' ); ?></option>
337
- </select>
338
- <?php
339
- }
340
-
341
- public static function update_control_email_success_cb() {
342
- ?>
343
- <input type="checkbox" class="update_control_email_dependency update_control_advanced" id="update_control_email_success" name="update_control_options[successemail]" <?php checked( self::get_option( 'successemail' ) ); ?> />
344
- <?php
345
- }
346
-
347
- public static function update_control_email_failure_cb() {
348
- ?>
349
- <input type="checkbox" class="update_control_email_dependency update_control_advanced" id="update_control_email_failure" name="update_control_options[failureemail]" <?php checked( self::get_option( 'failureemail' ) ); ?> />
350
- <?php
351
- }
352
-
353
- public static function update_control_email_critical_cb() {
354
- ?>
355
- <input type="checkbox" class="update_control_email_dependency update_control_advanced" id="update_control_email_critical" name="update_control_options[criticalemail]" <?php checked( self::get_option( 'criticalemail' ) ); ?> />
356
- <?php
357
- }
358
-
359
- public static function update_control_email_debug_cb() {
360
- ?>
361
- <input type="checkbox" class="update_control_advanced" id="update_control_email_debug" name="update_control_options[debugemail]" <?php checked( self::get_option( 'debugemail' ) ); ?> />
362
- <?php
363
- }
364
-
365
- public static function sanitize_options( $options ) {
366
- $options = (array) $options;
367
-
368
- $options['active'] = ( in_array( $options['active'], array( 'yes', 'no' ) ) ? $options['active'] : 'yes' );
369
- $options['core'] = ( in_array( $options['core'], array( 'minor', 'major', 'dev' ) ) ? $options['core'] : 'minor' );
370
- $options['plugin'] = ! empty( $options['plugin'] );
371
- $options['theme'] = ! empty( $options['theme'] );
372
- $options['translation'] = ! empty( $options['translation'] );
373
- $options['toggleadvanced'] = 'hide';
374
- $options['vcscheck'] = ! empty( $options['vcscheck'] );
375
- $options['emailactive'] = ( in_array( $options['emailactive'], array( 'yes', 'no' ) ) ? $options['emailactive'] : 'yes' );
376
- $options['successemail'] = ! empty( $options['successemail'] );
377
- $options['failureemail'] = ! empty( $options['failureemail'] );
378
- $options['criticalemail'] = ! empty( $options['criticalemail'] );
379
- $options['debugemail'] = ! empty( $options['debugemail'] );
380
-
381
- return $options;
382
- }
383
-
384
- }
385
  add_action( 'init', array( 'Stephanis_Update_Control', 'go' ), 0 );
1
+ <?php
2
+ /*
3
+ * Plugin Name: Update Control
4
+ * Plugin URI: http://github.com/georgestephanis/update-control/
5
+ * Description: Adds a manual toggle to the WordPress Admin Interface for managing auto-updates.
6
+ * Author: George Stephanis, Chip Bennett
7
+ * Version: 1.3.1
8
+ * Author URI: http://stephanis.info/
9
+ */
10
+
11
+ /**
12
+ * Update Control Class
13
+ */
14
+ class Stephanis_Update_Control {
15
+
16
+ public static function go() {
17
+ if ( is_multisite() && ! is_main_site() ) {
18
+ // Multisite check
19
+ // only run on the main site of a multisite network
20
+ return;
21
+ } else {
22
+ // Let's roll!
23
+ add_action( 'admin_init', array( __CLASS__, 'register_settings' ) );
24
+ add_action( 'init', array( __CLASS__, 'setup_upgrade_filters' ) );
25
+ }
26
+ }
27
+
28
+ public static function setup_upgrade_filters() {
29
+ $options = self::get_options();
30
+
31
+ // Do these at priority 1, so other folks can easily override it.
32
+
33
+ if ( 'no' == $options['active'] ) {
34
+
35
+ add_filter( 'auto_updater_disabled', '__return_true', 1 );
36
+
37
+ } else {
38
+
39
+ if ( in_array( $options['core'], array( 'dev', 'major', 'minor' ) ) ) {
40
+ add_filter( 'allow_' . $options['core'] . '_auto_core_updates', '__return_true', 1 );
41
+ }
42
+
43
+ if ( $options['plugin'] ) {
44
+ add_filter( 'auto_update_plugin', '__return_true', 1 );
45
+ }
46
+
47
+ if ( $options['theme'] ) {
48
+ add_filter( 'auto_update_theme', '__return_true', 1 );
49
+ }
50
+
51
+ if ( ! $options['translation'] ) {
52
+ add_filter( 'auto_update_translation', '__return_false', 1 );
53
+ }
54
+
55
+ if ( $options['vcscheck'] ) {
56
+ add_filter( 'automatic_updates_is_vcs_checkout', '__return_true', 1 );
57
+ }
58
+
59
+ if ( 'no' == $options['emailactive'] || ! ( $options['successemail'] || $options['failureemail'] || $options['criticalemail'] ) ) {
60
+ add_filter( 'auto_core_update_send_email', '__return_false', 1 );
61
+ } else {
62
+ add_filter( 'auto_core_update_send_email', array( __CLASS__, 'filter_email' ), 1, 2 );
63
+ }
64
+
65
+ if ( $options['debugemail'] ) {
66
+ add_filter( 'automatic_updates_send_debug_email ', '__return_true', 1 );
67
+ }
68
+
69
+ }
70
+
71
+ }
72
+
73
+ public static function filter_email( $bool, $type ) {
74
+ $options = self::get_options();
75
+
76
+ if ( 'success' == $type && ! $options['successemail'] )
77
+ return false;
78
+
79
+ if ( 'fail' == $type && ! $options['failureemail'] )
80
+ return false;
81
+
82
+ if ( 'critical' == $type && ! $options['criticalemail'] )
83
+ return false;
84
+
85
+ return $bool;
86
+ }
87
+
88
+ public static function get_options() {
89
+ $defaults = array(
90
+ 'active' => 'yes',
91
+ 'core' => 'minor',
92
+ 'plugin' => false,
93
+ 'theme' => false,
94
+ 'translation' => true,
95
+ 'toggleadvanced' => 'hide',
96
+ 'vcscheck' => true,
97
+ 'emailactive' => 'yes',
98
+ 'successemail' => true,
99
+ 'failureemail' => true,
100
+ 'criticalemail' => true,
101
+ 'debugemail' => false,
102
+ );
103
+ $args = get_option( 'update_control_options', array() );
104
+ return wp_parse_args( $args, $defaults );
105
+ }
106
+
107
+ public static function get_option( $key ) {
108
+ $options = self::get_options();
109
+ if ( isset( $options[ $key ] ) ) {
110
+ return $options[ $key ];
111
+ }
112
+ return null;
113
+ }
114
+
115
+ public static function register_settings() {
116
+ add_settings_section(
117
+ 'update-control',
118
+ esc_html__( 'Automatic Updates', 'update-control' ),
119
+ array( __CLASS__, 'update_control_settings_section' ),
120
+ 'general'
121
+ );
122
+
123
+ if ( defined( 'AUTOMATIC_UPDATER_DISABLED' ) && AUTOMATIC_UPDATER_DISABLED ) {
124
+ return;
125
+ }
126
+
127
+ add_settings_field(
128
+ 'update_control_active',
129
+ sprintf( '<label for="update_control_active">%1$s</label>', __( 'Automatic Updates Enabled?', 'update-control' ) ),
130
+ array( __CLASS__, 'update_control_active_cb' ),
131
+ 'general',
132
+ 'update-control'
133
+ );
134
+
135
+ add_settings_field(
136
+ 'update_control_core',
137
+ sprintf( '<label for="update_control_core">%1$s</label>', __( 'Automatic Core Update Level?', 'update-control' ) ),
138
+ array( __CLASS__, 'update_control_core_cb' ),
139
+ 'general',
140
+ 'update-control'
141
+ );
142
+
143
+ add_settings_field(
144
+ 'update_control_plugin',
145
+ sprintf( '<label for="update_control_plugin">%1$s</label>', __( 'Permit Automatic Plugin Updates?', 'update-control' ) ),
146
+ array( __CLASS__, 'update_control_plugin_cb' ),
147
+ 'general',
148
+ 'update-control'
149
+ );
150
+
151
+ add_settings_field(
152
+ 'update_control_theme',
153
+ sprintf( '<label for="update_control_theme">%1$s</label>', __( 'Permit Automatic Theme Updates?', 'update-control' ) ),
154
+ array( __CLASS__, 'update_control_theme_cb' ),
155
+ 'general',
156
+ 'update-control'
157
+ );
158
+
159
+ add_settings_field(
160
+ 'update_control_translation',
161
+ sprintf( '<label for="update_control_translation">%1$s</label>', __( 'Permit Automatic Translation Updates?', 'update-control' ) ),
162
+ array( __CLASS__, 'update_control_translation_cb' ),
163
+ 'general',
164
+ 'update-control'
165
+ );
166
+
167
+ add_settings_field(
168
+ 'update_control_toggleadvanced',
169
+ sprintf( '<label for="update_control_toggleadvanced">%1$s</label>', __( 'Advanced Settings', 'update-control' ) ),
170
+ array( __CLASS__, 'update_control_toggleadvanced_cb' ),
171
+ 'general',
172
+ 'update-control'
173
+ );
174
+
175
+ add_settings_field(
176
+ 'update_control_vcscheck',
177
+ sprintf( '<label for="update_control_vcscheck">%1$s</label>', __( 'Disable VCS Check?', 'update-control' ) ),
178
+ array( __CLASS__, 'update_control_vcscheck_cb' ),
179
+ 'general',
180
+ 'update-control'
181
+ );
182
+
183
+ add_settings_field(
184
+ 'update_control_email_active',
185
+ sprintf( '<label for="update_control_email_active">%1$s</label>', __( 'Update Emails Enabled?', 'update-control' ) ),
186
+ array( __CLASS__, 'update_control_email_active_cb' ),
187
+ 'general',
188
+ 'update-control'
189
+ );
190
+
191
+ add_settings_field(
192
+ 'update_control_email_success',
193
+ sprintf( '<label for="update_control_email_success">%1$s</label>', __( 'Send Emails for Successful Updates?', 'update-control' ) ),
194
+ array( __CLASS__, 'update_control_email_success_cb' ),
195
+ 'general',
196
+ 'update-control'
197
+ );
198
+
199
+ add_settings_field(
200
+ 'update_control_email_failure',
201
+ sprintf( '<label for="update_control_email_failure">%1$s</label>', __( 'Send Emails for Failed Updates?', 'update-control' ) ),
202
+ array( __CLASS__, 'update_control_email_failure_cb' ),
203
+ 'general',
204
+ 'update-control'
205
+ );
206
+
207
+ add_settings_field(
208
+ 'update_control_email_critical',
209
+ sprintf( '<label for="update_control_email_critical">%1$s</label>', __( 'Send Emails for Critically Failed Updates?', 'update-control' ) ),
210
+ array( __CLASS__, 'update_control_email_critical_cb' ),
211
+ 'general',
212
+ 'update-control'
213
+ );
214
+
215
+ add_settings_field(
216
+ 'update_control_email_debug',
217
+ sprintf( '<label for="update_control_email_debug">%1$s</label>', __( 'Send Update Debug Emails?', 'update-control' ) ),
218
+ array( __CLASS__, 'update_control_email_debug_cb' ),
219
+ 'general',
220
+ 'update-control'
221
+ );
222
+
223
+ register_setting( 'general', 'update_control_options', array( __CLASS__, 'sanitize_options' ) );
224
+ }
225
+
226
+ public static function update_control_settings_section() {
227
+ if ( defined( 'AUTOMATIC_UPDATER_DISABLED' ) && AUTOMATIC_UPDATER_DISABLED ) : ?>
228
+ <p id="update-control-settings-section">
229
+ <?php _e( 'You have the <code>AUTOMATIC_UPDATER_DISABLED</code> constant set. Automatic updates are disabled.', 'update-control' ); ?>
230
+ </p>
231
+ <?php else : ?>
232
+ <p id="update-control-settings-section">
233
+ <?php _e( 'This section lets you specify what areas of your WordPress install will be permitted to auto-update.', 'update-control' ); ?>
234
+ </p>
235
+ <?php
236
+ $update_core_obj = get_site_transient( 'update_core' );
237
+ $last_checked = $update_core_obj->last_checked;
238
+ ?>
239
+ <script>
240
+ jQuery(document).ready(function($){
241
+ $('#update_control_active').change(function(){
242
+ if ( 'yes' != $(this).val() ) {
243
+ $('.update_control_dependency').attr( 'readonly', 'readonly' );
244
+ $('#update_control_toggleadvanced').val('no');
245
+ $('.update_control_advanced' ).parent().parent().css( 'display', 'none' );
246
+ } else {
247
+ $('.update_control_dependency' ).removeAttr( 'readonly' );
248
+ }
249
+ }).trigger('change');
250
+
251
+ $('#update_control_toggleadvanced').change(function(){
252
+ if ( 'hide' != $(this).val() ) {
253
+ $('.update_control_advanced').parent().parent().css( { 'display' : 'table-row' } );
254
+ $('.update_control_advanced').parent().siblings( 'th' ).css( { 'display' : 'block', 'padding-left' : '20px' } );
255
+ } else {
256
+ $('.update_control_advanced' ).parent().parent().css( 'display', 'none' );
257
+ }
258
+ }).trigger('change');
259
+
260
+ $('#update_control_email_active').change(function(){
261
+ if ( 'yes' != $(this).val() ) {
262
+ $('.update_control_email_dependency.update_control_advanced').attr( 'readonly', 'readonly' );
263
+ $('.update_control_email_dependency.update_control_advanced').parent().siblings( 'th' ).children().css( { 'padding-left' : '20px', 'display' : 'block' } );
264
+ } else {
265
+ $('.update_control_email_dependency.update_control_advanced' ).removeAttr( 'readonly' );
266
+ $('.update_control_email_dependency.update_control_advanced').parent().siblings( 'th' ).children().css( { 'padding-left' : '20px', 'display' : 'block' } );
267
+ }
268
+ }).trigger('change');
269
+ });
270
+ </script>
271
+ <style>
272
+ .update_control_dependency[readonly],
273
+ .update_control_email_dependency[readonly] {
274
+ opacity: 0.4;
275
+ }
276
+ </style>
277
+ <?php endif;
278
+ }
279
+
280
+ public static function update_control_active_cb() {
281
+ ?>
282
+ <select id="update_control_active" name="update_control_options[active]">
283
+ <option <?php selected( 'yes' == self::get_option( 'active' ) ); ?> value="yes"><?php _e( 'Yes', 'update-control' ); ?></option>
284
+ <option <?php selected( 'no' == self::get_option( 'active' ) ); ?> value="no"><?php _e( 'No', 'update-control' ); ?></option>
285
+ </select>
286
+ <?php
287
+ }
288
+
289
+ public static function update_control_core_cb() {
290
+ ?>
291
+ <select class="update_control_dependency" id="update_control_core" name="update_control_options[core]">
292
+ <option <?php selected( 'minor' == self::get_option( 'core' ) ); ?> value="minor"><?php _e( 'Minor Updates', 'update-control' ); ?></option>
293
+ <option <?php selected( 'major' == self::get_option( 'core' ) ); ?> value="major"><?php _e( 'Major Updates', 'update-control' ); ?></option>
294
+ <option <?php selected( 'dev' == self::get_option( 'core' ) ); ?> value="dev"><?php _e( 'Development Updates', 'update-control' ); ?></option>
295
+ </select>
296
+ <?php
297
+ }
298
+
299
+ public static function update_control_plugin_cb() {
300
+ ?>
301
+ <input type="checkbox" class="update_control_dependency" id="update_control_plugin" name="update_control_options[plugin]" <?php checked( self::get_option( 'plugin' ) ); ?> />
302
+ <?php
303
+ }
304
+
305
+ public static function update_control_theme_cb() {
306
+ ?>
307
+ <input type="checkbox" class="update_control_dependency" id="update_control_theme" name="update_control_options[theme]" <?php checked( self::get_option( 'theme' ) ); ?> />
308
+ <?php
309
+ }
310
+
311
+ public static function update_control_translation_cb() {
312
+ ?>
313
+ <input type="checkbox" class="update_control_dependency" id="update_control_translation" name="update_control_options[translation]" <?php checked( self::get_option( 'translation' ) ); ?> />
314
+ <?php
315
+ }
316
+
317
+ public static function update_control_toggleadvanced_cb() {
318
+ ?>
319
+ <select class="update_control_dependency" id="update_control_toggleadvanced" name="update_control_options[toggleadvanced]">
320
+ <option <?php selected( 'show' == self::get_option( 'toggleadvanced' ) ); ?> value="show"><?php _e( 'Show', 'update-control' ); ?></option>
321
+ <option <?php selected( 'hide' == self::get_option( 'toggleadvanced' ) ); ?> value="hide"><?php _e( 'Hide', 'update-control' ); ?></option>
322
+ </select>
323
+ <?php
324
+ }
325
+
326
+ public static function update_control_vcscheck_cb() {
327
+ ?>
328
+ <input type="checkbox" class="update_control_advanced" id="update_control_vcscheck" name="update_control_options[vcscheck]" <?php checked( self::get_option( 'vcscheck' ) ); ?> />
329
+ <?php
330
+ }
331
+
332
+ public static function update_control_email_active_cb() {
333
+ ?>
334
+ <select class="update_control_advanced" id="update_control_email_active" name="update_control_options[emailactive]">
335
+ <option <?php selected( 'yes' == self::get_option( 'emailactive' ) ); ?> value="yes"><?php _e( 'Yes', 'update-control' ); ?></option>
336
+ <option <?php selected( 'no' == self::get_option( 'emailactive' ) ); ?> value="no"><?php _e( 'No', 'update-control' ); ?></option>
337
+ </select>
338
+ <?php
339
+ }
340
+
341
+ public static function update_control_email_success_cb() {
342
+ ?>
343
+ <input type="checkbox" class="update_control_email_dependency update_control_advanced" id="update_control_email_success" name="update_control_options[successemail]" <?php checked( self::get_option( 'successemail' ) ); ?> />
344
+ <?php
345
+ }
346
+
347
+ public static function update_control_email_failure_cb() {
348
+ ?>
349
+ <input type="checkbox" class="update_control_email_dependency update_control_advanced" id="update_control_email_failure" name="update_control_options[failureemail]" <?php checked( self::get_option( 'failureemail' ) ); ?> />
350
+ <?php
351
+ }
352
+
353
+ public static function update_control_email_critical_cb() {
354
+ ?>
355
+ <input type="checkbox" class="update_control_email_dependency update_control_advanced" id="update_control_email_critical" name="update_control_options[criticalemail]" <?php checked( self::get_option( 'criticalemail' ) ); ?> />
356
+ <?php
357
+ }
358
+
359
+ public static function update_control_email_debug_cb() {
360
+ ?>
361
+ <input type="checkbox" class="update_control_advanced" id="update_control_email_debug" name="update_control_options[debugemail]" <?php checked( self::get_option( 'debugemail' ) ); ?> />
362
+ <?php
363
+ }
364
+
365
+ public static function sanitize_options( $options ) {
366
+ $options = (array) $options;
367
+
368
+ $options['active'] = ( in_array( $options['active'], array( 'yes', 'no' ) ) ? $options['active'] : 'yes' );
369
+ $options['core'] = ( in_array( $options['core'], array( 'minor', 'major', 'dev' ) ) ? $options['core'] : 'minor' );
370
+ $options['plugin'] = ! empty( $options['plugin'] );
371
+ $options['theme'] = ! empty( $options['theme'] );
372
+ $options['translation'] = ! empty( $options['translation'] );
373
+ $options['toggleadvanced'] = 'hide';
374
+ $options['vcscheck'] = ! empty( $options['vcscheck'] );
375
+ $options['emailactive'] = ( in_array( $options['emailactive'], array( 'yes', 'no' ) ) ? $options['emailactive'] : 'yes' );
376
+ $options['successemail'] = ! empty( $options['successemail'] );
377
+ $options['failureemail'] = ! empty( $options['failureemail'] );
378
+ $options['criticalemail'] = ! empty( $options['criticalemail'] );
379
+ $options['debugemail'] = ! empty( $options['debugemail'] );
380
+
381
+ return $options;
382
+ }
383
+
384
+ }
385
  add_action( 'init', array( 'Stephanis_Update_Control', 'go' ), 0 );