Companion Auto Update - Version 3.0.1

Version Description

Download this release

Release Info

Developer Papin
Plugin Icon 128x128 Companion Auto Update
Version 3.0.1
Comparing to
See all releases

Code changes from version 3.0 to 3.0.1

admin/dashboard.php ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if ( !wp_next_scheduled ( 'cau_set_schedule_mail' ) ) {
4
+ echo '<div id="message" class="error"><p><b>'.__('Companion Auto Update was not able to set the event for sending you emails, please re-activate the plugin in order to set the event', 'companion-auto-update').'.</b></p></div>';
5
+ }
6
+
7
+ global $cau_db_version;
8
+
9
+ if ( get_site_option( 'cau_db_version' ) != $cau_db_version ) {
10
+ echo '<div id="message" class="error"><p><b>'.__('Database Update', 'companion-auto-update').' &ndash;</b> '.__('It seems like something went wrong while updating the database, please re-activate this plugin', 'companion-auto-update').'.</p></div>';
11
+ }
12
+
13
+ if( isset( $_POST['submit'] ) ) {
14
+
15
+ global $wpdb;
16
+ $table_name = $wpdb->prefix . "auto_updates";
17
+
18
+ $plugins = $_POST['plugins'];
19
+ $themes = $_POST['themes'];
20
+ $minor = $_POST['minor'];
21
+ $major = $_POST['major'];
22
+ $translations = $_POST['translations'];
23
+ $send = $_POST['cau_send'];
24
+ $sendupdate = $_POST['cau_send_update'];
25
+ $wpemails = $_POST['wpemails'];
26
+ $menloc = $_POST['menloc'];
27
+
28
+ $email = sanitize_text_field( $_POST['cau_email'] );
29
+
30
+ $wpdb->query( " UPDATE $table_name SET onoroff = '$plugins' WHERE name = 'plugins' " );
31
+ $wpdb->query( " UPDATE $table_name SET onoroff = '$themes' WHERE name = 'themes' " );
32
+ $wpdb->query( " UPDATE $table_name SET onoroff = '$minor' WHERE name = 'minor' " );
33
+ $wpdb->query( " UPDATE $table_name SET onoroff = '$major' WHERE name = 'major' " );
34
+ $wpdb->query( " UPDATE $table_name SET onoroff = '$translations' WHERE name = 'translations' " );
35
+ $wpdb->query( " UPDATE $table_name SET onoroff = '$email' WHERE name = 'email' " );
36
+ $wpdb->query( " UPDATE $table_name SET onoroff = '$send' WHERE name = 'send' " );
37
+ $wpdb->query( " UPDATE $table_name SET onoroff = '$sendupdate' WHERE name = 'sendupdate' " );
38
+ $wpdb->query( " UPDATE $table_name SET onoroff = '$wpemails' WHERE name = 'wpemails' " );
39
+ $wpdb->query( " UPDATE $table_name SET onoroff = '$menloc' WHERE name = 'menloc' " );
40
+
41
+ echo '<div id="message" class="updated"><p><b>'.__('Settings saved', 'companion-auto-update').'.</b></p></div>';
42
+
43
+ }
44
+
45
+ ?>
46
+
47
+ <form method="POST">
48
+
49
+ <table class="form-table">
50
+ <tr>
51
+ <th scope="row"><?php _e('Auto Updater', 'companion-auto-update');?></th>
52
+ <td>
53
+ <fieldset>
54
+
55
+ <?php
56
+
57
+ global $wpdb;
58
+ $table_name = $wpdb->prefix . "auto_updates";
59
+
60
+ $cau_configs = $wpdb->get_results( "SELECT * FROM $table_name" );
61
+
62
+ echo '<p><input id="'.$cau_configs[0]->name.'" name="'.$cau_configs[0]->name.'" type="checkbox"';
63
+ if( $cau_configs[0]->onoroff == 'on' ) echo 'checked';
64
+ echo '/> <label for="'.$cau_configs[0]->name.'">'.__('Auto update plugins?', 'companion-auto-update').'</label></p>';
65
+
66
+ echo '<p><input id="'.$cau_configs[1]->name.'" name="'.$cau_configs[1]->name.'" type="checkbox"';
67
+ if( $cau_configs[1]->onoroff == 'on' ) echo 'checked';
68
+ echo '/> <label for="'.$cau_configs[1]->name.'">'.__('Auto update themes?', 'companion-auto-update').'</label></p>';
69
+
70
+
71
+ echo '<p><input id="'.$cau_configs[2]->name.'" name="'.$cau_configs[2]->name.'" type="checkbox"';
72
+ if( $cau_configs[2]->onoroff == 'on' ) echo 'checked';
73
+ echo '/> <label for="'.$cau_configs[2]->name.'">'.__('Auto update minor core updates?', 'companion-auto-update').'</label></p>';
74
+
75
+
76
+ echo '<p><input id="'.$cau_configs[3]->name.'" name="'.$cau_configs[3]->name.'" type="checkbox"';
77
+ if( $cau_configs[3]->onoroff == 'on' ) echo 'checked';
78
+ echo '/> <label for="'.$cau_configs[3]->name.'">'.__('Auto update major core updates?', 'companion-auto-update').'</label></p>';
79
+
80
+ echo '<p><input id="'.$cau_configs[8]->name.'" name="'.$cau_configs[8]->name.'" type="checkbox"';
81
+ if( $cau_configs[8]->onoroff == 'on' ) echo 'checked';
82
+ echo '/> <label for="'.$cau_configs[8]->name.'">'.__('Auto update translation files?', 'companion-auto-update').'</label></p>';
83
+
84
+ ?>
85
+
86
+ </fieldset>
87
+ </td>
88
+ </tr>
89
+ </table>
90
+
91
+ <h2 class="title"><?php _e('Email Notifications', 'companion-auto-update');?></h2>
92
+ <p><?php _e('Email notifications are send once a day, you can choose what notifications to send below.', 'companion-auto-update');?></p>
93
+
94
+ <?php
95
+ if( $cau_configs[4]->onoroff == '' ) $toemail = get_option('admin_email');
96
+ else $toemail = $cau_configs[4]->onoroff;
97
+ ?>
98
+
99
+ <table class="form-table">
100
+ <tr>
101
+ <th scope="row"><?php _e('Update available', 'companion-auto-update');?></th>
102
+ <td>
103
+ <p>
104
+ <input id="cau_send" name="cau_send" type="checkbox" <?php if( $cau_configs[5]->onoroff == 'on' ) { echo 'checked'; } ?> />
105
+ <label for="cau_send"><?php _e('Send me emails when an update is available.', 'companion-auto-update');?></label>
106
+ </p>
107
+ </td>
108
+ </tr>
109
+ <tr>
110
+ <th scope="row"><?php _e('Successful update', 'companion-auto-update');?></th>
111
+ <td>
112
+ <p>
113
+ <input id="cau_send_update" name="cau_send_update" type="checkbox" <?php if( $cau_configs[6]->onoroff == 'on' ) { echo 'checked'; } ?> />
114
+ <label for="cau_send_update"><?php _e('Send me emails when something has been updated.', 'companion-auto-update');?></label>
115
+ </p>
116
+ </td>
117
+ </tr>
118
+ <tr>
119
+ <th scope="row"><?php _e('Core notifications', 'companion-auto-update');?></th>
120
+ <td>
121
+ <p>
122
+ <input id="wpemails" name="wpemails" type="checkbox" <?php if( $cau_configs[9]->onoroff == 'on' ) { echo 'checked'; } ?> />
123
+ <label for="wpemails"><?php _e('By default wordpress sends an email when a core update happend. Uncheck this box to disable these emails.', 'companion-auto-update');?></label>
124
+ </p>
125
+ </td>
126
+ </tr>
127
+ <tr>
128
+ <th scope="row"><?php _e('Email address', 'companion-auto-update');?></th>
129
+ <td>
130
+ <p>
131
+ <label for="cau_email"><?php _e('To', 'companion-auto-update');?>:</label>
132
+ <input type="text" name="cau_email" id="cau_email" class="regular-text" placeholder="<?php echo get_option('admin_email'); ?>" value="<?php echo esc_html( $toemail ); ?>" />
133
+ </p>
134
+
135
+ <p class="description"><?php _e('Seperate email addresses using commas.', 'companion-auto-update');?></p>
136
+ </td>
137
+ </tr>
138
+ </table>
139
+
140
+ <?php submit_button(); ?>
admin/log.php ADDED
@@ -0,0 +1,2 @@
 
 
1
+ <p><!-- SPACING --></p>
2
+ <?php cau_fetch_log( 'all', 'table' ); ?>
admin/pluginlist.php ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <p><?php _e('Here you can select plugins that you do not wish to automatically update', 'companion-auto-update'); ?>.</p>
2
+
3
+ <?php
4
+
5
+ global $wpdb;
6
+ $table_name = $wpdb->prefix . "auto_updates";
7
+
8
+ $configs = $wpdb->get_results( "SELECT * FROM $table_name WHERE name = 'plugins'");
9
+ foreach ( $configs as $config ) if( $config->onoroff != 'on' ) echo '<div id="message" class="error"><p><b>'.__('Auto updating disabled', 'companion-auto-update').' &ndash;</b> '.__('You have <strong>disabled</strong> auto updating, these settings do not work unless you <strong>enable</strong> it', 'companion-auto-update').'.</p></div>';
10
+
11
+ if( isset( $_POST['submit'] ) ) {
12
+
13
+ $noUpdateList = '';
14
+ $noUpdateCount = 0;
15
+
16
+ foreach ( $_POST['post'] as $key ) {
17
+ $noUpdateList .= $key.', ';
18
+ $noUpdateCount++;
19
+ }
20
+
21
+ $wpdb->query( " UPDATE $table_name SET onoroff = '$noUpdateList' WHERE name = 'notUpdateList' " );
22
+ echo '<div id="message" class="updated"><p><b>'.__('Succes', 'companion-auto-update').' &ndash;</b> '.sprintf( esc_html__( '%1$s plugins have been added to the no-update-list', 'companion-auto-update' ), $noUpdateCount ).'.</p></div>';
23
+ }
24
+
25
+ if( isset( $_POST['reset'] ) ) {
26
+
27
+ $wpdb->query( " UPDATE $table_name SET onoroff = '' WHERE name = 'notUpdateList' " );
28
+ echo '<div id="message" class="updated"><p><b>'.__('Succes', 'companion-auto-update').' &ndash;</b> '.__( 'The no-update-list has been reset, all plugins will be auto-updated from now on', 'companion-auto-update' ).'.</p></div>';
29
+ }
30
+
31
+ ?>
32
+
33
+ <form method="POST">
34
+
35
+ <p>
36
+ <input type='submit' name='submit' id='submit' class='button button-primary' value='<?php _e( "Save changes", "companion-auto-update" ); ?>'>
37
+ <input type='submit' name='reset' id='reset' class='button button-alt' value='<?php _e( "Reset list", "companion-auto-update" ); ?>'>
38
+ </p>
39
+
40
+ <table class="wp-list-table widefat autoupdate">
41
+ <thead>
42
+ <tr>
43
+ <td>&nbsp;</td>
44
+ <th class="head-plugin"><strong><?php _e('Plugin', 'companion-auto-update'); ?></strong></th>
45
+ <th class="head-status"><strong><?php _e('Status', 'companion-auto-update'); ?></strong></th>
46
+ <th class="head-description"><strong><?php _e('Description', 'companion-auto-update'); ?></strong></th>
47
+ </tr>
48
+ </thead>
49
+
50
+ <tbody id="the-list">
51
+
52
+ <?php
53
+
54
+ foreach ( get_plugins() as $key => $value ) {
55
+
56
+ $slug = $key;
57
+ $actualSlug = array_shift( explode( '/', $slug ) );
58
+ $hash = explode( '/', $slug );
59
+ $slug_hash = md5( $slug[0] );
60
+
61
+ foreach ( $value as $k => $v ) {
62
+
63
+ if( $k == "Name" ) $name = $v;
64
+ if( $k == "Description" ) $description = $v;
65
+
66
+ }
67
+
68
+ if( in_array( $actualSlug, donotupdatelist() ) ) {
69
+
70
+ $class = 'inactive';
71
+ $checked = 'CHECKED';
72
+ $status = __( 'Auto-updating: disabled' , 'companion-auto-update' );
73
+
74
+ } else {
75
+
76
+ $class = 'active';
77
+ $checked = '';
78
+ $status = __( 'Auto-updating: enabled' , 'companion-auto-update' );
79
+
80
+ }
81
+
82
+ echo '<tr id="post-'.$slug_hash.'" class="'.$class.'">
83
+
84
+ <th class="check-column">
85
+ <label class="screen-reader-text" for="cb-select-'.$slug_hash.'">Select '. $name .'</label>
86
+ <input id="cb-select-'.$slug_hash.'" type="checkbox" name="post[]" value="'.$actualSlug.'" '.$checked.' ><label></label>
87
+ <div class="locked-indicator"></div>
88
+ </th>
89
+
90
+ <td class="column-name">
91
+ <p><strong>'. $name .'</strong></p>
92
+ </td>
93
+
94
+ <td class="column-status">
95
+ <p>'. $status .'</p>
96
+ </td>
97
+
98
+ <td class="column-description">
99
+ <p>'.$description.'</p>
100
+ </td>
101
+
102
+ </tr>';
103
+
104
+ }
105
+ ?>
106
+
107
+ </tbody>
108
+ </table>
109
+
110
+ <p>
111
+ <input type='submit' name='submit' id='submit' class='button button-primary' value='<?php _e( "Save changes", "companion-auto-update" ); ?>'>
112
+ <input type='submit' name='reset' id='reset' class='button button-alt' value='<?php _e( "Reset list", "companion-auto-update" ); ?>'>
113
+ </p>
114
+
115
+ </form>
admin/rollback.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+
3
+ ?>
admin/schedule.php ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $plugin_schedule = wp_get_schedule( 'wp_update_plugins' );
4
+ $theme_schedule = wp_get_schedule( 'wp_update_themes' );
5
+ $core_schedule = wp_get_schedule( 'wp_version_check' );
6
+ $mail_sc = wp_get_schedule( 'cau_set_schedule_mail' );
7
+
8
+ if( isset( $_POST['submit'] ) ) {
9
+
10
+ // Set variables
11
+ $plugin_sc = $_POST['plugin_schedule'];
12
+ $theme_sc = $_POST['theme_schedule'];
13
+ $core_sc = $_POST['core_schedule'];
14
+ $schedule_mail = $_POST['schedule_mail'];
15
+
16
+
17
+ // First clear schedules
18
+ wp_clear_scheduled_hook('wp_update_plugins');
19
+ wp_clear_scheduled_hook('wp_update_themes');
20
+ wp_clear_scheduled_hook('wp_version_check');
21
+ wp_clear_scheduled_hook('cau_set_schedule_mail');
22
+
23
+ // Then set the new times
24
+ if( $plugin_sc == 'daily' ) {
25
+
26
+ $date = date( 'Y-m-d' );
27
+ $hours = ( $_POST['pluginScheduleTimeH'] - 1);
28
+ $minutes = $_POST['pluginScheduleTimeM'];
29
+ $seconds = date( 's' );
30
+ $fullDate = $date.' '.$hours.':'.$minutes.':'.$seconds;
31
+ $pluginSetTime = strtotime( $fullDate );
32
+
33
+ wp_schedule_event( $pluginSetTime, $plugin_sc, 'wp_update_plugins' );
34
+
35
+ } else {
36
+
37
+ wp_schedule_event( time(), $plugin_sc, 'wp_update_plugins' );
38
+
39
+ }
40
+ if( $theme_sc == 'daily' ) {
41
+
42
+ $dateT = date( 'Y-m-d' );
43
+ $hoursT = ( $_POST['ThemeScheduleTimeH'] - 1);
44
+ $minutesT = $_POST['ThemeScheduleTimeM'];
45
+ $secondsT = date( 's' );
46
+ $fullDateT = $dateT.' '.$hoursT.':'.$minutesT.':'.$secondsT;
47
+ $themeSetTime = strtotime( $fullDateT );
48
+
49
+ wp_schedule_event( $themeSetTime, $theme_sc, 'wp_update_themes' );
50
+
51
+ } else {
52
+
53
+ wp_schedule_event( time(), $theme_sc, 'wp_update_themes' );
54
+
55
+ }
56
+
57
+ wp_schedule_event( time(), $core_sc, 'wp_version_check' );
58
+ wp_schedule_event( time(), $schedule_mail, 'cau_set_schedule_mail' );
59
+
60
+ echo '<div id="message" class="updated"><p>'.__('Changes were saved. Reload the page to see the changes made.', 'companion-auto-update').'</p></div>';
61
+
62
+ }
63
+ ?>
64
+
65
+ <form method="POST">
66
+
67
+ <div class="message error warning">
68
+ <p class="warning">
69
+ <strong><?php _e('Warning', 'companion-auto-update'); ?></strong> &dash; <?php _e('Changing these settings may affect your sites perfomance.', 'companion-auto-update'); ?>
70
+ </p>
71
+ </div>
72
+
73
+ <h2 class="title"><?php _e('Updating', 'companion-auto-update');?></h2>
74
+ <?php _e('How often should the auto updater kick in? (Default twice daily)', 'companion-auto-update'); ?>
75
+ <table class="form-table">
76
+ <tr>
77
+ <th scope="row"><?php _e('Plugin update interval', 'companion-auto-update');?></th>
78
+ <td>
79
+ <p>
80
+ <select name='plugin_schedule'>
81
+ <option value='hourly' <?php if( $plugin_schedule == 'hourly' ) { echo "SELECTED"; } ?> ><?php _e('Hourly', 'companion-auto-update');?></option>
82
+ <option value='twicedaily' <?php if( $plugin_schedule == 'twicedaily' ) { echo "SELECTED"; } ?> ><?php _e('Twice Daily', 'companion-auto-update');?></option>
83
+ <option value='daily' <?php if( $plugin_schedule == 'daily' ) { echo "SELECTED"; } ?> ><?php _e('Daily', 'companion-auto-update');?></option>
84
+ </select>
85
+ </p>
86
+ <p>
87
+ <input type='text' name='pluginScheduleTimeH' value='<?php echo date("H"); ?>' style='max-width: 46px; text-align: center;'>:<input type='text' name='pluginScheduleTimeM' value='<?php echo date("i"); ?>' style='max-width: 46px; text-align: center;'>
88
+ <b><?php _e('Time notation: 24H', 'companion-auto-update'); ?></b>
89
+ <p class='description'><?php _e('At what time should the updater run? Only works when set to <u>daily</u>.', 'companion-auto-update'); ?> </p>
90
+ </p>
91
+ </td>
92
+ </tr>
93
+ <tr>
94
+ <th scope="row"><?php _e('Theme update interval', 'companion-auto-update');?></th>
95
+ <td>
96
+ <p>
97
+ <select name='theme_schedule'>
98
+ <option value='hourly' <?php if( $theme_schedule == 'hourly' ) { echo "SELECTED"; } ?> ><?php _e('Hourly', 'companion-auto-update');?></option>
99
+ <option value='twicedaily' <?php if( $theme_schedule == 'twicedaily' ) { echo "SELECTED"; } ?> ><?php _e('Twice Daily', 'companion-auto-update');?></option>
100
+ <option value='daily' <?php if( $theme_schedule == 'daily' ) { echo "SELECTED"; } ?> ><?php _e('Daily', 'companion-auto-update');?></option>
101
+ </select>
102
+ </p>
103
+ <p>
104
+ <input type='text' name='ThemeScheduleTimeH' value='<?php echo date("H"); ?>' style='max-width: 46px; text-align: center;'>:<input type='text' name='ThemeScheduleTimeM' value='<?php echo date("i"); ?>' style='max-width: 46px; text-align: center;'>
105
+ <b><?php _e('Time notation: 24H', 'companion-auto-update'); ?></b>
106
+ <p class='description'><?php _e('At what time should the updater run? Only works when set to <u>daily</u>.', 'companion-auto-update'); ?> </p>
107
+ </p>
108
+ </td>
109
+ </tr>
110
+ <tr>
111
+ <th scope="row"><?php _e('Core update interval', 'companion-auto-update');?></th>
112
+ <td>
113
+ <p>
114
+ <select name='core_schedule'>
115
+ <option value='hourly' <?php if( $core_schedule == 'hourly' ) { echo "SELECTED"; } ?> ><?php _e('Hourly', 'companion-auto-update');?></option>
116
+ <option value='twicedaily' <?php if( $core_schedule == 'twicedaily' ) { echo "SELECTED"; } ?> ><?php _e('Twice Daily', 'companion-auto-update');?></option>
117
+ <option value='daily' <?php if( $core_schedule == 'daily' ) { echo "SELECTED"; } ?> ><?php _e('Daily', 'companion-auto-update');?></option>
118
+ </select>
119
+ </p>
120
+ </td>
121
+ </tr>
122
+ </table>
123
+
124
+ <h2 class="title"><?php _e('Email Notifications', 'companion-auto-update');?></h2>
125
+ <?php _e('How often should notifications be send? (Default daily)', 'companion-auto-update'); ?>
126
+ <table class="form-table">
127
+ <tr>
128
+ <th scope="row"><?php _e('Email Notifications', 'companion-auto-update');?></th>
129
+ <td>
130
+ <p>
131
+ <select name='schedule_mail'>
132
+ <option value='hourly' <?php if( $mail_sc == 'hourly' ) { echo "SELECTED"; } ?> ><?php _e('Hourly', 'companion-auto-update');?></option>
133
+ <option value='twicedaily' <?php if( $mail_sc == 'twicedaily' ) { echo "SELECTED"; } ?> ><?php _e('Twice Daily', 'companion-auto-update');?></option>
134
+ <option value='daily' <?php if( $mail_sc == 'daily' ) { echo "SELECTED"; } ?> ><?php _e('Daily', 'companion-auto-update');?></option>
135
+ </select>
136
+ </p>
137
+ </td>
138
+ </tr>
139
+ </table>
140
+
141
+ <input type='submit' name='submit' id='submit' class='button button-primary' value='<?php _e( "Save changes", "companion-auto-update" ); ?>'>
142
+
143
+ </form>
cau_emails.php ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ function cau_check_updates_mail() {
3
+
4
+ global $wpdb;
5
+ $table_name = $wpdb->prefix . "auto_updates";
6
+ $cau_configs = $wpdb->get_results( "SELECT * FROM $table_name" );
7
+
8
+ if( $cau_configs[5]->onoroff == 'on' ) {
9
+ cau_list_theme_updates(); // Check for theme updates
10
+ cau_list_plugin_updates(); // Check for plugin updates
11
+ }
12
+
13
+ if( $cau_configs[6]->onoroff == 'on' ) if( $cau_configs[0]->onoroff == 'on' ) cau_plugin_updated(); // Check for updated plugins
14
+ }
15
+
16
+ function cau_set_email() {
17
+
18
+ global $wpdb;
19
+ $table_name = $wpdb->prefix . "auto_updates";
20
+ $cau_configs = $wpdb->get_results( "SELECT * FROM $table_name" );
21
+ $emailArray = array();
22
+
23
+ if( $cau_configs[4]->onoroff == '' ) {
24
+ array_push( $emailArray, get_option('admin_email') );
25
+ } else {
26
+ $emailAdresses = $cau_configs[4]->onoroff;
27
+ $list = explode( ", ", $emailAdresses );
28
+ foreach ( $list as $key ) {
29
+ array_push( $emailArray, $list );
30
+ }
31
+ }
32
+
33
+ return $emailArray;
34
+
35
+ }
36
+
37
+ function cau_set_content( $single, $plural ) {
38
+
39
+ return sprintf( esc_html__(
40
+ 'There are one or more %1$s updates available on your WordPress site at: %2$s, but you have disabled auto-updating for %3$s. Login to your dashboard to manually update your %3$s.', 'companion-auto-update'
41
+ ), $single, get_site_url(), $plural);
42
+
43
+ }
44
+
45
+ // Checks if theme updates are available
46
+ function cau_list_theme_updates() {
47
+
48
+ global $wpdb;
49
+ $table_name = $wpdb->prefix . "auto_updates";
50
+
51
+ $configs = $wpdb->get_results( "SELECT * FROM $table_name WHERE name = 'themes'");
52
+ foreach ( $configs as $config ) {
53
+
54
+ if( $config->onoroff != 'on' ) {
55
+
56
+ require_once ABSPATH . '/wp-admin/includes/update.php';
57
+ $themes = get_theme_updates();
58
+
59
+ if ( !empty( $themes ) ) {
60
+
61
+ $subject = '[' . get_bloginfo( 'name' ) . '] ' . __('Theme update available.', 'companion-auto-update');
62
+ $type = __('theme', 'companion-auto-update');
63
+ $type_plural = __('themes', 'companion-auto-update');
64
+ $message = cau_set_content( $type, $type_plural );
65
+
66
+ wp_mail( array( cau_set_email() ) , $subject, $message, $headers );
67
+ }
68
+
69
+ }
70
+
71
+ }
72
+
73
+ }
74
+
75
+ // Checks if plugin updates are available
76
+ function cau_list_plugin_updates() {
77
+
78
+ global $wpdb;
79
+ $table_name = $wpdb->prefix . "auto_updates";
80
+
81
+ $configs = $wpdb->get_results( "SELECT * FROM $table_name WHERE name = 'plugins'");
82
+ foreach ( $configs as $config ) {
83
+
84
+ if( $config->onoroff != 'on' ) {
85
+
86
+ require_once(ABSPATH . 'wp-admin/includes/plugin-install.php');
87
+ $plugins = get_plugin_updates();
88
+
89
+ if ( !empty( $plugins ) ) {
90
+
91
+ $subject = '[' . get_bloginfo( 'name' ) . '] ' . __('Plugin update available.', 'companion-auto-update');
92
+ $type = __('plugin', 'companion-auto-update');
93
+ $type_plural = __('plugins', 'companion-auto-update');
94
+ $message = cau_set_content( $type, $type_plural );
95
+
96
+ wp_mail( array( cau_set_email() ) , $subject, $message, $headers );
97
+ }
98
+
99
+ }
100
+
101
+ }
102
+ }
103
+
104
+ // Creates the messages to be send
105
+ function cau_updated_message( $type, $updatedList ) {
106
+
107
+ return sprintf( esc_html__(
108
+ 'We have updated one or more %1$s on your WordPress site at %2$s, be sure to check if everything still works properly. The following %1$s have been updated: %3$s', 'companion-auto-update'
109
+ ), $type, get_site_url(), $updatedList );
110
+
111
+ }
112
+
113
+ // Alerts when plugin has been updated
114
+ function cau_plugin_updated() {
115
+
116
+ $today = date("Y-m-d");
117
+ $yesterday = date('Y-m-d',strtotime("-1 days"));
118
+ $updatedList = '';
119
+ $all_plugins = get_plugins();
120
+
121
+ $updatedPlugins = false;
122
+
123
+ foreach ( $all_plugins as $key => $value ) {
124
+
125
+ $slug = explode( '/', $key );
126
+ $slug_hash = md5( $slug[0] );
127
+ $last_updated = get_transient( "cau_{$slug_hash}" );
128
+
129
+ if ( false === $last_updated ) {
130
+ $last_updated = cau_get_last_updated( $slug );
131
+ set_transient( "cau_{$slug_hash}", $last_updated, 86400 );
132
+ }
133
+
134
+ if ( $last_updated ) {
135
+ $last_updated = explode( ' ', $last_updated );
136
+ $last_updated = $last_updated[0];
137
+
138
+ if( $last_updated == $today OR $last_updated == $yesterday ) {
139
+ foreach ( $value as $k => $v ) {
140
+
141
+ if( $k == "Name" ) $plugName = $v;
142
+ if( $k == "Version" ) $plugVersion = $v;
143
+
144
+ $updatedList .= "- ".$plugName." ".__( "to version:", "companion-auto-update" )." ".$plugVersion."\n";
145
+
146
+ }
147
+
148
+ $updatedPlugins = true;
149
+
150
+ $subject = '[' . get_bloginfo( 'name' ) . '] ' . __('One or more plugins have been updated.', 'companion-auto-update');
151
+ $type = __('plugins', 'companion-auto-update');
152
+ $message = cau_updated_message( $type, "\n".$updatedList );
153
+
154
+ }
155
+ }
156
+
157
+ }
158
+
159
+ if( $updatedPlugins ) {
160
+ wp_mail( array( cau_set_email() ) , $subject, $message, $headers );
161
+ }
162
+
163
+ }
164
+
165
+ // Do some high-tech stuff
166
+ function cau_get_last_updated( $slug ) {
167
+ $request = wp_remote_post(
168
+ 'http://api.wordpress.org/plugins/info/1.0/',
169
+ array(
170
+ 'body' => array(
171
+ 'action' => 'plugin_information',
172
+ 'request' => serialize(
173
+ (object) array(
174
+ 'slug' => $slug,
175
+ 'fields' => array( 'last_updated' => true )
176
+ )
177
+ )
178
+ )
179
+ )
180
+ );
181
+ if ( 200 != wp_remote_retrieve_response_code( $request ) ) return false;
182
+
183
+ $response = unserialize( wp_remote_retrieve_body( $request ) );
184
+ // Return an empty but cachable response if the plugin isn't in the .org repo
185
+ if ( empty( $response ) )
186
+ return '';
187
+ if ( isset( $response->last_updated ) )
188
+ return sanitize_text_field( $response->last_updated );
189
+
190
+ return false;
191
+ }
192
+
193
+ ?>
cau_functions.php ADDED
@@ -0,0 +1,183 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ function cau_menloc() {
4
+
5
+ return 'tools.php';
6
+
7
+ }
8
+
9
+ function active_tab( $page ) {
10
+
11
+ if( !isset( $_GET['tab'] ) ) {
12
+ $cur_page = '';
13
+ } else {
14
+ $cur_page = $_GET['tab'];
15
+ }
16
+
17
+ if( $page == $cur_page ) {
18
+ echo 'nav-tab-active';
19
+ }
20
+
21
+ }
22
+
23
+ function donotupdatelist() {
24
+
25
+ global $wpdb;
26
+ $table_name = $wpdb->prefix . "auto_updates";
27
+ $config = $wpdb->get_results( "SELECT * FROM $table_name WHERE name = 'notUpdateList'");
28
+
29
+ $list = $config[0]->onoroff;
30
+ $list = explode( ", ", $list );
31
+ $returnList = array();
32
+
33
+ foreach ( $list as $key ) array_push( $returnList, $key );
34
+
35
+ return $returnList;
36
+
37
+ }
38
+
39
+ function cau_fetch_log( $limit, $format = 'simple' ) {
40
+
41
+ // Create arrays
42
+ $pluginNames = array();
43
+ $pluginDates = array();
44
+ $pluginDatesF = array();
45
+ $type = array();
46
+
47
+ // Where to look for plugins
48
+ $plugdir = plugin_dir_path( __DIR__ );
49
+ $allPlugins = get_plugins();
50
+
51
+ // Loop trough all plugins
52
+ foreach ( $allPlugins as $key => $value) {
53
+
54
+ // Get plugin data
55
+ $fullPath = $plugdir.'/'.$key;
56
+ $getFile = $path_parts = pathinfo( $fullPath );
57
+ $pluginData = get_plugin_data( $fullPath );
58
+
59
+ // Get plugin name
60
+ foreach ( $pluginData as $dataKey => $dataValue ) {
61
+ if( $dataKey == 'Name') {
62
+ array_push( $pluginNames , $dataValue );
63
+ }
64
+ }
65
+
66
+ // Get last update date
67
+ $dateFormat = get_option( 'date_format' );
68
+ $fileDate = date ( 'Ymd', filemtime( $fullPath ) );
69
+ $fileDateF = date_i18n ( $dateFormat, filemtime( $fullPath ) );
70
+ array_push( $pluginDates, $fileDate );
71
+ array_push( $pluginDatesF, $fileDateF );
72
+ array_push( $type, 'Plugin' );
73
+
74
+ }
75
+
76
+ // Where to look for themes
77
+ $themedir = get_theme_root();
78
+ $allThemes = wp_get_themes();
79
+
80
+ // Loop trough all themes
81
+ foreach ( $allThemes as $key => $value) {
82
+
83
+ // Get theme data
84
+ $fullPath = $themedir.'/'.$key;
85
+ $getFile = $path_parts = pathinfo( $fullPath );
86
+
87
+ // Get theme name
88
+ array_push( $pluginNames , $path_parts['filename'] );
89
+
90
+ // Get last update date
91
+ $dateFormat = get_option( 'date_format' );
92
+ $fileDate = date ( 'Ymd', filemtime( $fullPath ) );
93
+ $fileDateF = date_i18n ( $dateFormat, filemtime( $fullPath ) );
94
+ array_push( $pluginDates, $fileDate );
95
+ array_push( $pluginDatesF, $fileDateF );
96
+ array_push( $type, 'Theme' );
97
+
98
+ }
99
+
100
+ // Sort array by date
101
+ arsort( $pluginDates );
102
+
103
+ if( $limit == 'all' ) {
104
+ $limit = 999;
105
+ }
106
+
107
+ $listClasses = 'wp-list-table widefat autoupdate autoupdatelog';
108
+
109
+ if( $format == 'table' ) {
110
+ $listClasses .= ' autoupdatelog striped';
111
+ } else {
112
+ $listClasses .= ' autoupdatewidget';
113
+ }
114
+
115
+ echo '<table class="'.$listClasses.'">';
116
+
117
+ // Show the last updated plugins
118
+ if( $format == 'table' ) {
119
+
120
+ echo '<thead>
121
+ <tr>
122
+ <th><strong>'.__( 'Name', 'companion-auto-update' ).'</strong></th>
123
+ <th><strong>'.__( 'Type', 'companion-auto-update' ).'</strong></th>
124
+ <th><strong>'.__( 'Last updated on', 'companion-auto-update' ).'</strong></th>
125
+ </tr>
126
+ </thead>';
127
+
128
+ }
129
+
130
+ echo '<tbody id="the-list">';
131
+
132
+ $loopings = 0;
133
+
134
+ foreach ( $pluginDates as $key => $value ) {
135
+
136
+ if( $loopings < $limit ) {
137
+
138
+ echo '<tr>';
139
+
140
+ echo '<td class="column-primary"><p><strong>'. $pluginNames[$key] .'</strong></p></td>';
141
+
142
+ if( $format == 'table' ) {
143
+
144
+ if( $type[$key] == 'Plugin' ) {
145
+ $thisType = __( 'Plugin', 'companion-auto-update' );
146
+ } else if( $type[$key] == 'Theme' ) {
147
+ $thisType = __( 'Theme', 'companion-auto-update' );
148
+ }
149
+
150
+ echo '<td class="column-description"><p>'. $thisType .'</p></td>';
151
+
152
+ }
153
+
154
+ echo '<td class="column-date" style="min-width: 100px;"><p>'. $pluginDatesF[$key] .'</p></td>';
155
+
156
+ echo '</tr>';
157
+
158
+ $loopings++;
159
+
160
+ }
161
+
162
+ }
163
+
164
+ echo "</tbody></table>";
165
+
166
+ }
167
+
168
+ // Only update plugin which are enabled
169
+ function cau_dont_update( $update, $item ) {
170
+
171
+ $plugins = donotupdatelist();
172
+
173
+ if ( in_array( $item->slug, $plugins ) ) {
174
+ // Use the normal API response to decide whether to update or not
175
+ return $update;
176
+ } else {
177
+ // Always update plugins
178
+ return true;
179
+ }
180
+
181
+ }
182
+
183
+ ?>
companion-auto-update.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Companion Auto Update
4
  * Plugin URI: http://codeermeneer.nl/portfolio/companion-auto-update/
