Advanced Automatic Updates - Version 0.8

Version Description

  • ADDED: SVN support for plugins and themes
  • ADDED: Retry limits, so broken updates won't keep trying to install
  • ADDED: Option to only receive SVN update emails if something went wrong
  • FIXED: Some HTML tags in debug messages were being incorrectly stripped
  • FIXED: Don't automatically enable Core updates on installs that seem to be coming from a repo
Download this release

Release Info

Developer pento
Plugin Icon wp plugin Advanced Automatic Updates
Version 0.8
Comparing to
See all releases

Code changes from version 0.7.2 to 0.8

Files changed (4) hide show
  1. admin.php +247 -137
  2. automatic-updater.php +604 -313
  3. readme.txt +8 -1
  4. updater-skin.php +3 -3
admin.php CHANGED
@@ -1,159 +1,269 @@
1
  <?php
2
 
3
- function auto_updater_plugin_menu() {
4
- $slug = 'options-general.php';
5
- if ( is_multisite() )
6
- $slug = 'settings.php';
7
 
8
- $hook = add_submenu_page( $slug, esc_html__( 'Automatic Updater', 'automatic-updater' ), esc_html__( 'Automatic Updater', 'automatic-updater' ), 'update_core', 'automatic-updater', 'auto_updater_settings' );
 
9
 
10
- add_action( "load-$hook", 'auto_updater_settings_loader' );
11
- }
12
- if ( is_multisite() )
13
- add_action( 'network_admin_menu', 'auto_updater_plugin_menu' );
14
- else
15
- add_action( 'admin_menu', 'auto_updater_plugin_menu' );
16
-
17
- function auto_updater_settings_loader() {
18
- get_current_screen()->add_help_tab( array(
19
- 'id' => 'overview',
20
- 'title' => esc_html__( 'Overview', 'automatic-updater' ),
21
- 'content' =>
22
- '<p>' . esc_html__( 'This settings page allows you to select whether you would like WordPress Core, your plugins, and your themes to be automatically updated.', 'automatic-updater' ) . '</p>' .
23
- '<p>' . esc_html__( 'It is very important to keep your WordPress installation up to date for security reasons, so unless you have a specific reason not to, we recommend allowing everything to automatically update.', 'automatic-updater' ) . '</p>'
24
- ) );
25
-
26
- get_current_screen()->set_help_sidebar(
27
- '<p><strong>' . wp_kses( sprintf( __( 'A Plugin By <a href="%s" target="_blank">Gary</a>', 'automatic-updater' ), 'http://pento.net/' ), array( 'a' => array( 'href' => array(), 'target' => array() ) ) ) . '</strong></p>' .
28
- '<p><a href="http://pento.net/donate/">' . esc_html__( 'Donations', 'automatic-updater' ) . '</a></p>' .
29
- '<p><a href="http://wordpress.org/support/plugin/automatic-updater">' . esc_html__( 'Support Forums', 'automatic-updater' ) . '</a></p>'
30
- );
31
-
32
- wp_enqueue_style( 'automatic-updater-admin', plugins_url( 'css/admin.css', __FILE__ ) );
33
- }
34
 
35
- function auto_updater_settings() {
36
- if ( ! current_user_can( 'update_core' ) )
37
- wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'automatic-updater' ) );
38
 
39
- $message = '';
40
- if ( ! empty( $_REQUEST['submit'] ) ) {
41
- check_admin_referer( 'automatic-updater-settings' );
42
 
43
- auto_updater_save_settings();
44
- $message = esc_html__( 'Settings updated', 'automatic-updater' );
45
- }
46
- $options = get_option( 'automatic-updater' );
47
- $messages = array(
48
- 'core' => wp_kses( __( 'Update WordPress Core automatically? <strong>(Strongly Recommended)</strong>', 'automatic-updater' ), array( 'strong' => array() ) ),
49
- 'plugins' => esc_html__( 'Update your plugins automatically?', 'automatic-updater' ),
50
- 'themes' => esc_html__( 'Update your themes automatically?', 'automatic-updater' )
51
- );
52
- ?>
53
- <div class="wrap">
54
- <?php screen_icon('tools'); ?>
55
- <h2><?php esc_html_e( 'Automatic Updater', 'automatic-updater' ); ?></h2>
56
- <?php
57
- if ( ! empty( $message ) ) {
58
- ?>
59
- <div class="updated">
60
- <p><?php echo $message; ?></p>
61
- </div>
62
- <?php
63
- }
64
- ?>
65
- <form method="post">
66
- <?php wp_nonce_field( 'automatic-updater-settings' ); ?>
67
- <?php
68
- foreach ( $options['update'] as $type => $enabled ) {
69
- $checked = '';
70
- if ( $enabled )
71
- $checked = ' checked="checked"';
72
 
73
- echo "<p><input type='checkbox' id='$type' name='$type' value='1'$checked> <label for='$type'>{$messages[$type]}</label></p>";
 
74
  }
75
- ?>
76
- <br>
77
- <h3><?php esc_html_e( 'Notification Email', 'automatic-updater' ); ?></h3>
78
- <p><?php esc_html_e( 'By default, Automatic Updater will send an email to the Site Admin when an update is performed. If you would like to send that email to a different address, you can set it here.', 'automatic-updater' ); ?></p>
79
- <p><label for="override-email"><?php esc_html_e( 'Override Email Address', 'automatic-updater' ); ?>:</label> <input type="text" name="override-email" id="override-email" value="<?php echo esc_attr( $options['override-email'] ); ?>"></p>
80
- <?php
81
- $checked = '';
82
- if ( $options['disable-email'] )
83
- $checked = ' checked="checked"';
84
- ?>
85
- <p><?php esc_html_e( "If you don't want to receive an email when updates are installed, you can disable them completely.", 'automatic-updater' ); ?></p>
86
- <p><input type="checkbox" name="disable-email" id="disable-email" value="1"> <label for="disable-email"><?php esc_html_e( 'Disable email notifications.', 'automatic-updater' ); ?></label></p>
87
- <?php
88
- if ( is_dir( ABSPATH . '/.svn' ) ) {
89
- $checked = '';
90
- if ( $options['svn'] )
91
- $checked = ' checked="checked"';
92
- ?>
93
- <br>
94
- <h3><?php esc_html_e( 'SVN Support', 'automatic-updater' ); ?></h3>
95
- <p><?php echo wp_kses( __( "It looks like you're running an SVN version of WordPress, that's cool! Automatic Updater can run <tt>svn up</tt> once an hour, to keep you up-to-date. For safety, enabling this option will disable the normal WordPress core updates.", 'automatic-updater' ), array( 'tt' => array() ) ); ?></p>
96
- <?php
97
- if ( !is_writable( ABSPATH . '/.svn' ) ) {
98
- $uid = posix_getuid();
99
- $user = posix_getpwuid( $uid );
100
- echo '<div class="automatic-updater-notice"><p>' . wp_kses( sprintf( __( "The .svn directory isn't writable, so <tt>svn up</tt> will probably fail when the web server runs it. You need to give the user <tt>%s</tt> write permissions to your entire WordPress install, including .svn directories.", 'automatic-updater' ), $user['name'] ), array( 'tt' => array() ) ) . '</p></div>';
101
- }
102
- ?>
103
- <p><input type="checkbox" id="svn" name="svn" value="1"<?php echo $checked; ?>> <label for="svn"><?php echo wp_kses( __( 'Run <tt>svn up</tt> hourly?', 'automatic-updater' ), array( 'tt' => array() ) ); ?></label></p>
104
- <?php
105
- }
106
- else {
107
- echo '<input type="hidden" name="svn" value="0">';
108
  }
109
 
110
- $checked = '';
111
- if ( $options['debug'] )
112
- $checked = ' checked="checked"';
113
- ?>
114
- <br>
115
- <h3><?php esc_html_e( 'Debug Information', 'automatic-updater' ); ?></h3>
116
- <p><input type="checkbox" id="debug" name="debug" value="1"<?php echo $checked; ?>> <label for="debug"><?php esc_html_e( 'Show debug information in the notification email.', 'automatic-updater' ); ?></label></p>
117
- <p><input class="button button-primary" type="submit" name="submit" id="submit" value="<?php esc_attr_e( 'Save Changes', 'automatic-updater' ); ?>" /></p>
118
- </form>
119
- </div>
120
- <?php
121
- }
122
 
