Advanced Automatic Updates - Version 0.1

Version Description

Download this release

Release Info

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

Version 0.1

Files changed (4) hide show
  1. admin.php +85 -0
  2. automatic-updater.php +143 -0
  3. readme.txt +16 -0
  4. updater-skin.php +43 -0
admin.php ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action( 'admin_menu', 'auto_updater_plugin_menu' );
4
+
5
+ function auto_updater_plugin_menu() {
6
+ $hook = add_options_page( __( 'Automatic Updater', 'automatic-updater' ), __( 'Automatic Updater', 'automatic-updater' ), 'update_core', 'automatic-updater', 'auto_updater_settings' );
7
+ add_action( "load-$hook", 'auto_updater_settings_loader' );
8
+ }
9
+
10
+ function auto_updater_settings_loader() {
11
+ get_current_screen()->add_help_tab( array(
12
+ 'id' => 'overview',
13
+ 'title' => __( 'Overview', 'automatic-updater' ),
14
+ 'content' =>
15
+ '<p>' . __( '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>' .
16
+ '<p>' . __( '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>'
17
+ ) );
18
+
19
+ get_current_screen()->set_help_sidebar(
20
+ '<p><strong>' . sprintf( __( 'A Plugin By <a href="%s" target="_blank">Gary</a>', 'automatic-updater' ), 'http://pento.net/' ) . '</strong></p>' .
21
+ '<p><a href="http://pento.net/donate/">' . __( 'Donations', 'automatic-updater' ) . '</a></p>' .
22
+ '<p><a href="">' . __( 'Support Forums', 'automatic-updater' ) . '</a></p>'
23
+ );
24
+ }
25
+
26
+ function auto_updater_settings() {
27
+ if ( ! current_user_can( 'update_core' ) )
28
+ wp_die( __( 'You do not have sufficient permissions to access this page.', 'automatic-updater' ) );
29
+
30
+ $message = '';
31
+ if ( ! empty( $_REQUEST['submit'] ) ) {
32
+ check_admin_referer( 'automatic-updater-settings' );
33
+
34
+ auto_updater_save_settings();
35
+ $message = __( 'Settings updated', 'automatic-updater' );
36
+ }
37
+ $options = get_option( 'automatic-updater' );
38
+ $messages = array(
39
+ 'core' => __( 'Update WordPress Core automatically? <strong>(Strongly Recommended)</strong>', 'automatic-updater' ),
40
+ 'plugins' => __( 'Update your plugins automatically?', 'automatic-updater' ),
41
+ 'themes' => __( 'Updater your themes automatically?', 'automatic-updater' )
42
+ );
43
+ ?>
44
+ <div class="wrap">
45
+ <?php screen_icon('tools'); ?>
46
+ <h2><?php _e( 'Automattic Updater', 'automatic-updater' ); ?></h2>
47
+ <?php
48
+ if ( ! empty( $message ) ) {
49
+ ?>
50
+ <div class="updated">
51
+ <p><?php echo $message; ?></p>
52
+ </div>
53
+ <?php
54
+ }
55
+ ?>
56
+ <form method="post">
57
+ <?php wp_nonce_field( 'automatic-updater-settings' ); ?>
58
+ <?php
59
+ foreach ( $options['update'] as $type => $enabled ) {
60
+ $checked = '';
61
+ if ( $enabled )
62
+ $checked = ' checked="checked"';
63
+
64
+ echo "<p><input type='checkbox' id='$type' name='$type' value='1'$checked> <label for='$type'>{$messages[$type]}</label></p>";
65
+ }
66
+ ?>
67
+ <p><input class="button button-primary" type="submit" name="submit" id="submit" value="<?php esc_attr_e( 'Save Changes', 'automatic-updater' ); ?>" /></p>
68
+ </form>
69
+ </div>
70
+ <?php
71
+ }
72
+
73
+ function auto_updater_save_settings() {
74
+ $types = array( 'core', 'plugins', 'themes' );
75
+ $options = get_option( 'automatic-updater' );
76
+
77
+ foreach ( $types as $type ) {
78
+ if ( ! empty( $_REQUEST[$type] ) )
79
+ $options['update'][$type] = true;
80
+ else
81
+ $options['update'][$type] = false;
82
+ }
83
+
84
+ update_option( 'automatic-updater', $options );
85
+ }
automatic-updater.php ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * Plugin Name: Automatic Updater
4
+ * Plugin URI: http://pento.net/
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.1
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
+ function auto_updater_init() {
18
+ if ( is_admin() )
19
+ include_once( dirname( __FILE__ ) . '/admin.php' );
20
+
21
+ $options = get_option( 'automatic-updater', array() );
22
+
23
+ if ( empty( $options ) ) {
24
+ $options = array(
25
+ 'update' => array(
26
+ 'core' => true,
27
+ 'plugins' => false,
28
+ 'themes' => false,
29
+ ),
30
+ );
31
+ update_option( 'automatic-updater', $options );
32
+ }
33
+
34
+ global $auto_updater_running;
35
+ // If the update check was one we called manually, don't get into a crazy recusive loop.
36
+ if ( $auto_updater_running )
37
+ return;
38
+
39
+ // Only do this during the wp-cron version check, it'd suck if the upgrade was interrupted.
40
+ if ( ! defined( 'DOING_CRON' ) || ! DOING_CRON )
41
+ return;
42
+
43
+ if ( ! empty( $options['update']['core'] ) ) {
44
+ add_action( 'set_site_transient_update_core', 'auto_updater_core');
45
+ add_action( 'set_site_transient__site_transient_update_core', 'auto_updater_core');
46
+ }
47
+ if ( ! empty( $options['update']['plugins'] ) ) {
48
+ add_action( 'set_site_transient_update_plugins', 'auto_updater_plugins' );
49
+ add_action( 'set_site_transient__site_transient_update_plugins', 'auto_updater_plugins' );
50
+ }
51
+ if ( ! empty( $options['update']['themes'] ) ) {
52
+ add_action( 'set_site_transient_update_themes', 'auto_updater_themes' );
53
+ add_action( 'set_site_transient__site_transient_update_themes', 'auto_updater_themes' );
54
+ }
55
+ }
56
+ add_action( 'init', 'auto_updater_init' );
57
+
58
+ function auto_updater_core() {
59
+ global $auto_updater_running;
60
+ if ( $auto_updater_running )
61
+ return;
62
+
63
+ // Forgive me father, for I have sinned. I have included wp-admin files in a plugin.
64
+ // It's behind a DOING_CRON check, so won't cause much trouble.
65
+ include_once( ABSPATH . 'wp-admin/includes/update.php' );
66
+ include_once( ABSPATH . 'wp-admin/includes/file.php' );
67
+
68
+ include_once( dirname( __FILE__ ) . '/updater-skin.php' );
69
+
70
+ $updates = get_core_updates();
71
+ if ( empty( $updates ) )
72
+ return;
73
+
74
+ $update = find_core_update( $updates[0]->current, $updates[0]->locale );
75
+ if ( empty( $update ) )
76
+ return;
77
+
78
+ $auto_updater_running = true;
79
+
80
+ $skin = new Auto_Updater_Skin();
81
+ $upgrader = new Core_Upgrader( $skin );
82
+ $upgrader->upgrade( $update );
83
+
84
+ $message = join( "\r\n", $skin->messages );
85
+
86
+ wp_mail( get_option( 'admin_email' ), __( 'Core Update', 'automatic-updater' ), $message );
87
+
88
+ wp_version_check();
89
+ }
90
+
91
+ function auto_updater_plugins() {
92
+ global $auto_updater_running;
93
+ if ( $auto_updater_running )
94
+ return;
95
+
96
+ include_once( ABSPATH . 'wp-admin/includes/update.php' );
97
+ include_once( ABSPATH . 'wp-admin/includes/file.php' );
98
+
99
+ include_once( dirname( __FILE__ ) . '/updater-skin.php' );
100
+
101
+ $plugins = array_keys( get_plugin_updates() );
102
+ if ( empty( $plugins ) )
103
+ return;
104
+
105
+ $auto_updater_running = true;
106
+
107
+ $skin = new Auto_Updater_Skin();
108
+ $upgrader = new Plugin_Upgrader( $skin );
109
+ $upgrader->bulk_upgrade( $plugins );
110
+
111
+ $message = join( "\r\n", $skin->messages );
112
+
113
+ wp_mail( get_option( 'admin_email' ), __( 'Plugin Update', 'automatic-updater' ), $message );
114
+
115
+ wp_update_plugins();
116
+ }
117
+
118
+ function auto_updater_themes() {
119
+ global $auto_updater_running;
120
+ if ( $auto_updater_running )
121
+ return;
122
+
123
+ include_once( ABSPATH . 'wp-admin/includes/update.php' );
124
+ include_once( ABSPATH . 'wp-admin/includes/file.php' );
125
+
126
+ include_once( dirname( __FILE__ ) . '/updater-skin.php' );
127
+
128
+ $themes = array_keys( get_theme_updates() );
129
+ if ( empty( $themes ) )
130
+ return;
131
+
132
+ $auto_updater_running = true;
133
+
134
+ $skin = new Auto_Updater_Skin();
135
+ $upgrader = new Theme_Upgrader( $skin );
136
+ $upgrader->bulk_upgrade( $themes );
137
+
138
+ $message = join( "\r\n", $skin->messages );
139
+
140
+ wp_mail( get_option( 'admin_email' ), __( 'Theme Update', 'automatic-updater' ), $message );
141
+
142
+ wp_update_themes();
143
+ }
readme.txt ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Automatic Updater ===
2
+ Contributors: pento
3
+ Tags: updates, core, plugins, themes
4
+ Requires at least: 3.1
5
+ Tested up to: 3.5
6
+ Stable tag: 0.1
7
+
8
+ Automatically update WordPress, your themes and plugins! Never have to click the update button again!
9
+
10
+ == Description ==
11
+
12
+ Automatic Updater keeps your WordPress install up to date with the latest releases automatically, as soon as the update is available.
13
+
14
+ While this will be useful for the vast majority of sites, please exercise caution, particularly if you have any custom themes or plugins running on your site.
15
+
16
+ You should also be aware that this will only work on WordPress installs that have the appropriate file permissions to update through the web interface - it will not work if you usually FTP updates to your server.
updater-skin.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ include ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
4
+
5
+ class Auto_Updater_Skin extends WP_Upgrader_Skin {
6
+ var $messages = array();
7
+
8
+ function __construct( $args = array() ) {
9
+ parent::__construct( $args );
10
+ }
11
+
12
+ function feedback( $data ) {
13
+ if ( is_wp_error( $data ) )
14
+ $string = $data->get_error_message();
15
+ else if ( is_array( $data ) ) {
16
+ return;
17
+ }
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();
26
+ $args = array_splice( $args, 1 );
27
+ if ( ! empty( $args ) )
28
+ $string = vsprintf( $string, $args );
29
+ }
30
+
31
+ if ( empty( $string ) )
32
+ return;
33
+
34
+ $this->messages[] = $string;
35
+ }
36
+
37
+ function header() {}
38
+ function footer() {}
39
+ function bulk_header() {}
40
+ function bulk_footer() {}
41
+ function before() {}
42
+ function after() {}
43
+ }