Update Control - Version 1.1.3

Version Description

  • Bugfix. Declare static functions to eliminate e-strict PHP notice.
Download this release

Release Info

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

Code changes from version 1.1.2 to 1.1.3

Files changed (2) hide show
  1. readme.txt +83 -28
  2. update-control.php +298 -298
readme.txt CHANGED
@@ -1,28 +1,83 @@
1
- === Plugin Name ===
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.1.2
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
- == Changelog ==
17
-
18
- = 1.1.2 =
19
- * Bugfix. Use selected() instead of checked() in select form fields.
20
-
21
- = 1.1.1 =
22
- * Bugfix. Correct variable name typo
23
-
24
- = 1.1 =
25
- * Update for WordPress 3.7 final, add update email options.
26
-
27
- = 1.0 =
28
- * 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.7
6
+ Stable tag: 1.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
+ = How do I use this Plugin in a multisite network? =
40
+
41
+ Activate the Plugin on the main network site, and configure options via Settings -> General.
42
+
43
+ = What do "Minor", "Major", and "Development" core updates mean? =
44
+
45
+ * "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.
46
+ * "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".
47
+ * "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".
48
+
49
+ = Which setting should I use? =
50
+
51
+ Core Updates:
52
+
53
+ * If you want minor versions to update automatically (default WordPress core behavior): leave "Automatic Core Update Level?" set to "Minor".
54
+ * If you want both minor and major versions to update automatically: set "Automatic Core Update Level?" to "Major".
55
+ * If you want bleeding-edge nightlies: set "Automatic Core Update Level?" to "Development"
56
+ * If you want to disable core updates altogether: set "Automatic Updates Enabled?" to "no"
57
+
58
+ Plugin/Theme/Translation Updates:
59
+
60
+ * If you disable updates, Plugin, Theme, and Translation updates will also be disabled
61
+ * Separately enable Plugin, Theme, and Translation updates via the appropriate checkboxes
62
+
63
+ Update Result Emails
64
+
65
+ * By default, WordPress sends an update result email for successful, failed, and critically failed updates
66
+ * Selectively disable emails for each result type via the appropriate checkboxes
67
+
68
+ == Changelog ==
69
+
70
+ = 1.1.3 =
71
+ * Bugfix. Declare static functions to eliminate e-strict PHP notice.
72
+
73
+ = 1.1.2 =
74
+ * Bugfix. Use selected() instead of checked() in select form fields.
75
+
76
+ = 1.1.1 =
77
+ * Bugfix. Correct variable name typo
78
+
79
+ = 1.1 =
80
+ * Update for WordPress 3.7 final, add update email options.
81
+
82
+ = 1.0 =
83
+ * Initial Release.
update-control.php CHANGED
@@ -1,298 +1,298 @@
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.1.2
8
- * Author URI: http://stephanis.info/
9
- */
10
-
11
- /**
12
- * Update Control Class
13
- */
14
- class Stephanis_Update_Control {
15
-
16
- function go() {
17
- add_action( 'admin_init', array( __CLASS__, 'register_settings' ) );
18
- add_action( 'init', array( __CLASS__, 'setup_upgrade_filters' ) );
19
- }
20
-
21
- function setup_upgrade_filters() {
22
- $options = self::get_options();
23
-
24
- // Do these at priority 1, so other folks can easily override it.
25
-
26
- if ( 'no' == $options['active'] ) {
27
- add_filter( 'auto_upgrader_disabled', '__return_true', 1 );
28
- } else {
29
-
30
- if ( in_array( $options['core'], array( 'dev', 'major', 'minor' ) ) ) {
31
- add_filter( 'allow_' . $options['core'] . '_auto_core_updates', '__return_true', 1 );
32
- }
33
-
34
- if ( $options['plugin'] ) {
35
- add_filter( 'auto_update_plugin', '__return_true', 1 );
36
- }
37
-
38
- if ( $options['theme'] ) {
39
- add_filter( 'auto_update_theme', '__return_true', 1 );
40
- }
41
-
42
- if ( ! $options['translation'] ) {
43
- add_filter( 'auto_update_translation', '__return_false', 1 );
44
- }
45
-
46
- }
47
-
48
- if ( 'no' == $options['emailactive'] || ! ( $options['successemail'] || $options['failureemail'] || $options['criticalemail'] ) ) {
49
- add_filter( 'auto_core_update_send_email', '__return_false', 1 );
50
- } else {
51
- add_filter( 'auto_core_update_send_email', array( __CLASS__, 'filter_email' ), 1, 2 );
52
- }
53
-
54
- }
55
-
56
- function filter_email( $bool, $type ) {
57
- $options = self::get_options();
58
-
59
- if ( 'success' == $type && ! $options['successemail'] )
60
- return false;
61
-
62
- if ( 'fail' == $type && ! $options['failureemail'] )
63
- return false;
64
-
65
- if ( 'critical' == $type && ! $options['criticalemail'] )
66
- return false;
67
-
68
- return $bool;
69
- }
70
-
71
- function get_options() {
72
- $defaults = array(
73
- 'active' => 'yes',
74
- 'core' => 'minor',
75
- 'plugin' => false,
76
- 'theme' => false,
77
- 'translation' => true,
78
- 'emailactive' => 'yes',
79
- 'successemail' => true,
80
- 'failureemail' => true,
81
- 'criticalemail' => true,
82
- );
83
- $args = get_option( 'update_control_options', array() );
84
- return wp_parse_args( $args, $defaults );
85
- }
86
-
87
- function get_option( $key ) {
88
- $options = self::get_options();
89
- if ( isset( $options[ $key ] ) ) {
90
- return $options[ $key ];
91
- }
92
- return null;
93
- }
94
-
95
- function register_settings() {
96
- add_settings_section(
97
- 'update-control',
98
- esc_html__( 'Automatic Updates', 'update-control' ),
99
- array( __CLASS__, 'update_control_settings_section' ),
100
- 'general'
101
- );
102
-
103
- if ( defined( 'AUTOMATIC_UPDATER_DISABLED' ) && AUTOMATIC_UPDATER_DISABLED ) {
104
- return;
105
- }
106
-
107
- add_settings_field(
108
- 'update_control_active',
109
- sprintf( '<label for="update_control_active">%1$s</label>', __( 'Automatic Updates Enabled?', 'update-control' ) ),
110
- array( __CLASS__, 'update_control_active_cb' ),
111
- 'general',
112
- 'update-control'
113
- );
114
-
115
- add_settings_field(
116
- 'update_control_core',
117
- sprintf( '<label for="update_control_core">%1$s</label>', __( 'Automatic Major Core Updates?', 'update-control' ) ),
118
- array( __CLASS__, 'update_control_core_cb' ),
119
- 'general',
120
- 'update-control'
121
- );
122
-
123
- add_settings_field(
124
- 'update_control_plugin',
125
- sprintf( '<label for="update_control_plugin">%1$s</label>', __( 'Permit Automatic Plugin Updates?', 'update-control' ) ),
126
- array( __CLASS__, 'update_control_plugin_cb' ),
127
- 'general',
128
- 'update-control'
129
- );
130
-
131
- add_settings_field(
132
- 'update_control_theme',
133
- sprintf( '<label for="update_control_theme">%1$s</label>', __( 'Permit Automatic Theme Updates?', 'update-control' ) ),
134
- array( __CLASS__, 'update_control_theme_cb' ),
135
- 'general',
136
- 'update-control'
137
- );
138
-
139
- add_settings_field(
140
- 'update_control_translation',
141
- sprintf( '<label for="update_control_translation">%1$s</label>', __( 'Permit Automatic Translation Updates?', 'update-control' ) ),
142
- array( __CLASS__, 'update_control_translation_cb' ),
143
- 'general',
144
- 'update-control'
145
- );
146
-
147
- add_settings_field(
148
- 'update_control_email_active',
149
- sprintf( '<label for="update_control_email_active">%1$s</label>', __( 'Update Emails Enabled?', 'update-control' ) ),
150
- array( __CLASS__, 'update_control_email_active_cb' ),
151
- 'general',
152
- 'update-control'
153
- );
154
-
155
- add_settings_field(
156
- 'update_control_email_success',
157
- sprintf( '<label for="update_control_email_success">%1$s</label>', __( 'Send Emails for Successful Updates?', 'update-control' ) ),
158
- array( __CLASS__, 'update_control_email_success_cb' ),
159
- 'general',
160
- 'update-control'
161
- );
162
-
163
- add_settings_field(
164
- 'update_control_email_failure',
165
- sprintf( '<label for="update_control_email_failure">%1$s</label>', __( 'Send Emails for Failed Updates?', 'update-control' ) ),
166
- array( __CLASS__, 'update_control_email_failure_cb' ),
167
- 'general',
168
- 'update-control'
169
- );
170
-
171
- add_settings_field(
172
- 'update_control_email_critical',
173
- sprintf( '<label for="update_control_email_critical">%1$s</label>', __( 'Send Emails for Critically Failed Updates?', 'update-control' ) ),
174
- array( __CLASS__, 'update_control_email_critical_cb' ),
175
- 'general',
176
- 'update-control'
177
- );
178
-
179
- register_setting( 'general', 'update_control_options', array( __CLASS__, 'sanitize_options' ) );
180
- }
181
-
182
- function update_control_settings_section() {
183
- if ( defined( 'AUTOMATIC_UPDATER_DISABLED' ) && AUTOMATIC_UPDATER_DISABLED ) : ?>
184
- <p id="update-control-settings-section">
185
- <?php _e( 'You have the <code>AUTOMATIC_UPDATER_DISABLED</code> constant set. Automatic updates are disabled.', 'update-control' ); ?>
186
- </p>
187
- <?php else : ?>
188
- <p id="update-control-settings-section">
189
- <?php _e( 'This section lets you specify what areas of your WordPress install will be permitted to auto-update.', 'update-control' ); ?>
190
- </p>
191
- <script>
192
- jQuery(document).ready(function($){
193
- $('#update_control_active').change(function(){
194
- if ( 'yes' != $(this).val() )
195
- $('.update_control_dependency').attr( 'readonly', 'readonly' );
196
- else
197
- $('.update_control_dependency' ).removeAttr( 'readonly' );
198
- }).trigger('change');
199
-
200
- $('#update_control_email_active').change(function(){
201
- if ( 'yes' != $(this).val() )
202
- $('.update_control_email_dependency').attr( 'readonly', 'readonly' );
203
- else
204
- $('.update_control_email_dependency' ).removeAttr( 'readonly' );
205
- }).trigger('change');
206
- });
207
- </script>
208
- <style>
209
- .update_control_dependency[readonly],
210
- .update_control_email_dependency[readonly] {
211
- opacity: 0.4;
212
- }
213
- </style>
214
- <?php endif;
215
- }
216
-
217
- function update_control_active_cb() {
218
- ?>
219
- <select id="update_control_active" name="update_control_options[active]">
220
- <option <?php selected( 'yes' == self::get_option( 'active' ) ); ?> value="yes"><?php _e( 'Yes', 'update-control' ); ?></option>
221
- <option <?php selected( 'no' == self::get_option( 'active' ) ); ?> value="no"><?php _e( 'No', 'update-control' ); ?></option>
222
- </select>
223
- <?php
224
- }
225
-
226
- function update_control_core_cb() {
227
- ?>
228
- <select class="update_control_dependency" id="update_control_core" name="update_control_options[core]">
229
- <option <?php selected( 'minor' == self::get_option( 'core' ) ); ?> value="minor"><?php _e( 'Minor Updates', 'update-control' ); ?></option>
230
- <option <?php selected( 'major' == self::get_option( 'core' ) ); ?> value="major"><?php _e( 'Major Updates', 'update-control' ); ?></option>
231
- <option <?php selected( 'dev' == self::get_option( 'core' ) ); ?> value="dev"><?php _e( 'Development Updates', 'update-control' ); ?></option>
232
- </select>
233
- <?php
234
- }
235
-
236
- function update_control_plugin_cb() {
237
- ?>
238
- <input type="checkbox" class="update_control_dependency" id="update_control_plugin" name="update_control_options[plugin]" <?php checked( self::get_option( 'plugin' ) ); ?> />
239
- <?php
240
- }
241
-
242
- function update_control_theme_cb() {
243
- ?>
244
- <input type="checkbox" class="update_control_dependency" id="update_control_theme" name="update_control_options[theme]" <?php checked( self::get_option( 'theme' ) ); ?> />
245
- <?php
246
- }
247
-
248
- function update_control_translation_cb() {
249
- ?>
250
- <input type="checkbox" class="update_control_dependency" id="update_control_translation" name="update_control_options[translation]" <?php checked( self::get_option( 'translation' ) ); ?> />
251
- <?php
252
- }
253
-
254
- function update_control_email_active_cb() {
255
- ?>
256
- <select id="update_control_email_active" name="update_control_options[emailactive]">
257
- <option <?php selected( 'yes' == self::get_option( 'emailactive' ) ); ?> value="yes"><?php _e( 'Yes', 'update-control' ); ?></option>
258
- <option <?php selected( 'no' == self::get_option( 'emailactive' ) ); ?> value="no"><?php _e( 'No', 'update-control' ); ?></option>
259
- </select>
260
- <?php
261
- }
262
-
263
- function update_control_email_success_cb() {
264
- ?>
265
- <input type="checkbox" class="update_control_email_dependency" id="update_control_email_success" name="update_control_options[successemail]" <?php checked( self::get_option( 'successemail' ) ); ?> />
266
- <?php
267
- }
268
-
269
- function update_control_email_failure_cb() {
270
- ?>
271
- <input type="checkbox" class="update_control_email_dependency" id="update_control_email_failure" name="update_control_options[failureemail]" <?php checked( self::get_option( 'failureemail' ) ); ?> />
272
- <?php
273
- }
274
-
275
- function update_control_email_critical_cb() {
276
- ?>
277
- <input type="checkbox" class="update_control_email_dependency" id="update_control_email_critical" name="update_control_options[criticalemail]" <?php checked( self::get_option( 'criticalemail' ) ); ?> />
278
- <?php
279
- }
280
-
281
- function sanitize_options( $options ) {
282
- $options = (array) $options;
283
-
284
- $options['active'] = ( in_array( $options['active'], array( 'yes', 'no' ) ) ? $options['active'] : 'yes' );
285
- $options['core'] = ( in_array( $options['core'], array( 'minor', 'major', 'dev' ) ) ? $options['core'] : 'minor' );
286
- $options['plugin'] = ! empty( $options['plugin'] );
287
- $options['theme'] = ! empty( $options['theme'] );
288
- $options['translation'] = ! empty( $options['translation'] );
289
- $options['emailactive'] = ( in_array( $options['emailactive'], array( 'yes', 'no' ) ) ? $options['emailactive'] : 'yes' );
290
- $options['successemail'] = ! empty( $options['successemail'] );
291
- $options['failureemail'] = ! empty( $options['failureemail'] );
292
- $options['criticalemail'] = ! empty( $options['criticalemail'] );
293
-
294
- return $options;
295
- }
296
-
297
- }
298
- Stephanis_Update_Control::go();
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.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
+ add_action( 'admin_init', array( __CLASS__, 'register_settings' ) );
18
+ add_action( 'init', array( __CLASS__, 'setup_upgrade_filters' ) );
19
+ }
20
+
21
+ public static function setup_upgrade_filters() {
22
+ $options = self::get_options();
23
+
24
+ // Do these at priority 1, so other folks can easily override it.
25
+
26
+ if ( 'no' == $options['active'] ) {
27
+ add_filter( 'auto_upgrader_disabled', '__return_true', 1 );
28
+ } else {
29
+
30
+ if ( in_array( $options['core'], array( 'dev', 'major', 'minor' ) ) ) {
31
+ add_filter( 'allow_' . $options['core'] . '_auto_core_updates', '__return_true', 1 );
32
+ }
33
+
34
+ if ( $options['plugin'] ) {
35
+ add_filter( 'auto_update_plugin', '__return_true', 1 );
36
+ }
37
+
38
+ if ( $options['theme'] ) {
39
+ add_filter( 'auto_update_theme', '__return_true', 1 );
40
+ }
41
+
42
+ if ( ! $options['translation'] ) {
43
+ add_filter( 'auto_update_translation', '__return_false', 1 );
44
+ }
45
+
46
+ }
47
+
48
+ if ( 'no' == $options['emailactive'] || ! ( $options['successemail'] || $options['failureemail'] || $options['criticalemail'] ) ) {
49
+ add_filter( 'auto_core_update_send_email', '__return_false', 1 );
50
+ } else {
51
+ add_filter( 'auto_core_update_send_email', array( __CLASS__, 'filter_email' ), 1, 2 );
52
+ }
53
+
54
+ }
55
+
56
+ public static function filter_email( $bool, $type ) {
57
+ $options = self::get_options();
58
+
59
+ if ( 'success' == $type && ! $options['successemail'] )
60
+ return false;
61
+
62
+ if ( 'fail' == $type && ! $options['failureemail'] )
63
+ return false;
64
+
65
+ if ( 'critical' == $type && ! $options['criticalemail'] )
66
+ return false;
67
+
68
+ return $bool;
69
+ }
70
+
71
+ public static function get_options() {
72
+ $defaults = array(
73
+ 'active' => 'yes',
74
+ 'core' => 'minor',
75
+ 'plugin' => false,
76
+ 'theme' => false,
77
+ 'translation' => true,
78
+ 'emailactive' => 'yes',
79
+ 'successemail' => true,
80
+ 'failureemail' => true,
81
+ 'criticalemail' => true,
82
+ );
83
+ $args = get_option( 'update_control_options', array() );
84
+ return wp_parse_args( $args, $defaults );
85
+ }
86
+
87
+ public static function get_option( $key ) {
88
+ $options = self::get_options();
89
+ if ( isset( $options[ $key ] ) ) {
90
+ return $options[ $key ];
91
+ }
92
+ return null;
93
+ }
94
+
95
+ public static function register_settings() {
96
+ add_settings_section(
97
+ 'update-control',
98
+ esc_html__( 'Automatic Updates', 'update-control' ),
99
+ array( __CLASS__, 'update_control_settings_section' ),
100
+ 'general'
101
+ );
102
+
103
+ if ( defined( 'AUTOMATIC_UPDATER_DISABLED' ) && AUTOMATIC_UPDATER_DISABLED ) {
104
+ return;
105
+ }
106
+
107
+ add_settings_field(
108
+ 'update_control_active',
109
+ sprintf( '<label for="update_control_active">%1$s</label>', __( 'Automatic Updates Enabled?', 'update-control' ) ),
110
+ array( __CLASS__, 'update_control_active_cb' ),
111
+ 'general',
112
+ 'update-control'
113
+ );
114
+
115
+ add_settings_field(
116
+ 'update_control_core',
117
+ sprintf( '<label for="update_control_core">%1$s</label>', __( 'Automatic Core Update Level?', 'update-control' ) ),
118
+ array( __CLASS__, 'update_control_core_cb' ),
119
+ 'general',
120
+ 'update-control'
121
+ );
122
+
123
+ add_settings_field(
124
+ 'update_control_plugin',
125
+ sprintf( '<label for="update_control_plugin">%1$s</label>', __( 'Permit Automatic Plugin Updates?', 'update-control' ) ),
126
+ array( __CLASS__, 'update_control_plugin_cb' ),
127
+ 'general',
128
+ 'update-control'
129
+ );
130
+
131
+ add_settings_field(
132
+ 'update_control_theme',
133
+ sprintf( '<label for="update_control_theme">%1$s</label>', __( 'Permit Automatic Theme Updates?', 'update-control' ) ),
134
+ array( __CLASS__, 'update_control_theme_cb' ),
135
+ 'general',
136
+ 'update-control'
137
+ );
138
+
139
+ add_settings_field(
140
+ 'update_control_translation',
141
+ sprintf( '<label for="update_control_translation">%1$s</label>', __( 'Permit Automatic Translation Updates?', 'update-control' ) ),
142
+ array( __CLASS__, 'update_control_translation_cb' ),
143
+ 'general',
144
+ 'update-control'
145
+ );
146
+
147
+ add_settings_field(
148
+ 'update_control_email_active',
149
+ sprintf( '<label for="update_control_email_active">%1$s</label>', __( 'Update Emails Enabled?', 'update-control' ) ),
150
+ array( __CLASS__, 'update_control_email_active_cb' ),
151
+ 'general',
152
+ 'update-control'
153
+ );
154
+
155
+ add_settings_field(
156
+ 'update_control_email_success',
157
+ sprintf( '<label for="update_control_email_success">%1$s</label>', __( 'Send Emails for Successful Updates?', 'update-control' ) ),
158
+ array( __CLASS__, 'update_control_email_success_cb' ),
159
+ 'general',
160
+ 'update-control'
161
+ );
162
+
163
+ add_settings_field(
164
+ 'update_control_email_failure',
165
+ sprintf( '<label for="update_control_email_failure">%1$s</label>', __( 'Send Emails for Failed Updates?', 'update-control' ) ),
166
+ array( __CLASS__, 'update_control_email_failure_cb' ),
167
+ 'general',
168
+ 'update-control'
169
+ );
170
+
171
+ add_settings_field(
172
+ 'update_control_email_critical',
173
+ sprintf( '<label for="update_control_email_critical">%1$s</label>', __( 'Send Emails for Critically Failed Updates?', 'update-control' ) ),
174
+ array( __CLASS__, 'update_control_email_critical_cb' ),
175
+ 'general',
176
+ 'update-control'
177
+ );
178
+
179
+ register_setting( 'general', 'update_control_options', array( __CLASS__, 'sanitize_options' ) );
180
+ }
181
+
182
+ public static function update_control_settings_section() {
183
+ if ( defined( 'AUTOMATIC_UPDATER_DISABLED' ) && AUTOMATIC_UPDATER_DISABLED ) : ?>
184
+ <p id="update-control-settings-section">
185
+ <?php _e( 'You have the <code>AUTOMATIC_UPDATER_DISABLED</code> constant set. Automatic updates are disabled.', 'update-control' ); ?>
186
+ </p>
187
+ <?php else : ?>
188
+ <p id="update-control-settings-section">
189
+ <?php _e( 'This section lets you specify what areas of your WordPress install will be permitted to auto-update.', 'update-control' ); ?>
190
+ </p>
191
+ <script>
192
+ jQuery(document).ready(function($){
193
+ $('#update_control_active').change(function(){
194
+ if ( 'yes' != $(this).val() )
195
+ $('.update_control_dependency').attr( 'readonly', 'readonly' );
196
+ else
197
+ $('.update_control_dependency' ).removeAttr( 'readonly' );
198
+ }).trigger('change');
199
+
200
+ $('#update_control_email_active').change(function(){
201
+ if ( 'yes' != $(this).val() )
202
+ $('.update_control_email_dependency').attr( 'readonly', 'readonly' );
203
+ else
204
+ $('.update_control_email_dependency' ).removeAttr( 'readonly' );
205
+ }).trigger('change');
206
+ });
207
+ </script>
208
+ <style>
209
+ .update_control_dependency[readonly],
210
+ .update_control_email_dependency[readonly] {
211
+ opacity: 0.4;
212
+ }
213
+ </style>
214
+ <?php endif;
215
+ }
216
+
217
+ public static function update_control_active_cb() {
218
+ ?>
219
+ <select id="update_control_active" name="update_control_options[active]">
220
+ <option <?php selected( 'yes' == self::get_option( 'active' ) ); ?> value="yes"><?php _e( 'Yes', 'update-control' ); ?></option>
221
+ <option <?php selected( 'no' == self::get_option( 'active' ) ); ?> value="no"><?php _e( 'No', 'update-control' ); ?></option>
222
+ </select>
223
+ <?php
224
+ }
225
+
226
+ public static function update_control_core_cb() {
227
+ ?>
228
+ <select class="update_control_dependency" id="update_control_core" name="update_control_options[core]">
229
+ <option <?php selected( 'minor' == self::get_option( 'core' ) ); ?> value="minor"><?php _e( 'Minor Updates', 'update-control' ); ?></option>
230
+ <option <?php selected( 'major' == self::get_option( 'core' ) ); ?> value="major"><?php _e( 'Major Updates', 'update-control' ); ?></option>
231
+ <option <?php selected( 'dev' == self::get_option( 'core' ) ); ?> value="dev"><?php _e( 'Development Updates', 'update-control' ); ?></option>
232
+ </select>
233
+ <?php
234
+ }
235
+
236
+ public static function update_control_plugin_cb() {
237
+ ?>
238
+ <input type="checkbox" class="update_control_dependency" id="update_control_plugin" name="update_control_options[plugin]" <?php checked( self::get_option( 'plugin' ) ); ?> />
239
+ <?php
240
+ }
241
+
242
+ public static function update_control_theme_cb() {
243
+ ?>
244
+ <input type="checkbox" class="update_control_dependency" id="update_control_theme" name="update_control_options[theme]" <?php checked( self::get_option( 'theme' ) ); ?> />
245
+ <?php
246
+ }
247
+
248
+ public static function update_control_translation_cb() {
249
+ ?>
250
+ <input type="checkbox" class="update_control_dependency" id="update_control_translation" name="update_control_options[translation]" <?php checked( self::get_option( 'translation' ) ); ?> />
251
+ <?php
252
+ }
253
+
254
+ public static function update_control_email_active_cb() {
255
+ ?>
256
+ <select id="update_control_email_active" name="update_control_options[emailactive]">
257
+ <option <?php selected( 'yes' == self::get_option( 'emailactive' ) ); ?> value="yes"><?php _e( 'Yes', 'update-control' ); ?></option>
258
+ <option <?php selected( 'no' == self::get_option( 'emailactive' ) ); ?> value="no"><?php _e( 'No', 'update-control' ); ?></option>
259
+ </select>
260
+ <?php
261
+ }
262
+
263
+ public static function update_control_email_success_cb() {
264
+ ?>
265
+ <input type="checkbox" class="update_control_email_dependency" id="update_control_email_success" name="update_control_options[successemail]" <?php checked( self::get_option( 'successemail' ) ); ?> />
266
+ <?php
267
+ }
268
+
269
+ public static function update_control_email_failure_cb() {
270
+ ?>
271
+ <input type="checkbox" class="update_control_email_dependency" id="update_control_email_failure" name="update_control_options[failureemail]" <?php checked( self::get_option( 'failureemail' ) ); ?> />
272
+ <?php
273
+ }
274
+
275
+ public static function update_control_email_critical_cb() {
276
+ ?>
277
+ <input type="checkbox" class="update_control_email_dependency" id="update_control_email_critical" name="update_control_options[criticalemail]" <?php checked( self::get_option( 'criticalemail' ) ); ?> />
278
+ <?php
279
+ }
280
+
281
+ public static function sanitize_options( $options ) {
282
+ $options = (array) $options;
283
+
284
+ $options['active'] = ( in_array( $options['active'], array( 'yes', 'no' ) ) ? $options['active'] : 'yes' );
285
+ $options['core'] = ( in_array( $options['core'], array( 'minor', 'major', 'dev' ) ) ? $options['core'] : 'minor' );
286
+ $options['plugin'] = ! empty( $options['plugin'] );
287
+ $options['theme'] = ! empty( $options['theme'] );
288
+ $options['translation'] = ! empty( $options['translation'] );
289
+ $options['emailactive'] = ( in_array( $options['emailactive'], array( 'yes', 'no' ) ) ? $options['emailactive'] : 'yes' );
290
+ $options['successemail'] = ! empty( $options['successemail'] );
291
+ $options['failureemail'] = ! empty( $options['failureemail'] );
292
+ $options['criticalemail'] = ! empty( $options['criticalemail'] );
293
+
294
+ return $options;
295
+ }
296
+
297
+ }
298
+ add_action( 'init', array( 'Stephanis_Update_Control', 'go' ), 0 );