123
- function auto_updater_save_settings() {
124
- $options = get_option( 'automatic-updater' );
 
 
 
125
 
126
- $types = array( 'core', 'plugins', 'themes' );
127
- foreach ( $types as $type ) {
128
- if ( ! empty( $_REQUEST[$type] ) )
129
- $options['update'][$type] = true;
130
- else
131
- $options['update'][$type] = false;
132
  }
133
 
134
- $top_bool_options = array( 'debug', 'svn', 'disable-email' );
135
- foreach ( $top_bool_options as $option ) {
136
- if ( ! empty( $_REQUEST[$option] ) )
137
- $options[$option] = true;
138
- else
139
- $options[$option] = false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  }
141
 
142
- $top_options = array( 'override-email' );
143
- foreach ( $top_options as $option )
144
- $options[$option] = $_REQUEST[$option];
 
 
 
 
 
 
 
145
 
146
- update_option( 'automatic-updater', $options );
147
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
 
149
- function auto_updater_plugin_row_links( $links ) {
150
- $url = admin_url( 'options-general.php?page=automatic-updater' );
151
- if ( is_multisite() )
152
- $url = network_admin_url( 'settings.php?page=automatic-updater' );
153
 
154
- array_unshift( $links, "<a href='$url'>" . esc_html__( 'Settings', 'automatic-updater' ) . '</a>' );
 
155
 
156
- return $links;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
  }
158
- add_filter( 'plugin_action_links_' . AUTOMATIC_UPDATER_BASENAME, 'auto_updater_plugin_row_links' );
159
- add_filter( 'network_admin_plugin_action_links_' . AUTOMATIC_UPDATER_BASENAME, 'auto_updater_plugin_row_links' );
1
  <?php
2
 
3
+ class Automatic_Updater_Admin {
4
+ private $automatic_updater;
 
 
5
 
6
+ function init( $automatic_updater ) {
7
+ static $instance = false;
8
 
9
+ if( ! $instance )
10
+ $instance = new Automatic_Updater_Admin( $automatic_updater );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
+ return $instance;
13
+ }
 
14
 
15
+ function __construct( $automatic_updater ) {
16
+ $this->automatic_updater = $automatic_updater;
 
17
 
18
+ if ( is_multisite() )
19
+ add_action( 'network_admin_menu', array( &$this, 'plugin_menu' ) );
20
+ else
21
+ add_action( 'admin_menu', array( &$this, 'plugin_menu' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
+ add_filter( 'plugin_action_links_' . Automatic_Updater::$basename, array( &$this, 'plugin_row_links' ) );
24
+ add_filter( 'network_admin_plugin_action_links_' . Automatic_Updater::$basename, array( &$this, 'plugin_row_links' ) );
25
  }
26
+
27
+ function plugin_menu() {
28
+ $slug = 'options-general.php';
29
+ if ( is_multisite() )
30
+ $slug = 'settings.php';
31
+
32
+ $hook = add_submenu_page( $slug, esc_html__( 'Automatic Updater', 'automatic-updater' ), esc_html__( 'Automatic Updater', 'automatic-updater' ), 'update_core', 'automatic-updater', array( &$this, 'settings' ) );
33
+
34
+ add_action( "load-$hook", array( &$this, 'settings_loader' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  }
36
 
37
+ function settings_loader() {
38
+ get_current_screen()->add_help_tab( array(
39
+ 'id' => 'overview',
40
+ 'title' => esc_html__( 'Overview', 'automatic-updater' ),
41
+ 'content' =>
42
+ '<p>' . esc_html__( 'This settings page allows you to select whether you would like WordPress Core, your plugins, and your themes to be automatically updated.', 'automatic-updater' ) . '</p>' .
43
+ '<p>' . esc_html__( 'It is very important to keep your WordPress installation up to date for security reasons, so unless you have a specific reason not to, we recommend allowing everything to automatically update.', 'automatic-updater' ) . '</p>'
44
+ ) );
 
 
 
 
45
 
46
+ get_current_screen()->set_help_sidebar(
47
+ '<p><strong>' . wp_kses( sprintf( __( 'A Plugin By <a href="%s" target="_blank">Gary</a>', 'automatic-updater' ), 'http://pento.net/' ), array( 'a' => array( 'href' => array(), 'target' => array() ) ) ) . '</strong></p>' .
48
+ '<p><a href="http://pento.net/donate/">' . esc_html__( 'Donations', 'automatic-updater' ) . '</a></p>' .
49
+ '<p><a href="http://wordpress.org/support/plugin/automatic-updater">' . esc_html__( 'Support Forums', 'automatic-updater' ) . '</a></p>'
50
+ );
51
 
52
+ wp_enqueue_style( 'automatic-updater-admin', plugins_url( 'css/admin.css', __FILE__ ) );
 
 
 
 
 
53
  }
54
 
55
+ function settings() {
56
+ if ( ! current_user_can( 'update_core' ) )
57
+ wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'automatic-updater' ) );
58
+
59
+ $message = '';
60
+ if ( ! empty( $_REQUEST['submit'] ) ) {
61
+ check_admin_referer( 'automatic-updater-settings' );
62
+
63
+ $this->save_settings();
64
+ $message = esc_html__( 'Settings updated', 'automatic-updater' );
65
+ }
66
+
67
+ $messages = array(
68
+ 'core' => wp_kses( __( 'Update WordPress Core automatically? <strong>(Strongly Recommended)</strong>', 'automatic-updater' ), array( 'strong' => array() ) ),
69
+ 'plugins' => esc_html__( 'Update your plugins automatically?', 'automatic-updater' ),
70
+ 'themes' => esc_html__( 'Update your themes automatically?', 'automatic-updater' )
71
+ );
72
+ ?>
73
+ <div class="wrap">
74
+ <?php screen_icon( 'tools' ); ?>
75
+ <h2><?php esc_html_e( 'Automatic Updater', 'automatic-updater' ); ?></h2>
76
+
77
+ <?php if ( ! empty( $message ) ) { ?>
78
+ <div class="updated">
79
+ <p><?php echo $message; ?></p>
80
+ </div>
81
+ <?php } ?>
82
+
83
+ <form method="post">
84
+ <?php wp_nonce_field( 'automatic-updater-settings' ); ?>
85
+
86
+ <?php
87
+ foreach ( $this->automatic_updater->get_option( 'update' ) as $type => $enabled ) {
88
+ $checked = '';
89
+ if ( $enabled )
90
+ $checked = ' checked="checked"';
91
+
92
+ echo "<p><input type='checkbox' id='$type' name='$type' value='1'$checked> <label for='$type'>{$messages[ $type ]}</label></p>";
93
+ }
94
+ ?>
95
+
96
+ <br>
97
+ <h3><?php esc_html_e( 'Notification Email', 'automatic-updater' ); ?></h3>
98
+ <p><?php esc_html_e( 'By default, Automatic Updater will send an email to the Site Admin when an update is performed. If you would like to send that email to a different address, you can set it here.', 'automatic-updater' ); ?></p>
99
+ <p><label for="override-email"><?php esc_html_e( 'Override Email Address', 'automatic-updater' ); ?>:</label> <input type="text" name="override-email" id="override-email" value="<?php echo esc_attr( $this->automatic_updater->get_option( 'override-email' ) ); ?>"></p>
100
+
101
+ <?php
102
+ $checked = '';
103
+ if ( $this->automatic_updater->get_option( 'disable-email' ) )
104
+ $checked = ' checked="checked"';
105
+ ?>
106
+
107
+ <p><?php esc_html_e( "If you don't want to receive an email when updates are installed, you can disable them completely.", 'automatic-updater' ); ?></p>
108
+ <p><input type="checkbox" name="disable-email" id="disable-email" value="1"> <label for="disable-email"><?php esc_html_e( 'Disable email notifications.', 'automatic-updater' ); ?></label></p>
109
+
110
+ <br>
111
+ <h3><?php esc_html_e( 'Retries', 'automatic-updater' ); ?></h3>
112
+ <p><?php esc_html_e( 'To avoid updating when something is broken, Automatic Updater can limit the number of times it will attempt to update WordPress Core, a plugin or a theme. If, for example, a plugin update reaches this limit, Automatic Updater will stop trying to update it until you manually install the update, or a new version is released.', 'automatic-updater' ); ?></p>
113
+ <p><label for="retries-limit"><?php esc_html_e( 'Retries Limit', 'automatic-updater' ); ?>:</label> <input type="number" step="1" name="retries-limit" id="retries-limit" class="small-text" value="<?php echo esc_attr( $this->automatic_updater->get_option( 'retries-limit' ) ); ?>"></p>
114
+
115
+ <?php
116
+ $source_control = $this->automatic_updater->under_source_control();
117
+ if ( $source_control['core'] || ! empty( $source_control['plugins'] ) || ! empty( $source_control['themes'] ) ) {
118
+ $svn_options = $this->automatic_updater->get_option( 'svn' );
119
+ $writable_error = false;
120
+ ?>
121
+
122
+ <br>
123
+ <h3><?php esc_html_e( 'SVN Support', 'automatic-updater' ); ?></h3>
124
+ <?php
125
+ if ( $source_control['core'] ) {
126
+ $svn_core_checked = '';
127
+ if ( $svn_options['core'] )
128
+ $svn_core_checked = ' checked="checked"';
129
+
130
+ if ( ! is_writable( ABSPATH . '/.svn' ) )
131
+ $writable_error = true;
132
+ ?>
133
+ <h4><?php esc_html_e( 'WordPress Core', 'automatic-updater' ); ?></h4>
134
+ <p><?php echo wp_kses( __( "It looks like you're running an SVN version of WordPress, that's cool! Automatic Updater can run <tt>svn up</tt> once an hour, to keep you up-to-date. For safety, enabling this option will disable the normal WordPress core updates.", 'automatic-updater' ), array( 'tt' => array() ) ); ?></p>
135
+ <p><input type="checkbox" id="svn-core" name="svn-core" value="1"<?php echo $svn_core_checked; ?>> <label for="svn-core"><?php esc_html_e( 'Update WordPress Core hourly?', 'automatic-updater' ); ?></label></p>
136
+
137
+ <?php
138
+ }
139
+
140
+ if ( ! empty( $source_control['plugins'] ) ) {
141
+ ?>
142
+ <h4><?php esc_html_e( 'Plugins', 'automatic-updater' ); ?></h4>
143
+ <p><?php esc_html_e( "Running plugins from SVN is great for helping plugin devs fine tune them before release, so on behalf of all of us, thanks! If you see Akismet here and don't have it coming from a custom repository, it will probably automatically update when the WordPress Core SVN update occurs.", 'automatic-updater' ); ?></p>
144
+ <?php
145
+ foreach ( $source_control['plugins'] as $id => $plugin ) {
146
+ if ( ! is_writable( WP_PLUGIN_DIR . '/' . plugin_dir_path( $id ) . '/.svn' ) )
147
+ $writable_error = true;
148
+
149
+ $checked = '';
150
+ if ( array_key_exists( $id, $svn_options['plugins'] ) )
151
+ $checked = ' checked="checked"';
152
+ echo "<input type='checkbox' name='svn-plugins[]' id='$id' value='$id'$checked /> <label for='$id'>{$plugin['plugin']['Name']} ($id)</label><br/>";
153
+ }
154
+ }
155
+
156
+ if ( ! empty( $source_control['themes'] ) ) {
157
+ ?>
158
+ <h4><?php esc_html_e( 'Themes', 'automatic-updater' ); ?></h4>
159
+ <p><?php esc_html_e( "Running themes from SVN makes you an excellent person who makes the WordPress community better - thank you! If you see any of the default Twenty Ten, Eleven or Twelve themes, these will probably automatically update when the WordPress Core SVN update occurs.", 'automatic-updater' ); ?></p>
160
+ <?php
161
+ foreach ( $source_control['themes'] as $id => $theme ) {
162
+ if ( ! is_writable( $theme['theme']->get_stylesheet_directory() . '/.svn' ) )
163
+ $writable_error = true;
164
+
165
+ $checked = '';
166
+ if ( array_key_exists( $id, $svn_options['themes'] ) )
167
+ $checked = ' checked="checked"';
168
+ echo "<input type='checkbox' name='svn-themes[]' id='$id' value='$id'$checked /> <label for='$id'>{$theme['theme']->name} ($id)</label><br/>";
169
+ }
170
+ }
171
+
172
+ if ( $writable_error ) {
173
+ $uid = posix_getuid();
174
+ $user = posix_getpwuid( $uid );
175
+ echo '<div class="automatic-updater-notice"><p>' . wp_kses( sprintf( __( "The items marked in red don't have their .svn directory writable, so <tt>svn up</tt> will probably fail when the web server runs it. You need to give the user <tt>%s</tt> write permissions to your entire WordPress install, including .svn directories.", 'automatic-updater' ), $user['name'] ), array( 'tt' => array() ) ) . '</p></div>';
176
+ }
177
+
178
+ $svn_success_email_checked = '';
179
+ if ( $this->automatic_updater->get_option( 'svn-success-email' ) )
180
+ $svn_success_email_checked = ' checked="checked"';
181
+ ?>
182
+ <h4><?php esc_html_e( 'SVN Options', 'automatic-updater' ); ?></h4>
183
+ <p><input type="checkbox" id="svn-success-email" name="svn-success-email" value="1"<?php echo $svn_success_email_checked; ?>> <label for="svn-success-email"><?php echo wp_kses( __( 'Send email on <tt>svn up</tt> success? Disabling this will cause notification emails to only be sent if the <tt>svn up</tt> fails.', 'automatic-updater' ), array( 'tt' => array() ) ); ?></label></p>
184
+
185
+ <?php
186
+ } else {
187
+ ?>
188
+ <input type="hidden" name="svn-core" value="0">;
189
+ <input type="hidden" name="svn-plugins" value="0">;
190
+ <input type="hidden" name="svn-themes" value="0">;
191
+ <input type="hidden" name="svn-success-email" value="0">;
192
+ <?php
193
+ }
194
+
195
+ $checked = '';
196
+ if ( $this->automatic_updater->get_option( 'debug' ) )
197
+ $checked = ' checked="checked"';
198
+ ?>
199
+
200
+ <br>
201
+ <h3><?php esc_html_e( 'Debug Information', 'automatic-updater' ); ?></h3>
202
+ <p><input type="checkbox" id="debug" name="debug" value="1"<?php echo $checked; ?>> <label for="debug"><?php esc_html_e( 'Show debug information in the notification email.', 'automatic-updater' ); ?></label></p>
203
+ <p><input class="button button-primary" type="submit" name="submit" id="submit" value="<?php esc_attr_e( 'Save Changes', 'automatic-updater' ); ?>" /></p>
204
+ </form>
205
+ </div>
206
+ <?php
207
  }
208
 
209
+ function save_settings() {
210
+ $types = array( 'core', 'plugins', 'themes' );
211
+ $update = array();
212
+ foreach ( $types as $type ) {
213
+ if ( ! empty( $_REQUEST[ $type ] ) )
214
+ $update[ $type ] = true;
215
+ else
216
+ $update[ $type ] = false;
217
+ }
218
+ $this->automatic_updater->update_option( 'update', $update );
219
 
220
+ $top_bool_options = array( 'debug', 'disable-email' );
221
+ foreach ( $top_bool_options as $option ) {
222
+ if ( ! empty( $_REQUEST[ $option ] ) )
223
+ $this->automatic_updater->update_option( $option, true );
224
+ else
225
+ $this->automatic_updater->update_option( $option, false );
226
+ }
227
+
228
+ $top_options = array( 'override-email', 'retries-limit' );
229
+ foreach ( $top_options as $option )
230
+ $this->automatic_updater->update_option( $option, $_REQUEST[ $option ] );
231
+
232
+ $svn_options = array(
233
+ 'core' => false,
234
+ 'plugins' => array(),
235
+ 'themes' => array()
236
+ );
237
 
238
+ $source_control = $this->automatic_updater->under_source_control();
 
 
 
239
 
240
+ if ( $source_control['core'] && ! empty( $_REQUEST['svn-core'] ) )
241
+ $svn_options['core'] = true;
242
 
243
+ if ( ! empty( $source_control['plugins'] ) && ! empty( $_REQUEST['svn-plugins'] ) && is_array( $_REQUEST['svn-plugins'] ) ) {
244
+ foreach ( $_REQUEST['svn-plugins'] as $plugin ) {
245
+ if ( array_key_exists( $plugin, $source_control['plugins'] ) )
246
+ $svn_options['plugins'][ $plugin ] = $source_control['plugins'][ $plugin ]['type'];
247
+ }
248
+ }
249
+
250
+ if ( ! empty( $source_control['themes'] ) && ! empty( $_REQUEST['svn-themes'] ) && is_array( $_REQUEST['svn-themes'] ) ) {
251
+ foreach ( $_REQUEST['svn-themes'] as $theme ) {
252
+ if ( array_key_exists( $theme, $source_control['themes'] ) )
253
+ $svn_options['themes'][ $theme ] = $source_control['themes'][ $theme ]['type'];
254
+ }
255
+ }
256
+
257
+ $this->automatic_updater->update_option( 'svn', $svn_options );
258
+ }
259
+
260
+ function plugin_row_links( $links ) {
261
+ $url = admin_url( 'options-general.php?page=automatic-updater' );
262
+ if ( is_multisite() )
263
+ $url = network_admin_url( 'settings.php?page=automatic-updater' );
264
+
265
+ array_unshift( $links, "<a href='$url'>" . esc_html__( 'Settings', 'automatic-updater' ) . '</a>' );
266
+
267
+ return $links;
268
+ }
269
  }
 
 
automatic-updater.php CHANGED
@@ -4,16 +4,13 @@
4
  * Plugin URI: http://pento.net/projects/automatic-updater-for-wordpress/
5
  * Description: Automatically update your WordPress site, as soon as updates are released! Never worry about falling behing on updating again!
6
  * Author: pento
7
- * Version: 0.7.2
8
  * Author URI: http://pento.net/
9
  * License: GPL2+
10
  * Text Domain: automatic-updater
11
  * Domain Path: /languages/
12
  */
13
 
14
- global $auto_updater_running;
15
- $auto_updater_running = false;
16
-
17
  $automatic_updater_file = __FILE__;
18
 
19
  if ( isset( $plugin ) )
@@ -23,424 +20,718 @@ else if ( isset( $mu_plugin ) )
23
  else if ( isset( $network_plugin ) )
24
  $automatic_updater_file = $network_plugin;
25
 
26
- define( 'AUTOMATIC_UPDATER_BASENAME', plugin_basename( $automatic_updater_file ) );
27
 
28
- function auto_updater_requires_wordpress_version() {
29
- if ( version_compare( $GLOBALS['wp_version'], '3.4', '<' ) ) {
30
- if ( is_plugin_active( AUTOMATIC_UPDATER_BASENAME ) ) {
31
- deactivate_plugins( AUTOMATIC_UPDATER_BASENAME );
32
- add_action( 'admin_notices', 'auto_updater_disabled_notice' );
33
- if ( isset( $_GET['activate'] ) )
34
- unset( $_GET['activate'] );
35
- }
36
- }
37
- }
38
- add_action( 'admin_init', 'auto_updater_requires_wordpress_version' );
39
 
40
- function auto_updater_disabled_notice() {
41
- echo '<div class="updated"><p><strong>' . esc_html__( 'Automatic Updater requires WordPress 3.4 or higher! Please upgrade WordPress manually, then reactivate Automatic Updater.', 'automatic-updater' ) . '</strong></p></div>';
42
- }
43
 
44
- function auto_updater_init() {
45
- if ( is_multisite() && ! is_main_site() )
46
- return;
47
-
48
- if ( is_admin() )
49
- include_once( dirname( __FILE__ ) . '/admin.php' );
50
-
51
- $options = get_option( 'automatic-updater', array() );
52
-
53
- if ( empty( $options ) ) {
54
- $options = array(
55
- 'update' => array(
56
- 'core' => true,
57
- 'plugins' => false,
58
- 'themes' => false,
59
- ),
60
- 'svn' => false,
61
- 'debug' => false,
62
- 'next-development-update' => time(),
63
- 'override-email' => '',
64
- 'disable-email' => false,
65
- );
66
- update_option( 'automatic-updater', $options );
67
- }
68
 
69
- // 'debug' option added in version 0.3
70
- if ( ! array_key_exists( 'debug', $options ) ) {
71
- $options['debug'] = false;
72
- update_option( 'automatic-updater', $options );
73
- }
74
 
75
- // SVN updates added in version 0.5
76
- if ( ! array_key_exists( 'svn', $options ) ) {
77
- $options['svn'] = false;
78
- update_option( 'automatic-updater', $options );
79
  }
80
 
81
- // Development version updates added in version 0.6
82
- if ( ! array_key_exists( 'next-development-update', $options ) ) {
83
- $options['next-development-update'] = time();
84
- update_option( 'automatic-updater', $options );
85
- }
86
 
87
- // Override contact email added in version 0.7
88
- if ( ! array_key_exists( 'override-email', $options ) ) {
89
- $options['override-email'] = '';
90
- update_option( 'automatic-updater', $options );
91
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
 
93
- // Ability to disable email added in version 0.7
94
- if ( ! array_key_exists( 'disable-email', $options ) ) {
95
- $options['disable-email'] = false;
96
- update_option( 'automatic-updater', $options );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  }
98
 
99
- // Configure SVN updates cron, if it's enabled
100
- if ( $options['svn'] ) {
101
- if ( ! wp_next_scheduled( 'auto_updater_svn_event' ) )
102
- wp_schedule_event( time(), 'hourly', 'auto_updater_svn_event' );
103
  }
104
- else {
105
- if ( $timestamp = wp_next_scheduled( 'auto_updater_svn_event' ) )
106
- wp_unschedule_event( $timestamp, 'auto_updater_svn_event' );
 
 
 
107
  }
108
 
109
- // Load the translations
110
- load_plugin_textdomain( 'automatic-updater', false, dirname( AUTOMATIC_UPDATER_BASENAME ) . '/languages/' );
 
111
 
112
- global $auto_updater_running;
113
- // If the update check was one we called manually, don't get into a crazy recursive loop.
114
- if ( $auto_updater_running )
115
- return;
116
 
117
- $types = array( 'wordpress' => 'core', 'plugins' => 'plugins', 'themes' => 'themes' );
118
- if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
119
- // We're in a cron, do updates now
120
- foreach ( $types as $type ) {
121
- if ( ! empty( $options['update'][$type] ) ) {
122
- add_action( "set_site_transient_update_$type", "auto_updater_$type" );
123
- add_action( "set_site_transient__site_transient_update_$type", "auto_updater_$type" );
124
  }
125
  }
126
  }
127
- else {
128
- include_once( ABSPATH . 'wp-admin/includes/update.php' );
129
- $update_data = auto_updater_get_update_data();
130
- // Not in a cron, schedule updates to happen in the next cron run
131
- foreach ( $types as $internal => $type ) {
132
- if ( ! empty( $options['update'][$type] ) && $update_data['counts'][$internal] > 0 ) {
133
- wp_schedule_single_event( time(), "auto_updater_{$type}_event" );
134
- }
135
- }
136
  }
137
- }
138
- add_action( 'init', 'auto_updater_init' );
139
 
140
- function auto_updater_core() {
141
- global $auto_updater_running;
142
- if ( $auto_updater_running )
143
- return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
 
145
- $options = get_option( 'automatic-updater', array() );
146
- if ( $options['svn'] )
147
- return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
 
149
- // Forgive me father, for I have sinned. I have included wp-admin files in a plugin.
150
- include_once( ABSPATH . 'wp-admin/includes/update.php' );
151
- include_once( ABSPATH . 'wp-admin/includes/file.php' );
 
 
 
 
 
 
 
 
 
152
 
153
- include_once( dirname( __FILE__ ) . '/updater-skin.php' );
 
 
154
 
155
- $updates = get_core_updates();
156
- if ( empty( $updates ) )
157
- return;
158
 
159
- if ( 'development' == $updates[0]->response )
160
- $update = $updates[0];
161
- else
162
- $update = find_core_update( $updates[0]->current, $updates[0]->locale );
163
 
164
- $update = apply_filters( 'auto_updater_core_updates', $update );
165
- if ( empty( $update ) )
166
- return;
167
 
168
- $old_version = $GLOBALS['wp_version'];
 
 
169
 
170
- // Sanity check that the new upgrade is actually an upgrade
171
- if ( 'development' != $update->response && version_compare( $old_version, $update->current, '>=' ) )
172
- return;
 
173
 
174
- // Only do development version updates once every 24 hours
175
- if ( 'development' == $update->response ) {
176
- if ( time() < $options['next-development-update'] )
177
  return;
178
 
179
- $options['next-development-update'] = strtotime( '+24 hours' );
180
- update_option( 'automatic-updater', $options );
181
- }
182
 
183
- $auto_updater_running = true;
184
 
185
- do_action( 'auto_updater_before_update', 'core' );
 
 
186
 
187
- $skin = new Auto_Updater_Skin();
188
- $upgrader = new Core_Upgrader( $skin );
189
- $result = $upgrader->upgrade( $update );
 
190
 
191
- do_action( 'auto_updater_after_update', 'core' );
 
192
 
193
- if ( is_wp_error( $result ) ) {
194
- $message = esc_html__( "While trying to upgrade WordPress, we ran into the following error:", 'automatic-updater' );
195
- $message .= '<br><br>' . $result->get_error_message() . '<br><br>';
196
- $message .= esc_html__( "We're sorry it didn't work out. Please try upgrading manually, instead.", 'automatic-updater' );
197
- }
198
- else if( 'development' == $update->response ) {
199
- $message = esc_html__( "We've successfully upgraded WordPress to the latest nightly build!", 'automatic-updater' );
200
- $message .= '<br><br>' . esc_html__( 'Have fun!', 'automatic-updater' );
201
- }
202
- else {
203
- $message = sprintf( esc_html__( 'We\'ve successfully upgraded WordPress from version %1$s to version %2$s!', 'automatic-updater' ), $old_version, $update->current );
204
- $message .= '<br><br>' . esc_html__( 'Have fun!', 'automatic-updater' );
205
- }
206
 
207
- $message .= '<br>';
208
 
209
- $debug = join( '<br>', $skin->messages );
210
 
211
- auto_updater_notification( $message, $debug );
 
 
212
 
213
- wp_version_check();
214
- }
215
- add_action( 'auto_updater_core_event', 'auto_updater_core' );
216
 
217
- function auto_updater_plugins() {
218
- global $auto_updater_running;
219
- if ( $auto_updater_running )
220
- return;
221
 
222
- include_once( ABSPATH . 'wp-admin/includes/update.php' );
223
- include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
224
- include_once( ABSPATH . 'wp-admin/includes/file.php' );
225
 
226
- include_once( dirname( __FILE__ ) . '/updater-skin.php' );
227
 
228
- $plugins = apply_filters( 'auto_updater_plugin_updates', get_plugin_updates() );
 
 
 
 
 
 
 
229
 
230
- // Remove any plugins from the list that may've already been updated
231
- foreach ( $plugins as $id => $plugin ) {
232
- if ( version_compare( $plugin->Version, $plugin->update->new_version, '>=' ) )
233
- unset( $plugins[$id] );
234
- }
235
 
236
- if ( empty( $plugins ) )
237
- return;
 
238
 
239
- $auto_updater_running = true;
240
 
241
- do_action( 'auto_updater_before_update', 'plugins' );
242
 
243
- $skin = new Auto_Updater_Skin();
244
- $upgrader = new Plugin_Upgrader( $skin );
245
- $result = $upgrader->bulk_upgrade( array_keys( $plugins ) );
246
 
247
- do_action( 'auto_updater_after_update', 'plugins' );
 
248
 
249
- $message = esc_html( _n( 'We found a plugin upgrade!', 'We found upgrades for some plugins!', count( $plugins ), 'automatic-updater' ) );
250
- $message .= '<br><br>';
 
251
 
252
- foreach ( $plugins as $id => $plugin ) {
253
- if ( is_wp_error( $result[$id] ) ) {
254
- /* translators: First argument is the plugin url, second argument is the Plugin name, third argument is the error encountered while upgrading */
255
- $message .= wp_kses( sprintf( __( '<a href="%1$s">%2$s</a>: We encounted an error upgrading this plugin: %3$s', 'automatic-updater' ),
256
- $plugin->update->url,
257
- $plugin->Name,
258
- $result[$id]->get_error_message() ), array( 'a' => array( 'href' => array() ) ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
259
  }
260
- else {
261
- /* translators: First argument is the plugin url, second argument is the Plugin name, third argument is the old version number, fourth argument is the new version number */
262
- $message .= wp_kses( sprintf( __( '<a href="%1$s">%2$s</a>: Successfully upgraded from version %3$s to %4$s!', 'automatic-updater' ),
263
- $plugin->update->url,
264
- $plugin->Name,
265
- $plugin->Version,
266
- $plugin->update->new_version ), array( 'a' => array( 'href' => array() ) ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
267
  }
268
 
269
- $message .= '<br>';
 
 
 
 
 
 
270
  }
271
 
272
- $message .= '<br>' . esc_html__( 'Plugin authors depend on your feedback to make their plugins better, and the WordPress community depends on plugin ratings for checking the quality of a plugin. If you have a couple of minutes, click on the plugin names above, and leave a Compatibility Vote or a Rating!', 'automatic-updater' ) . '<br>';
 
 
 
 
 
 
 
273
 
274
- $debug = join( '<br>', $skin->messages );
275
 
276
- auto_updater_notification( $message, $debug );
 
 
 
277
 
278
- wp_update_plugins();
279
- }
280
- add_action( 'auto_updater_plugins_event', 'auto_updater_plugins' );
 
 
 
 
 
 
 
 
 
 
281
 
282
- function auto_updater_themes() {
283
- global $auto_updater_running;
284
- if ( $auto_updater_running )
285
- return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
286
 
287
- include_once( ABSPATH . 'wp-admin/includes/update.php' );
288
- include_once( ABSPATH . 'wp-admin/includes/file.php' );
289
 
290
- include_once( dirname( __FILE__ ) . '/updater-skin.php' );
291
 
292
- $themes = apply_filters( 'auto_updater_theme_updates', get_theme_updates() );
293
 
294
- // Remove any themes from the list that may've already been updated
295
- foreach ( $themes as $id => $theme ) {
296
- if ( version_compare( $theme->Version, $theme->update['new_version'], '>=' ) )
297
- unset( $themes[$id] );
298
  }
299
 
300
- if ( empty( $themes ) )
301
- return;
 
 
 
302
 
303
- $auto_updater_running = true;
 
304
 
305
- do_action( 'auto_updater_before_update', 'themes' );
306
 
307
- $skin = new Auto_Updater_Skin();
308
- $upgrader = new Theme_Upgrader( $skin );
309
- $result = $upgrader->bulk_upgrade( array_keys( $themes ) );
310
 
311
- do_action( 'auto_updater_after_update', 'themes' );
 
312
 
313
- $message = esc_html( _n( 'We found a theme upgrade!', 'We found upgrades for some themes!', count( $themes ), 'automatic-updater' ) );
314
- $message .= '<br><br>';
315
 
316
- foreach ( $themes as $id => $theme ) {
317
- if ( is_wp_error( $result[$id] ) ) {
318
- /* translators: First argument is the theme URL, second argument is the Theme name, third argument is the error encountered while upgrading */
319
- $message .= wp_kses( sprintf( __( '<a href="%1$s">%2$s</a>: We encounted an error upgrading this theme: %3$s', 'automatic-updater' ),
320
- $theme->update['url'],
321
- $theme->name,
322
- $result[$id]->get_error_message() ), array( 'a' => array( 'href' => array() ) ) );
 
 
 
 
323
  }
324
- else {
325
- /* translators: First argument is the theme URL, second argument is the Theme name, third argument is the old version number, fourth argument is the new version number */
326
- $message .= wp_kses( sprintf( __( '<a href="%1$s">%2$s</a>: Successfully upgraded from version %3$s to %4$s!', 'automatic-updater' ),
327
- $theme->update['url'],
328
- $theme->name,
329
- $theme->version,
330
- $theme->update['new_version'] ), array( 'a' => array( 'href' => array() ) ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
331
  }
332
 
333
- $message .= '<br>';
334
- }
335
 
336
- $message .= '<br>' . esc_html__( 'Theme authors depend on your feedback to make their plugins better, and the WordPress community depends on theme ratings for checking the quality of a theme. If you have a couple of minutes, click on the theme names above, and leave a Compatibility Vote or a Rating!', 'automatic-updater' ) . '<br>';
 
 
 
 
337
 
338
- $debug = join( '<br>', $skin->messages );
 
 
339
 
340
- auto_updater_notification( $message, $debug );
341
 
342
- wp_update_themes();
343
- }
344
- add_action( 'auto_updater_themes_event', 'auto_updater_themes' );
 
345
 
346
- function auto_updater_svn() {
347
- $output = array();
348
- $return = NULL;
349
 
350
- exec( 'svn up ' . ABSPATH, $output, $return );
 
 
351
 
352
- if ( 0 === $return ) {
353
- $update = end( $output );
354
- // No need to email if there was no update.
355
- if ( 0 === strpos( $update, "At revision" ) )
 
 
 
 
 
 
 
 
 
 
 
356
  return;
357
 
358
- $message = esc_html__( 'We successfully upgraded from SVN!', 'automatic-updater' );
359
- $message .= "<br><br>$update";
360
- }
361
- else {
362
- $message = esc_html__( 'While upgrading from SVN, we ran into the following error:', 'automatic-updater' );
363
- $message .= '<br><br>' . end( $output ) . '<br><br>';
364
- $message .= esc_html__( "We're sorry it didn't work out. Please try upgrading manually, instead.", 'automatic-updater' );
 
 
365
  }
366
 
367
- $message .= '<br>';
 
 
368
 
369
- $debug = join( '<br>', $output );
 
370
 
371
- auto_updater_notification( $message, $debug );
372
- }
373
- add_action( 'auto_updater_svn_event', 'auto_updater_svn' );
 
 
 
 
 
 
 
374
 
375
- function auto_updater_notification( $info = '', $debug = '' ) {
376
- $options = get_option( 'automatic-updater', array() );
 
 
 
 
377
 
378
- if ( $options['disable-email'] )
379
- return;
380
 
381
- $site = get_home_url();
382
- $subject = sprintf( esc_html__( 'WordPress Update: %s', 'automatic-updater' ), $site );
 
 
 
383
 
384
- $message = '<html>';
385
- $message .= '<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>';
386
- $message .= '<body>';
387
 
388
- $message .= esc_html__( 'Howdy!', 'automatic-updater' );
389
- $message .= '<br><br>';
390
- $message .= wp_kses( sprintf( __( 'Automatic Updater just ran on your site, <a href="%1$s">%1$s</a>, with the following result:', 'automatic-updater' ), $site ), array( 'a' => array( 'href' => array() ) ) );
391
- $message .= '<br><br>';
392
 
393
- $message .= $info;
394
 
395
- $message .= '<br>';
396
- $message .= esc_html__( 'Thanks for using the Automatic Updater plugin!', 'automatic-updater' );
 
 
397
 
398
- if ( ! empty( $options['debug'] ) ) {
399
- $message .= "<br><br><br>";
400
- $message .= esc_html__( 'Debug Information:', 'automatic-updater' );
401
- $message .= "<br><br>$debug";
402
  }
403
 
404
- $message .= '</body></html>';
 
 
405
 
406
- $email = get_option( 'admin_email' );
407
- if ( ! empty( $options['override-email'] ) )
408
- $email = $options['override-email'];
409
 
410
- $email = apply_filters( 'auto_updater_notification_email_address', $email );
 
 
411
 
412
- $headers = array(
413
- 'MIME-Version: 1.0',
414
- 'Content-Type: text/html; charset=UTF-8'
415
- );
416
 
417
- add_filter( 'wp_mail_content_type', 'auto_updater_wp_mail_content_type' );
418
- wp_mail( $email, $subject, $message, $headers );
419
- remove_filter( 'wp_mail_content_type', 'auto_updater_wp_mail_content_type' );
420
- }
 
421
 
422
- function auto_updater_wp_mail_content_type() {
423
- return 'text/html';
424
- }
425
 
426
- function auto_updater_get_update_data() {
427
- $counts = array( 'plugins' => 0, 'themes' => 0, 'wordpress' => 0 );
428
 
429
- $update_plugins = get_site_transient( 'update_plugins' );
430
- if ( ! empty( $update_plugins->response ) )
431
- $counts['plugins'] = count( $update_plugins->response );
 
 
 
432
 
433
- $update_themes = get_site_transient( 'update_themes' );
434
- if ( ! empty( $update_themes->response ) )
435
- $counts['themes'] = count( $update_themes->response );
 
436
 
437
- if ( function_exists( 'get_core_updates' ) ) {
438
- $update_wordpress = get_core_updates( array( 'dismissed' => false ) );
439
- if ( ! empty( $update_wordpress ) && 'latest' != $update_wordpress[0]->response )
440
- $counts['wordpress'] = 1;
441
- }
 
 
442
 
443
- $counts['total'] = $counts['plugins'] + $counts['themes'] + $counts['wordpress'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
444
 
445
- return apply_filters( 'auto_update_get_update_data', array( 'counts' => $counts ) );
 
446
  }
 
 
4
  * Plugin URI: http://pento.net/projects/automatic-updater-for-wordpress/
5
  * Description: Automatically update your WordPress site, as soon as updates are released! Never worry about falling behing on updating again!
6
  * Author: pento
7
+ * Version: 0.8
8
  * Author URI: http://pento.net/
9
  * License: GPL2+
10
  * Text Domain: automatic-updater
11
  * Domain Path: /languages/
12
  */
13
 
 
 
 
14
  $automatic_updater_file = __FILE__;
15
 
16
  if ( isset( $plugin ) )
20
  else if ( isset( $network_plugin ) )
21
  $automatic_updater_file = $network_plugin;
22
 
23
+ Automatic_Updater::$basename = plugin_basename( $automatic_updater_file );
24
 
25
+ class Automatic_Updater {
26
+ private $running = false;
27
+ private $options = array();
 
 
 
 
 
 
 
 
28
 
29
+ public static $basename;
 
 
30
 
31
+ function init() {
32
+ static $instance = false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
+ if( ! $instance )
35
+ $instance = new Automatic_Updater;
 
 
 
36
 
37
+ return $instance;
 
 
 
38
  }
39
 
40
+ function __construct() {
41
+ // Load the translations
42
+ load_plugin_textdomain( 'automatic-updater', false, dirname( self::$basename ) . '/languages/' );
 
 
43
 
44
+ // Load the options, and check that they're all up to date.
45
+ $this->options = get_option( 'automatic-updater', array() );
46
+ $this->plugin_upgrade();
47
+
48
+ add_action( 'shutdown', array( &$this, 'shutdown' ) );
49
+
50
+ add_action( 'auto_updater_core_event', array( &$this, 'update_core' ) );
51
+ add_action( 'auto_updater_plugins_event', array( &$this, 'update_plugins' ) );
52
+ add_action( 'auto_updater_themes_event', array( &$this, 'update_themes' ) );
53
+ add_action( 'auto_updater_svn_event', array( &$this, 'update_svn' ) );
54
+
55
+ // Nothing else matters if we're on WPMS and not on the main site
56
+ if ( is_multisite() && ! is_main_site() )
57
+ return;
58
+
59
+ if ( is_admin() ) {
60
+ include_once( dirname( __FILE__ ) . '/admin.php' );
61
+ Automatic_Updater_Admin::init( $this );
62
+ }
63
+
64
+ add_action( 'admin_init', array( &$this, 'check_wordpress_version' ) );
65
 
66
+ // Configure SVN updates cron, if it's enabled
67
+ if ( $this->options['svn']['core'] || ! empty( $this->options['svn']['plugins'] ) || ! empty( $this->options['svn']['themes'] ) ) {
68
+ if ( ! wp_next_scheduled( 'auto_updater_svn_event' ) )
69
+ wp_schedule_event( time(), 'hourly', 'auto_updater_svn_event' );
70
+ } else {
71
+ if ( $timestamp = wp_next_scheduled( 'auto_updater_svn_event' ) )
72
+ wp_unschedule_event( $timestamp, 'auto_updater_svn_event' );
73
+ }
74
+
75
+ // If the update check was one we called manually, don't get into a crazy recursive loop.
76
+ if ( $this->running )
77
+ return;
78
+
79
+ $types = array(
80
+ 'wordpress' => 'core',
81
+ 'plugins' => 'plugins',
82
+ 'themes' => 'themes'
83
+ );
84
+ if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
85
+ // We're in a cron, do updates now
86
+ foreach ( $types as $type ) {
87
+ if ( ! empty( $this->options['update'][ $type ] ) ) {
88
+ add_action( "set_site_transient_update_$type", array( &$this, "update_$type" ) );
89
+ add_action( "set_site_transient__site_transient_update_$type", array( &$this, "update_$type" ) );
90
+ }
91
+ }
92
+ } else {
93
+ include_once( ABSPATH . 'wp-admin/includes/update.php' );
94
+ $update_data = $this->get_update_data();
95
+ // Not in a cron, schedule updates to happen in the next cron run
96
+ foreach ( $types as $internal => $type ) {
97
+ if ( ! empty( $this->options['update'][ $type ] ) && $update_data['counts'][ $internal ] > 0 ) {
98
+ wp_schedule_single_event( time(), "auto_updater_{$type}_event" );
99
+ }
100
+ }
101
+ }
102
  }
103
 
104
+ function shutdown() {
105
+ update_option( 'automatic-updater', $this->options );
 
 
106
  }
107
+
108
+ function get_option( $name ) {
109
+ if ( array_key_exists( $name, $this->options ) )
110
+ return $this->options[ $name ];
111
+
112
+ return null;
113
  }
114
 
115
+ function update_option( $name, $value ) {
116
+ if ( array_key_exists( $name, $this->options ) )
117
+ return $this->options[ $name ] = $value;
118
 
119
+ return null;
120
+ }
 
 
121
 
122
+ function check_wordpress_version() {
123
+ if ( version_compare( $GLOBALS['wp_version'], '3.4', '<' ) ) {
124
+ if ( is_plugin_active( self::$basename ) ) {
125
+ deactivate_plugins( self::$basename );
126
+ add_action( 'admin_notices', array( &$this, 'disabled_notice' ) );
127
+ if ( isset( $_GET['activate'] ) )
128
+ unset( $_GET['activate'] );
129
  }
130
  }
131
  }
132
+
133
+ function disabled_notice() {
134
+ echo '<div class="updated"><p><strong>' . esc_html__( 'Automatic Updater requires WordPress 3.4 or higher! Please upgrade WordPress manually, then reactivate Automatic Updater.', 'automatic-updater' ) . '</strong></p></div>';
 
 
 
 
 
 
135
  }
 
 
136
 
137
+ function plugin_upgrade() {
138
+ if ( empty( $this->options ) ) {
139
+ // Don't automatically enable core updates in installs coming from a repo
140
+ $core_updates_enabled = true;
141
+ if ( is_dir( ABSPATH . '/.svn' ) || is_dir( ABSPATH . '/.git' ) )
142
+ $core_updates_enabled = false;
143
+
144
+ $this->options = array(
145
+ 'update' => array(
146
+ 'core' => $core_updates_enabled,
147
+ 'plugins' => false,
148
+ 'themes' => false,
149
+ ),
150
+ 'retries-limit' => 3,
151
+ 'tries' => array(
152
+ 'core' => array(
153
+ 'version' => 0,
154
+ 'tries' => 0,
155
+ ),
156
+ 'plugins' => array(),
157
+ 'themes' => array(),
158
+ ),
159
+ 'svn' => array(
160
+ 'core' => false,
161
+ 'plugins' => array(),
162
+ 'themes' => array(),
163
+ ),
164
+ 'svn-success-email' => true,
165
+ 'debug' => false,
166
+ 'next-development-update' => time(),
167
+ 'override-email' => '',
168
+ 'disable-email' => false,
169
+ );
170
+ }
171
 
172
+ // 'debug' option added in version 0.3
173
+ if ( ! array_key_exists( 'debug', $this->options ) )
174
+ $this->options['debug'] = false;
175
+
176
+ // SVN updates added in version 0.5
177
+ if ( ! array_key_exists( 'svn', $this->options ) )
178
+ $this->options['svn'] = false;
179
+
180
+ // Development version updates added in version 0.6
181
+ if ( ! array_key_exists( 'next-development-update', $this->options ) )
182
+ $this->options['next-development-update'] = time();
183
+
184
+ // Override contact email added in version 0.7
185
+ if ( ! array_key_exists( 'override-email', $this->options ) )
186
+ $this->options['override-email'] = '';
187
+
188
+ // Ability to disable email added in version 0.7
189
+ if ( ! array_key_exists( 'disable-email', $this->options ) )
190
+ $this->options['disable-email'] = false;
191
+
192
+ // Ability to limit retries added in version 0.8
193
+ if ( ! array_key_exists( 'retries-limit', $this->options ) ) {
194
+ $this->options['retries-limit'] = 3;
195
+ $this->options['tries'] = array(
196
+ 'core' => array(
197
+ 'version' => 0,
198
+ 'tries' => 0,
199
+ ),
200
+ 'plugins' => array(),
201
+ 'themes' => array(),
202
+ );
203
+ }
204
 
205
+ // Ability to only send SVN update emails on failure added in 0.8
206
+ if ( ! array_key_exists( 'svn-success-email', $this->options ) )
207
+ $this->options['svn-success-email'] = true;
208
+
209
+ // SVN support for themes and plugins added in 0.8
210
+ if ( ! is_array( $this->options['svn'] ) )
211
+ $this->options['svn'] = array(
212
+ 'core' => $this->options['svn'],
213
+ 'plugins' => array(),
214
+ 'themes' => array(),
215
+ );
216
+ }
217
 
218
+ function update_core() {
219
+ if ( $this->running )
220
+ return;
221
 
222
+ if ( $this->options['svn'] )
223
+ return;
 
224
 
225
+ // Forgive me father, for I have sinned. I have included wp-admin files in a plugin.
226
+ include_once( ABSPATH . 'wp-admin/includes/update.php' );
227
+ include_once( ABSPATH . 'wp-admin/includes/file.php' );
 
228
 
229
+ include_once( dirname( __FILE__ ) . '/updater-skin.php' );
 
 
230
 
231
+ $updates = get_core_updates();
232
+ if ( empty( $updates ) )
233
+ return;
234
 
235
+ if ( 'development' == $updates[0]->response )
236
+ $update = $updates[0];
237
+ else
238
+ $update = find_core_update( $updates[0]->current, $updates[0]->locale );
239
 
240
+ $update = apply_filters( 'auto_updater_core_updates', $update );
241
+ if ( empty( $update ) )
 
242
  return;
243
 
244
+ // Check that we haven't failed to upgrade to the updated version in the past
245
+ if ( version_compare( $update->current, $this->options['retries']['core']['version'], '>=' ) && $this->options['retries']['core']['tries'] >= $this->option['retries-limit'] )
246
+ return;
247
 
248
+ $old_version = $GLOBALS['wp_version'];
249
 
250
+ // Sanity check that the new upgrade is actually an upgrade
251
+ if ( 'development' != $update->response && version_compare( $old_version, $update->current, '>=' ) )
252
+ return;
253
 
254
+ // Only do development version updates once every 24 hours
255
+ if ( 'development' == $update->response ) {
256
+ if ( time() < $this->options['next-development-update'] )
257
+ return;
258
 
259
+ $this->options['next-development-update'] = strtotime( '+24 hours' );
260
+ }
261
 
262
+ $this->running = true;
 
 
 
 
 
 
 
 
 
 
 
 
263
 
264
+ do_action( 'auto_updater_before_update', 'core' );
265
 
266
+ $upgrade_failed = false;
267
 
268
+ $skin = new Auto_Updater_Skin();
269
+ $upgrader = new Core_Upgrader( $skin );
270
+ $result = $upgrader->upgrade( $update );
271
 
272
+ do_action( 'auto_updater_after_update', 'core' );
 
 
273
 
274
+ if ( is_wp_error( $result ) ) {
275
+ if ( $this->options['tries']['core']['version'] != $update->current )
276
+ $this->options['tries']['core']['version'] = $update->current;
 
277
 
278
+ $this->options['tries']['core']['tries']++;
 
 
279
 
280
+ $upgrade_failed = true;
281
 
282
+ $message = esc_html__( "While trying to upgrade WordPress, we ran into the following error:", 'automatic-updater' );
283
+ $message .= '<br><br>' . $result->get_error_message() . '<br><br>';
284
+ $message .= sprintf( esc_html__( 'We\'re sorry it didn\'t work out. Please try upgrading manually, instead. This is attempt %1$d of %2$d.', 'automatic-updater' ),
285
+ $this->options['tries']['core']['tries'],
286
+ $this->option['retries-limit'] );
287
+ } else if( 'development' == $update->response ) {
288
+ $message = esc_html__( "We've successfully upgraded WordPress to the latest nightly build!", 'automatic-updater' );
289
+ $message .= '<br><br>' . esc_html__( 'Have fun!', 'automatic-updater' );
290
 
291
+ $this->options['tries']['core']['version'] = 0;
292
+ $this->options['tries']['core']['tries'] = 0;
293
+ } else {
294
+ $message = sprintf( esc_html__( 'We\'ve successfully upgraded WordPress from version %1$s to version %2$s!', 'automatic-updater' ), $old_version, $update->current );
295
+ $message .= '<br><br>' . esc_html__( 'Have fun!', 'automatic-updater' );
296
 
297
+ $this->options['tries']['core']['version'] = 0;
298
+ $this->options['tries']['core']['tries'] = 0;
299
+ }
300
 
301
+ $message .= '<br>';
302
 
303
+ $debug = join( '<br>', $skin->messages );
304
 
305
+ $this->notification( $message, $debug, $upgrade_failed );
 
 
306
 
307
+ wp_version_check();
308
+ }
309
 
310
+ function update_plugins() {
311
+ if ( $this->running )
312
+ return;
313
 
314
+ include_once( ABSPATH . 'wp-admin/includes/update.php' );
315
+ include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
316
+ include_once( ABSPATH . 'wp-admin/includes/file.php' );
317
+
318
+ include_once( dirname( __FILE__ ) . '/updater-skin.php' );
319
+
320
+ $plugins = apply_filters( 'auto_updater_plugin_updates', get_plugin_updates() );
321
+
322
+ foreach ( $plugins as $id => $plugin ) {
323
+ // Remove any plugins from the list that may've already been updated
324
+ if ( version_compare( $plugin->Version, $plugin->update->new_version, '>=' ) )
325
+ unset( $plugins[ $id ] );
326
+
327
+ // Remove any plugins that have failed to upgrade
328
+ if ( ! empty( $this->options['retries']['plugins'][ $id ] ) ) {
329
+ // If there's a new version of a failed plugin, we should give it another go.
330
+ if ( $this->options['retries']['plugins'][ $id ]['version'] != $plugin->update->new_version )
331
+ unset( $this->options['retries']['plugins'][ $id ] );
332
+ // If the plugin has already had it's chance, move on.
333
+ else if ($this->options['retries']['plugins'][ $id ]['tries'] > $this->options['retries-limit'] )
334
+ unset( $plugins[ $id ] );
335
+ }
336
  }
337
+
338
+ if ( empty( $plugins ) )
339
+ return;
340
+
341
+ $this->running = true;
342
+
343
+ do_action( 'auto_updater_before_update', 'plugins' );
344
+
345
+ $skin = new Auto_Updater_Skin();
346
+ $upgrader = new Plugin_Upgrader( $skin );
347
+ $result = $upgrader->bulk_upgrade( array_keys( $plugins ) );
348
+
349
+ do_action( 'auto_updater_after_update', 'plugins' );
350
+
351
+ $message = esc_html( _n( 'We found a plugin upgrade!', 'We found upgrades for some plugins!', count( $plugins ), 'automatic-updater' ) );
352
+ $message .= '<br><br>';
353
+
354
+ $upgrade_failed = false;
355
+
356
+ foreach ( $plugins as $id => $plugin ) {
357
+ if ( is_wp_error( $result[ $id ] ) ) {
358
+ if ( empty( $this->options['retries']['plugins'][ $id ] ) )
359
+ $this->options['retries']['plugins'][ $id ] = array(
360
+ 'tries' => 1,
361
+ 'version' => $plugin->update->new_version,
362
+ );
363
+ else
364
+ $this->options['retries']['plugins'][ $id ]['tries']++;
365
+
366
+ $upgrade_failed = true;
367
+
368
+ /* translators: First argument is the plugin url, second argument is the Plugin name, third argument is the error encountered while upgrading. The fourth and fifth arguments refer to how many retries we've had at installing this plugin. */
369
+ $message .= wp_kses( sprintf( __( '<a href="%1$s">%2$s</a>: We encounted an error upgrading this plugin: %3$s (Attempt %4$d of %5$d)', 'automatic-updater' ),
370
+ $plugin->update->url,
371
+ $plugin->Name,
372
+ $result[ $id ]->get_error_message(),
373
+ $this->options['retries']['plugins'][ $id ]['tries'],
374
+ $this->options['retries-limit'] ),
375
+ array( 'a' => array( 'href' => array() ) ) );
376
+ } else {
377
+ /* translators: First argument is the plugin url, second argument is the Plugin name, third argument is the old version number, fourth argument is the new version number */
378
+ $message .= wp_kses( sprintf( __( '<a href="%1$s">%2$s</a>: Successfully upgraded from version %3$s to %4$s!', 'automatic-updater' ),
379
+ $plugin->update->url,
380
+ $plugin->Name,
381
+ $plugin->Version,
382
+ $plugin->update->new_version ), array( 'a' => array( 'href' => array() ) ) );
383
+
384
+ if ( ! empty( $this->options['retries']['plugins'][ $id ] ) )
385
+ unset( $this->options['retries']['plugins'][ $id ] );
386
+ }
387
+
388
+ $message .= '<br>';
389
  }
390
 
391
+ $message .= '<br>' . esc_html__( 'Plugin authors depend on your feedback to make their plugins better, and the WordPress community depends on plugin ratings for checking the quality of a plugin. If you have a couple of minutes, click on the plugin names above, and leave a Compatibility Vote or a Rating!', 'automatic-updater' ) . '<br>';
392
+
393
+ $debug = join( '<br>', $skin->messages );
394
+
395
+ $this->notification( $message, $debug, $upgrade_failed );
396
+
397
+ wp_update_plugins();
398
  }
399
 
400
+ function update_themes() {
401
+ if ( $this->running )
402
+ return;
403
+
404
+ include_once( ABSPATH . 'wp-admin/includes/update.php' );
405
+ include_once( ABSPATH . 'wp-admin/includes/file.php' );
406
+
407
+ include_once( dirname( __FILE__ ) . '/updater-skin.php' );
408
 
409
+ $themes = apply_filters( 'auto_updater_theme_updates', get_theme_updates() );
410
 
411
+ foreach ( $themes as $id => $theme ) {
412
+ // Remove any themes from the list that may've already been updated
413
+ if ( version_compare( $theme->Version, $theme->update['new_version'], '>=' ) )
414
+ unset( $themes[ $id ] );
415
 
416
+ // Remove any themes that have failed to upgrade
417
+ if ( ! empty( $this->options['retries']['themes'][ $id ] ) ) {
418
+ // If there's a new version of a failed theme, we should give it another go.
419
+ if ( $this->options['retries']['themes'][ $id ]['version'] != $theme->update['new_version'] )
420
+ unset( $this->options['retries']['themes'][ $id ] );
421
+ // If the themes has already had it's chance, move on.
422
+ else if ($this->options['retries']['themes'][ $id ]['tries'] > $this->options['retries-limit'] )
423
+ unset( $themes[ $id ] );
424
+ }
425
+ }
426
+
427
+ if ( empty( $themes ) )
428
+ return;
429
 
430
+ $this->running = true;
431
+
432
+ do_action( 'auto_updater_before_update', 'themes' );
433
+
434
+ $skin = new Auto_Updater_Skin();
435
+ $upgrader = new Theme_Upgrader( $skin );
436
+ $result = $upgrader->bulk_upgrade( array_keys( $themes ) );
437
+
438
+ do_action( 'auto_updater_after_update', 'themes' );
439
+
440
+ $message = esc_html( _n( 'We found a theme upgrade!', 'We found upgrades for some themes!', count( $themes ), 'automatic-updater' ) );
441
+ $message .= '<br><br>';
442
+
443
+ $upgrade_failed = false;
444
+
445
+ foreach ( $themes as $id => $theme ) {
446
+ if ( is_wp_error( $result[ $id ] ) ) {
447
+ if ( empty( $this->options['retries']['themes'][ $id ] ) )
448
+ $this->options['retries']['themes'][ $id ] = array(
449
+ 'tries' => 1,
450
+ 'version' => $themes->update['new_version'],
451
+ );
452
+ else
453
+ $this->options['retries']['themes'][ $id ]['tries']++;
454
+
455
+ $upgrade_failed = true;
456
+
457
+ /* translators: First argument is the theme URL, second argument is the Theme name, third argument is the error encountered while upgrading. The fourth and fifth arguments refer to how many retries we've had at installing this theme. */
458
+ $message .= wp_kses( sprintf( __( '<a href="%1$s">%2$s</a>: We encounted an error upgrading this theme: %3$s (Attempt %4$d of %5$d)', 'automatic-updater' ),
459
+ $theme->update['url'],
460
+ $theme->name,
461
+ $result[ $id ]->get_error_message(),
462
+ $this->options['retries']['plugins'][ $id ]['tries'],
463
+ $this->options['retries-limit'] ),
464
+ array( 'a' => array( 'href' => array() ) ) );
465
+ } else {
466
+ /* translators: First argument is the theme URL, second argument is the Theme name, third argument is the old version number, fourth argument is the new version number */
467
+ $message .= wp_kses( sprintf( __( '<a href="%1$s">%2$s</a>: Successfully upgraded from version %3$s to %4$s!', 'automatic-updater' ),
468
+ $theme->update['url'],
469
+ $theme->name,
470
+ $theme->version,
471
+ $theme->update['new_version'] ), array( 'a' => array( 'href' => array() ) ) );
472
+
473
+ if ( ! empty( $this->options['retries']['themes'][ $id ] ) )
474
+ unset( $this->options['retries']['themes'][ $id ] );
475
+ }
476
+
477
+ $message .= '<br>';
478
+ }
479
 
480
+ $message .= '<br>' . esc_html__( 'Theme authors depend on your feedback to make their plugins better, and the WordPress community depends on theme ratings for checking the quality of a theme. If you have a couple of minutes, click on the theme names above, and leave a Compatibility Vote or a Rating!', 'automatic-updater' ) . '<br>';
 
481
 
482
+ $debug = join( '<br>', $skin->messages );
483
 
484
+ $this->notification( $message, $debug, $upgrade_failed );
485
 
486
+ wp_update_themes();
 
 
 
487
  }
488
 
489
+ function update_svn() {
490
+ $output = array();
491
+ $return = null;
492
+
493
+ $message = '';
494
 
495
+ $found_error = false;
496
+ $found_update = false;
497
 
498
+ $source_control = $this->under_source_control();
499
 
500
+ if ( $source_control['core'] && 'svn' === $this->options['svn']['core'] ) {
501
+ $output[] = esc_html__( 'WordPress Core:', 'automatic-updater' );
502
+ exec( 'svn up ' . ABSPATH, $output, $return );
503
 
504
+ if ( 0 !== strpos( $update, "At revision" ) ) {
505
+ $found_update = true;
506
 
507
+ $update = end( $output );
 
508
 
509
+ if ( 0 === $return ) {
510
+ $message .= esc_html__( 'We successfully upgraded WordPress Core from SVN!', 'automatic-updater' );
511
+ $message .= "<br><br>$update";
512
+ } else {
513
+ $found_error = true;
514
+
515
+ $message .= esc_html__( 'While upgrading WordPress Core from SVN, we ran into the following error:', 'automatic-updater' );
516
+ $message .= "<br><br>$update<br><br>";
517
+ $message .= esc_html__( "We're sorry it didn't work out. Please try upgrading manually, instead.", 'automatic-updater' );
518
+ }
519
+ }
520
  }
521
+
522
+ if ( ! empty( $source_control['plugins'] ) && ! empty( $this->options['svn']['plugins'] ) ) {
523
+ $plugin_message = '';
524
+
525
+ include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
526
+
527
+ $plugin_upgrades = 0;
528
+ foreach ( $this->options['svn']['plugins'] as $id => $type ) {
529
+ // We only support SVN at the moment
530
+ if ( 'svn' !== $type )
531
+ continue;
532
+
533
+ // Check that this plugin is still under source control
534
+ if ( ! array_key_exists( $id, $source_control['plugins'] ) )
535
+ continue;
536
+
537
+ $plugin = get_plugin_data( WP_PLUGIN_DIR . '/' . $id );
538
+
539
+ $output[] = '';
540
+ $output[] = "{$plugin['Name']} ($id):";
541
+
542
+ exec( 'svn up ' . WP_PLUGIN_DIR . '/' . plugin_dir_path( $id ), $output, $return );
543
+
544
+ $update = end( $output );
545
+
546
+ if ( 0 !== strpos( $update, "At revision" ) ) {
547
+ $plugin_upgrades++;
548
+ $found_update = true;
549
+
550
+ if ( 0 !== $return )
551
+ $found_error = true;
552
+
553
+ $plugin_message .= "{$plugin['Name']}: $update<br>";
554
+ }
555
+ }
556
+
557
+ if ( ! empty( $plugin_message ) ) {
558
+ $message .= esc_html( _n( 'We upgraded the following plugin:', 'We upgraded the following plugins:', $plugin_upgrades, 'automatic-updater' ) );
559
+ $message .= "<br><br>$plugin_message";
560
+ }
561
  }
562
 
563
+ if ( ! empty( $source_control['themes'] ) && ! empty( $this->options['svn']['themes'] ) ) {
564
+ $theme_message = '';
565
 
566
+ $theme_upgrades = 0;
567
+ foreach ( $this->options['svn']['themes'] as $id => $type ) {
568
+ // We only support SVN at the moment
569
+ if ( 'svn' !== $type )
570
+ continue;
571
 
572
+ // Check that this theme is still under source control
573
+ if ( ! array_key_exists( $id, $source_control['themes'] ) )
574
+ continue;
575
 
576
+ $theme = wp_get_theme( $id );
577
 
578
+ $output[] = '';
579
+ $output[] = "{$theme->name} ($id):";
580
+
581
+ exec( 'svn up ' . $theme->get_stylesheet_directory(), $output, $return );
582
 
583
+ $update = end( $output );
 
 
584
 
585
+ if ( 0 !== strpos( $update, "At revision" ) ) {
586
+ $theme_upgrades++;
587
+ $found_update = true;
588
 
589
+ if ( 0 !== $return )
590
+ $found_error = true;
591
+
592
+ $theme_message .= "{$theme->name}: $update<br>";
593
+ }
594
+ }
595
+
596
+ if ( ! empty( $theme_message ) ) {
597
+ $message .= esc_html( _n( 'We upgraded the following theme:', 'We upgraded the following themes:', $theme_upgrades, 'automatic-updater' ) );
598
+ $message .= "<br><br>$theme_message";
599
+ }
600
+ }
601
+
602
+ // No need to email if there were no updates.
603
+ if ( ! $found_update )
604
  return;
605
 
606
+ // If we're only sending emails on failure, check if any errors were found
607
+ if( ! $found_error && ! $this->options['svn-success-email'] )
608
+ return;
609
+
610
+ $message .= '<br>';
611
+
612
+ $debug = join( '<br>', $output );
613
+
614
+ $this->notification( $message, $debug );
615
  }
616
 
617
+ function notification( $info = '', $debug = '', $upgrade_failed = false ) {
618
+ if ( $this->options['disable-email'] )
619
+ return;
620
 
621
+ $site = get_home_url();
622
+ $subject = sprintf( esc_html__( 'WordPress Update: %s', 'automatic-updater' ), $site );
623
 
624
+ $message = '<html>';
625
+ $message .= '<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>';
626
+ $message .= '<body>';
627
+
628
+ $message .= esc_html__( 'Howdy!', 'automatic-updater' );
629
+ $message .= '<br><br>';
630
+ $message .= wp_kses( sprintf( __( 'Automatic Updater just ran on your site, <a href="%1$s">%1$s</a>, with the following result:', 'automatic-updater' ), $site ), array( 'a' => array( 'href' => array() ) ) );
631
+ $message .= '<br><br>';
632
+
633
+ $message .= $info;
634
 
635
+ $message .= '<br>';
636
+
637
+ if ( $upgrade_failed ) {
638
+ $message .= esc_html__( 'It looks like something went wrong during the update. Note that, if Automatic Updater continues to encounter problems, it will stop trying to do this update, and will not try again until after you manually update.', 'automatic-updater' );
639
+ $message .= '<br><br>';
640
+ }
641
 
642
+ $message .= esc_html__( 'Thanks for using the Automatic Updater plugin!', 'automatic-updater' );
 
643
 
644
+ if ( ! empty( $this->options['debug'] ) ) {
645
+ $message .= "<br><br><br>";
646
+ $message .= esc_html__( 'Debug Information:', 'automatic-updater' );
647
+ $message .= "<br><br>$debug";
648
+ }
649
 
650
+ $message .= '</body></html>';
 
 
651
 
652
+ $email = get_option( 'admin_email' );
653
+ if ( ! empty( $this->options['override-email'] ) )
654
+ $email = $this->options['override-email'];
 
655
 
656
+ $email = apply_filters( 'auto_updater_notification_email_address', $email );
657
 
658
+ $headers = array(
659
+ 'MIME-Version: 1.0',
660
+ 'Content-Type: text/html; charset=UTF-8'
661
+ );
662
 
663
+ add_filter( 'wp_mail_content_type', array( &$this, 'wp_mail_content_type' ) );
664
+ wp_mail( $email, $subject, $message, $headers );
665
+ remove_filter( 'wp_mail_content_type', array( &$this, 'wp_mail_content_type' ) );
 
666
  }
667
 
668
+ function wp_mail_content_type() {
669
+ return 'text/html';
670
+ }
671
 
672
+ function get_update_data() {
673
+ $counts = array( 'plugins' => 0, 'themes' => 0, 'wordpress' => 0 );
 
674
 
675
+ $update_plugins = get_site_transient( 'update_plugins' );
676
+ if ( ! empty( $update_plugins->response ) )
677
+ $counts['plugins'] = count( $update_plugins->response );
678
 
679
+ $update_themes = get_site_transient( 'update_themes' );
680
+ if ( ! empty( $update_themes->response ) )
681
+ $counts['themes'] = count( $update_themes->response );
 
682
 
683
+ if ( function_exists( 'get_core_updates' ) ) {
684
+ $update_wordpress = get_core_updates( array( 'dismissed' => false ) );
685
+ if ( ! empty( $update_wordpress ) && 'latest' != $update_wordpress[0]->response )
686
+ $counts['wordpress'] = 1;
687
+ }
688
 
689
+ $counts['total'] = $counts['plugins'] + $counts['themes'] + $counts['wordpress'];
 
 
690
 
691
+ return apply_filters( 'auto_update_get_update_data', array( 'counts' => $counts ) );
692
+ }
693
 
694
+ function under_source_control( $types = array( 'svn' ) ) {
695
+ $return = array(
696
+ 'core' => false,
697
+ 'plugins' => array(),
698
+ 'themes' => array()
699
+ );
700
 
701
+ $supported_checks = array( 'svn', 'git' );
702
+ foreach ( $types as $id => $type )
703
+ if ( ! in_array( $type, $supported_checks ) )
704
+ unset( $types[ $id ] );
705
 
706
+ if ( empty( $types ) )
707
+ return $return;
708
+
709
+ include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
710
+
711
+ $plugins = get_plugins();
712
+ $themes = wp_get_themes();
713
 
714
+ foreach ( $types as $type ) {
715
+ if ( is_dir( ABSPATH . "/.$type" ) )
716
+ $return['core'] = $type;
717
+
718
+ foreach ( $plugins as $id => $plugin )
719
+ if ( plugin_dir_path( $id ) != './' && is_dir( WP_PLUGIN_DIR . '/' . plugin_dir_path( $id ) . ".$type" ) )
720
+ $return['plugins'][ $id ] = array(
721
+ 'type' => $type,
722
+ 'plugin' => $plugin
723
+ );
724
+
725
+ foreach ( $themes as $id => $theme )
726
+ if ( is_dir( $theme->get_stylesheet_directory() . "/.$type" ) )
727
+ $return['themes'][ $id ] = array(
728
+ 'type' => $type,
729
+ 'theme' => $theme
730
+ );
731
+ }
732
 
733
+ return $return;
734
+ }
735
  }
736
+
737
+ add_action( 'init', array( 'Automatic_Updater', 'init' ) );
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://pento.net/donate/
4
  Tags: updates, core, plugins, themes, stable, nightly, svn, wordpress automatic upgrader
5
  Requires at least: 3.4
6
  Tested up to: 3.5
7
- Stable tag: 0.7.1
8
  License: GPL2+
9
 
10
  Automatically update WordPress, your themes and plugins! Never have to click the update button again!
@@ -43,6 +43,13 @@ There are some Actions and Filters provided, check the [Documentation](http://pe
43
 
44
  == Changelog ==
45
 
 
 
 
 
 
 
 
46
  = 0.7.2 =
47
  * ADDED: WordPress MultiSite support
48
  * UPDATED: German (de_DE) translation. Props [Alexander Pfabel](http://alexander.pfabel.de/)
4
  Tags: updates, core, plugins, themes, stable, nightly, svn, wordpress automatic upgrader
5
  Requires at least: 3.4
6
  Tested up to: 3.5
7
+ Stable tag: 0.7.2
8
  License: GPL2+
9
 
10
  Automatically update WordPress, your themes and plugins! Never have to click the update button again!
43
 
44
  == Changelog ==
45
 
46
+ = 0.8 =
47
+ * ADDED: SVN support for plugins and themes
48
+ * ADDED: Retry limits, so broken updates won't keep trying to install
49
+ * ADDED: Option to only receive SVN update emails if something went wrong
50
+ * FIXED: Some HTML tags in debug messages were being incorrectly stripped
51
+ * FIXED: Don't automatically enable Core updates on installs that seem to be coming from a repo
52
+
53
  = 0.7.2 =
54
  * ADDED: WordPress MultiSite support
55
  * UPDATED: German (de_DE) translation. Props [Alexander Pfabel](http://alexander.pfabel.de/)
updater-skin.php CHANGED
@@ -18,8 +18,8 @@ class Auto_Updater_Skin extends WP_Upgrader_Skin {
18
  else
19
  $string = $data;
20
 
21
- if ( ! empty( $this->upgrader->strings[$string] ) )
22
- $string = $this->upgrader->strings[$string];
23
 
24
  if ( strpos($string, '%') !== false ) {
25
  $args = func_get_args();
@@ -31,7 +31,7 @@ class Auto_Updater_Skin extends WP_Upgrader_Skin {
31
  $string = trim( $string );
32
 
33
  // Only allow basic HTML in the messages
34
- $string = wp_kses( $string, array( 'a' => array( 'href' ), 'br', 'em', 'strong' ) );
35
 
36
  if ( empty( $string ) )
37
  return;
18
  else
19
  $string = $data;
20
 
21
+ if ( ! empty( $this->upgrader->strings[ $string ] ) )
22
+ $string = $this->upgrader->strings[ $string ];
23
 
24
  if ( strpos($string, '%') !== false ) {
25
  $args = func_get_args();
31
  $string = trim( $string );
32
 
33
  // Only allow basic HTML in the messages
34
+ $string = wp_kses( $string, array( 'a' => array( 'href' => array() ), 'br' => array(), 'em' => array(), 'strong' => array() ) );
35
 
36
  if ( empty( $string ) )
37
  return;