5
  * Description: This plugin auto updates all plugins, all themes and the wordpress core.
6
- * Version: 3.0
7
  * Author: Papin Schipper
8
  * Author URI: http://codeermeneer.nl/
9
  * Contributors: papin
3
  * Plugin Name: Companion Auto Update
4
  * Plugin URI: http://codeermeneer.nl/portfolio/companion-auto-update/
5
  * Description: This plugin auto updates all plugins, all themes and the wordpress core.
6
+ * Version: 3.0.1
7
  * Author: Papin Schipper
8
  * Author URI: http://codeermeneer.nl/
9
  * Contributors: papin
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.me/dakel/2
4
  Tags: auto, automatic, background, update, updates, updating, automatic updates, automatic background updates, easy update, wordpress update, theme update, plugin update, up-to-date, security, update latest version, update core, update wp, update wp core, major updates, minor updates, update to new version, update core, update plugin, update plugins, update plugins automatically, update theme, plugin, theme, advance, control, mail, notifations, enable
5
  Requires at least: 3.5.0
6
  Tested up to: 4.9
7
- Stable tag: 2.9.6
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
4
  Tags: auto, automatic, background, update, updates, updating, automatic updates, automatic background updates, easy update, wordpress update, theme update, plugin update, up-to-date, security, update latest version, update core, update wp, update wp core, major updates, minor updates, update to new version, update core, update plugin, update plugins, update plugins automatically, update theme, plugin, theme, advance, control, mail, notifations, enable
5
  Requires at least: 3.5.0
6
  Tested up to: 4.9
7
+ Stable tag: 3.0.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10