Version Description
- Update for WordPress 3.7 final, add update email options.
Download this release
Release Info
Developer | chipbennett |
Plugin | Update Control |
Version | 1.1 |
Comparing to | |
See all releases |
Code changes from version 1.0 to 1.1
- readme.txt +22 -19
- update-control.php +297 -167
readme.txt
CHANGED
@@ -1,19 +1,22 @@
|
|
1 |
-
=== Plugin Name ===
|
2 |
-
Contributors: georgestephanis
|
3 |
-
Tags: automatic updates, updates
|
4 |
-
Requires at least: 3.7
|
5 |
-
Tested up to: 3.7
|
6 |
-
Stable tag: 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 |
-
== Changelog ==
|
17 |
-
|
18 |
-
= 1.
|
19 |
-
*
|
|
|
|
|
|
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
|
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 =
|
19 |
+
* Update for WordPress 3.7 final, add update email options.
|
20 |
+
|
21 |
+
= 1.0 =
|
22 |
+
* Initial Release.
|
update-control.php
CHANGED
@@ -1,168 +1,298 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
|
4 |
-
* Plugin
|
5 |
-
*
|
6 |
-
*
|
7 |
-
*
|
8 |
-
*
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
)
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
'
|
75 |
-
|
76 |
-
|
77 |
-
'
|
78 |
-
'
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
'
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
)
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
<
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
168 |
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
|
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_' . $option['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 checked( 'minor' == self::get_option( 'core' ) ); ?> value="minor"><?php _e( 'Minor Updates', 'update-control' ); ?></option>
|
230 |
+
<option <?php checked( 'major' == self::get_option( 'core' ) ); ?> value="major"><?php _e( 'Major Updates', 'update-control' ); ?></option>
|
231 |
+
<option <?php checked( '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();
|