Companion Auto Update - Version 3.4.4

Version Description

(November 16, 2019) = * Sometimes the database wouldn't correctly update to the newest version, we've added a manual button for this now. * Sometimes plugins excluded from the updater would still update, this should be fixed now.

Download this release

Release Info

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

Code changes from version 3.4.3 to 3.4.4

admin/dashboard.php CHANGED
@@ -5,7 +5,8 @@
5
  }
6
 
7
  if ( get_site_option( 'cau_db_version' ) != cau_db_version() ) {
8
- 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>';
 
9
  }
10
 
11
  if( isset( $_POST['submit'] ) ) {
5
  }
6
 
7
  if ( get_site_option( 'cau_db_version' ) != cau_db_version() ) {
8
+ echo '<div id="message" class="error"><p><b>'.__( 'Companion Auto Update Database Update', 'companion-auto-update' ).' &ndash;</b>
9
+ '.__( 'We need you to update to the latest database version', 'companion-auto-update' ).'. <a href="'.cau_url( 'status' ).'&run=db_update" class="button button-alt" style="background: #FFF;">'.__( 'Run updater now', 'companion-auto-update' ).'</a></p></div>';
10
  }
11
 
12
  if( isset( $_POST['submit'] ) ) {
admin/status.php CHANGED
@@ -1,4 +1,9 @@
1
  <?php
 
 
 
 
 
2
 
3
  // Date format
4
  $dateFormat = get_option( 'date_format' );
@@ -379,7 +384,7 @@ if( cau_incompatiblePlugins() ) { ?>
379
  echo '<tr>
380
  <td class="cau_plugin_issue_name">'.$key.'</td>
381
  <td class="cau_plugin_issue_explain">'.$value.'</td>
382
- <td class="cau_plugin_issue_fixit"><a href="https://codeermeneer.nl/documentation/possible-plugin-issues-fixes/" target="_blank" class="button">'.__( 'How to fix', 'companion-auto-update' ).'</a></td>
383
  </tr>';
384
 
385
  }
1
  <?php
2
+
3
+ if( isset( $_GET['run'] ) && $_GET['run'] == 'db_update' ) {
4
+ cau_manual_update();
5
+ echo '<div id="message" class="updated"><p><b>'.__( 'Datbase update completed' ).'</b></p></div>';
6
+ }
7
 
8
  // Date format
9
  $dateFormat = get_option( 'date_format' );
384
  echo '<tr>
385
  <td class="cau_plugin_issue_name">'.$key.'</td>
386
  <td class="cau_plugin_issue_explain">'.$value.'</td>
387
+ <td class="cau_plugin_issue_fixit"><a href="https://codeermeneer.nl/documentation/known-issues-fixes/#plugins" target="_blank" class="button">'.__( 'How to fix', 'companion-auto-update' ).'</a></td>
388
  </tr>';
389
 
390
  }
cau_functions.php CHANGED
@@ -292,6 +292,11 @@ function donotupdatelist() {
292
  // Show the update log
293
  function cau_fetch_log( $limit, $format = 'simple' ) {
294
 
 
 
 
 
 
295
  // Filter log
296
  if( isset( $_GET['filter'] ) ) {
297
  $filter = $_GET['filter'];
@@ -327,6 +332,7 @@ function cau_fetch_log( $limit, $format = 'simple' ) {
327
  $pluginDatesF = array();
328
  $plugslug = array();
329
  $type = array();
 
330
 
331
  // Date format
332
  $dateFormat = get_option( 'date_format' );
@@ -350,6 +356,15 @@ function cau_fetch_log( $limit, $format = 'simple' ) {
350
 
351
  array_push( $plugslug , $pluginSlug );
352
 
 
 
 
 
 
 
 
 
 
353
  // Get plugin name
354
  foreach ( $pluginData as $dataKey => $dataValue ) {
355
  if( $dataKey == 'Name') {
@@ -397,6 +412,8 @@ function cau_fetch_log( $limit, $format = 'simple' ) {
397
  array_push( $pluginNames , $themeName );
398
  array_push( $pluginVersion , $themeVersion );
399
 
 
 
400
 
401
  // Get last update date
402
  $fileDate = date( 'YmdHi', filemtime( $fullPath ) );
@@ -444,6 +461,9 @@ function cau_fetch_log( $limit, $format = 'simple' ) {
444
  array_push( $pluginDatesF, $coreDateF );
445
  array_push( $plugslug , '' );
446
 
 
 
 
447
  }
448
 
449
  // Sort array by date
@@ -472,6 +492,7 @@ function cau_fetch_log( $limit, $format = 'simple' ) {
472
  <th><strong>'.__( 'To', 'companion-auto-update' ).'</strong></th>
473
  <th><strong>'.__( 'Type', 'companion-auto-update' ).'</strong></th>
474
  <th><strong>'.__( 'Last updated on', 'companion-auto-update' ).'</strong></th>
 
475
  </tr>
476
  </thead>';
477
 
@@ -515,6 +536,10 @@ function cau_fetch_log( $limit, $format = 'simple' ) {
515
 
516
  echo '<td class="column-date" style="min-width: 100px;"><p>'. $pluginDatesF[$key] .'</p></td>';
517
 
 
 
 
 
518
  echo '</tr>';
519
 
520
  $loopings++;
@@ -556,13 +581,12 @@ function cau_dont_update( $update, $item ) {
556
  $plugins = donotupdatelist();
557
 
558
  if ( in_array( $item->slug, $plugins ) ) {
559
- // Use the normal API response to decide whether to update or not
560
- return $update;
561
  } else {
562
- // Always update plugins
563
- return true;
564
  }
565
 
 
566
  }
567
 
568
  // Get plugin information of repository
@@ -657,4 +681,44 @@ function cau_addMoreIntervals( $schedules ) {
657
  }
658
  add_filter( 'cron_schedules', 'cau_addMoreIntervals' );
659
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
660
  ?>
292
  // Show the update log
293
  function cau_fetch_log( $limit, $format = 'simple' ) {
294
 
295
+ // Database
296
+ global $wpdb;
297
+ $updateLog = "update_log";
298
+ $updateLogDB = $wpdb->prefix.$updateLog;
299
+
300
  // Filter log
301
  if( isset( $_GET['filter'] ) ) {
302
  $filter = $_GET['filter'];
332
  $pluginDatesF = array();
333
  $plugslug = array();
334
  $type = array();
335
+ $method = array();
336
 
337
  // Date format
338
  $dateFormat = get_option( 'date_format' );
356
 
357
  array_push( $plugslug , $pluginSlug );
358
 
359
+ // Get info from database
360
+ // if( cau_check_if_exists( $key, 'slug', $updateLog ) ) {
361
+ // array_push( $method , 'Method found!' );
362
+ // } else {
363
+ // array_push( $method , 'New' );
364
+ // }
365
+
366
+ array_push( $method , '-' );
367
+
368
  // Get plugin name
369
  foreach ( $pluginData as $dataKey => $dataValue ) {
370
  if( $dataKey == 'Name') {
412
  array_push( $pluginNames , $themeName );
413
  array_push( $pluginVersion , $themeVersion );
414
 
415
+ // Get info from database
416
+ array_push( $method , '-' );
417
 
418
  // Get last update date
419
  $fileDate = date( 'YmdHi', filemtime( $fullPath ) );
461
  array_push( $pluginDatesF, $coreDateF );
462
  array_push( $plugslug , '' );
463
 
464
+ // Get info from database
465
+ array_push( $method , '-' );
466
+
467
  }
468
 
469
  // Sort array by date
492
  <th><strong>'.__( 'To', 'companion-auto-update' ).'</strong></th>
493
  <th><strong>'.__( 'Type', 'companion-auto-update' ).'</strong></th>
494
  <th><strong>'.__( 'Last updated on', 'companion-auto-update' ).'</strong></th>
495
+ <th style="display: none;"><strong>'.__( 'Update method', 'companion-auto-update' ).'</strong></th>
496
  </tr>
497
  </thead>';
498
 
536
 
537
  echo '<td class="column-date" style="min-width: 100px;"><p>'. $pluginDatesF[$key] .'</p></td>';
538
 
539
+ if( $format == 'table' ) {
540
+ echo '<td class="column-method" style="display: none;"><p>'. $method[$key] .'</p></td>';
541
+ }
542
+
543
  echo '</tr>';
544
 
545
  $loopings++;
581
  $plugins = donotupdatelist();
582
 
583
  if ( in_array( $item->slug, $plugins ) ) {
584
+ return false; // Don't update these plugins
 
585
  } else {
586
+ return true; // Always update these plugins
 
587
  }
588
 
589
+
590
  }
591
 
592
  // Get plugin information of repository
681
  }
682
  add_filter( 'cron_schedules', 'cau_addMoreIntervals' );
683
 
684
+ // Plugin information to DB
685
+ function cau_savePluginInformation() {
686
+
687
+ global $wpdb;
688
+ $updateLog = $wpdb->prefix."update_log";
689
+ $allPlugins = get_plugins();
690
+
691
+ foreach ( $allPlugins as $key => $value ) {
692
+ foreach ( $value as $k => $v ) {
693
+ if( $k == 'Version' ) $version = $v;
694
+ }
695
+ $slug = $key;
696
+ $version = $version;
697
+
698
+ if( !cau_check_if_exists( $slug, 'slug', $updateLog ) ) $wpdb->insert( $updateLog, array( 'slug' => $slug, 'oldVersion' => $version ) );
699
+ }
700
+ }
701
+ add_action( 'cau_custom_hooks_plugins', 'cau_savePluginInformation' );
702
+
703
+ // Check for manual updates
704
+ function manual_update_check_init() {
705
+
706
+ if( isset( $_GET['action'] ) && $_GET['action'] == 'upgrade-plugin' ) {
707
+
708
+ if( isset( $_GET['plugin'] ) ) {
709
+
710
+ global $wpdb;
711
+ $updateLog = $wpdb->prefix."update_log";
712
+
713
+ if( cau_check_if_exists( $_GET['plugin'], 'slug', 'update_log' ) ) $wpdb->query( $wpdb->prepare( "UPDATE $updateLog SET method = 'Manual' WHERE slug = '%s'", $_GET['plugin'] ) );
714
+
715
+ die();
716
+
717
+ }
718
+
719
+ }
720
+
721
+ }
722
+ add_action( 'admin_footer', 'manual_update_check_init', 1000 );
723
+
724
  ?>
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.4.3
7
  * Author: Papin Schipper
8
  * Author URI: http://codeermeneer.nl/
9
  * Contributors: papin
@@ -29,9 +29,9 @@ function cau_install() {
29
  if (! wp_next_scheduled ( 'cau_custom_hooks_plugins' )) wp_schedule_event( time(), 'daily', 'cau_custom_hooks_plugins'); // Run custom hooks on plugin updates
30
  if (! wp_next_scheduled ( 'cau_custom_hooks_themes' )) wp_schedule_event( time(), 'daily', 'cau_custom_hooks_themes'); // Run custom hooks on theme updates
31
  }
32
- add_action('cau_set_schedule_mail', 'cau_check_updates_mail');
33
- add_action('cau_custom_hooks_plugins', 'cau_run_custom_hooks_p');
34
- add_action('cau_custom_hooks_themes', 'cau_run_custom_hooks_t');
35
 
36
  // Redirect to welcome screen on activation of plugin
37
  function cau_pluginActivateWelcome() {
@@ -56,25 +56,37 @@ function cau_donateUrl() {
56
 
57
  // Database version
58
  function cau_db_version() {
59
- return '3.4.3';
60
  }
61
  function cau_database_creation() {
62
 
63
  global $wpdb;
64
 
65
  $cau_db_version = cau_db_version();
66
- $table_name = $wpdb->prefix . "auto_updates";
 
67
 
68
  // Create db table
69
- $sql = "CREATE TABLE $table_name (
70
  id INT(9) NOT NULL AUTO_INCREMENT,
71
  name VARCHAR(255) NOT NULL,
72
  onoroff VARCHAR(255) NOT NULL,
73
  UNIQUE KEY id (id)
74
  )";
75
 
 
 
 
 
 
 
 
 
 
 
76
  require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
77
  dbDelta( $sql );
 
78
 
79
  // Database version
80
  add_option( "cau_db_version", "$cau_db_version" );
@@ -85,12 +97,12 @@ function cau_database_creation() {
85
  }
86
 
87
  // Check if database table exists before creating
88
- function cau_check_if_exists( $whattocheck ) {
89
 
90
  global $wpdb;
91
- $table_name = $wpdb->prefix . "auto_updates";
92
 
93
- $rows = $wpdb->get_col( "SELECT COUNT(*) as num_rows FROM {$table_name} WHERE name = '{$whattocheck}'" );
94
  $check = $rows[0];
95
 
96
  if( $check > 0 ) {
@@ -110,19 +122,20 @@ function cau_install_data() {
110
 
111
  // Update configs
112
  if( !cau_check_if_exists( 'plugins' ) ) $wpdb->insert( $table_name, array( 'name' => 'plugins', 'onoroff' => 'on' ) );
113
- if( !cau_check_if_exists( 'themes' ) ) $wpdb->insert( $table_name, array( 'name' => 'themes', 'onoroff' => 'on' ) );
114
- if( !cau_check_if_exists( 'minor' ) ) $wpdb->insert( $table_name, array( 'name' => 'minor', 'onoroff' => 'on' ) );
115
- if( !cau_check_if_exists( 'major' ) ) $wpdb->insert( $table_name, array( 'name' => 'major', 'onoroff' => '' ) );
116
 
117
  // Email configs
118
- if( !cau_check_if_exists( 'email' ) ) $wpdb->insert( $table_name, array( 'name' => 'email', 'onoroff' => '' ) );
119
- if( !cau_check_if_exists( 'send' ) ) $wpdb->insert( $table_name, array( 'name' => 'send', 'onoroff' => '' ) );
120
- if( !cau_check_if_exists( 'sendupdate' ) ) $wpdb->insert( $table_name, array( 'name' => 'sendupdate', 'onoroff' => '' ) );
121
 
122
  // Advanced
123
- if( !cau_check_if_exists( 'notUpdateList' ) ) $wpdb->insert( $table_name, array( 'name' => 'notUpdateList', 'onoroff' => '' ) );
124
- if( !cau_check_if_exists( 'translations' ) ) $wpdb->insert( $table_name, array( 'name' => 'translations', 'onoroff' => 'on' ) );
125
- if( !cau_check_if_exists( 'wpemails' ) ) $wpdb->insert( $table_name, array( 'name' => 'wpemails', 'onoroff' => 'on' ) );
 
126
 
127
  }
128
  register_activation_hook( __FILE__, 'cau_install' );
@@ -130,8 +143,10 @@ register_activation_hook( __FILE__, 'cau_install' );
130
  // Clear everything on deactivation
131
  function cau_remove() {
132
  global $wpdb;
133
- $table_name = $wpdb->prefix . "auto_updates";
134
- $wpdb->query( "DROP TABLE IF EXISTS $table_name" );
 
 
135
  wp_clear_scheduled_hook('cau_set_schedule_mail');
136
  }
137
  register_deactivation_hook( __FILE__, 'cau_remove' );
@@ -146,6 +161,11 @@ function cau_update_db_check() {
146
  }
147
  add_action( 'upgrader_process_complete', 'cau_update_db_check' );
148
 
 
 
 
 
 
149
  // Load custom functions
150
  require_once( plugin_dir_path( __FILE__ ) . 'cau_functions.php' );
151
 
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.4.4
7
  * Author: Papin Schipper
8
  * Author URI: http://codeermeneer.nl/
9
  * Contributors: papin
29
  if (! wp_next_scheduled ( 'cau_custom_hooks_plugins' )) wp_schedule_event( time(), 'daily', 'cau_custom_hooks_plugins'); // Run custom hooks on plugin updates
30
  if (! wp_next_scheduled ( 'cau_custom_hooks_themes' )) wp_schedule_event( time(), 'daily', 'cau_custom_hooks_themes'); // Run custom hooks on theme updates
31
  }
32
+ add_action( 'cau_set_schedule_mail', 'cau_check_updates_mail' );
33
+ add_action( 'cau_custom_hooks_plugins', 'cau_run_custom_hooks_p' );
34
+ add_action( 'cau_custom_hooks_themes', 'cau_run_custom_hooks_t' );
35
 
36
  // Redirect to welcome screen on activation of plugin
37
  function cau_pluginActivateWelcome() {
56
 
57
  // Database version
58
  function cau_db_version() {
59
+ return '3.5.0';
60
  }
61
  function cau_database_creation() {
62
 
63
  global $wpdb;
64
 
65
  $cau_db_version = cau_db_version();
66
+ $autoupdates = $wpdb->prefix."auto_updates";
67
+ $updateLog = $wpdb->prefix."update_log";
68
 
69
  // Create db table
70
+ $sql = "CREATE TABLE $autoupdates (
71
  id INT(9) NOT NULL AUTO_INCREMENT,
72
  name VARCHAR(255) NOT NULL,
73
  onoroff VARCHAR(255) NOT NULL,
74
  UNIQUE KEY id (id)
75
  )";
76
 
77
+ // Create second db table
78
+ $sql2 = "CREATE TABLE $updateLog (
79
+ id INT(9) NOT NULL AUTO_INCREMENT,
80
+ slug VARCHAR(255) NOT NULL,
81
+ oldVersion VARCHAR(10) NOT NULL,
82
+ newVersion VARCHAR(10) NOT NULL,
83
+ method VARCHAR(10) NOT NULL,
84
+ UNIQUE KEY id (id)
85
+ )";
86
+
87
  require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
88
  dbDelta( $sql );
89
+ dbDelta( $sql2 );
90
 
91
  // Database version
92
  add_option( "cau_db_version", "$cau_db_version" );
97
  }
98
 
99
  // Check if database table exists before creating
100
+ function cau_check_if_exists( $whattocheck, $id = 'name', $db_table = 'auto_updates' ) {
101
 
102
  global $wpdb;
103
+ $table_name = $wpdb->prefix.$db_table;
104
 
105
+ $rows = $wpdb->get_col( "SELECT COUNT(*) as num_rows FROM {$table_name} WHERE {$id} = '{$whattocheck}'" );
106
  $check = $rows[0];
107
 
108
  if( $check > 0 ) {
122
 
123
  // Update configs
124
  if( !cau_check_if_exists( 'plugins' ) ) $wpdb->insert( $table_name, array( 'name' => 'plugins', 'onoroff' => 'on' ) );
125
+ if( !cau_check_if_exists( 'themes' ) ) $wpdb->insert( $table_name, array( 'name' => 'themes', 'onoroff' => 'on' ) );
126
+ if( !cau_check_if_exists( 'minor' ) ) $wpdb->insert( $table_name, array( 'name' => 'minor', 'onoroff' => 'on' ) );
127
+ if( !cau_check_if_exists( 'major' ) ) $wpdb->insert( $table_name, array( 'name' => 'major', 'onoroff' => '' ) );
128
 
129
  // Email configs
130
+ if( !cau_check_if_exists( 'email' ) ) $wpdb->insert( $table_name, array( 'name' => 'email', 'onoroff' => '' ) );
131
+ if( !cau_check_if_exists( 'send' ) ) $wpdb->insert( $table_name, array( 'name' => 'send', 'onoroff' => '' ) );
132
+ if( !cau_check_if_exists( 'sendupdate' ) ) $wpdb->insert( $table_name, array( 'name' => 'sendupdate', 'onoroff' => '' ) );
133
 
134
  // Advanced
135
+ if( !cau_check_if_exists( 'notUpdateList' ) ) $wpdb->insert( $table_name, array( 'name' => 'notUpdateList', 'onoroff' => '' ) );
136
+ if( !cau_check_if_exists( 'translations' ) ) $wpdb->insert( $table_name, array( 'name' => 'translations', 'onoroff' => 'on' ) );
137
+ if( !cau_check_if_exists( 'wpemails' ) ) $wpdb->insert( $table_name, array( 'name' => 'wpemails', 'onoroff' => 'on' ) );
138
+
139
 
140
  }
141
  register_activation_hook( __FILE__, 'cau_install' );
143
  // Clear everything on deactivation
144
  function cau_remove() {
145
  global $wpdb;
146
+ $autoupdates = $wpdb->prefix."auto_updates";
147
+ $updateLog = $wpdb->prefix."update_log";
148
+ $wpdb->query( "DROP TABLE IF EXISTS $autoupdates" );
149
+ $wpdb->query( "DROP TABLE IF EXISTS $updateLog" );
150
  wp_clear_scheduled_hook('cau_set_schedule_mail');
151
  }
152
  register_deactivation_hook( __FILE__, 'cau_remove' );
161
  }
162
  add_action( 'upgrader_process_complete', 'cau_update_db_check' );
163
 
164
+ // Manual update
165
+ function cau_manual_update() {
166
+ cau_update_db_check();
167
+ }
168
+
169
  // Load custom functions
170
  require_once( plugin_dir_path( __FILE__ ) . 'cau_functions.php' );
171
 
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: auto, automatic, background, update, updates, updating, automatic updates,
5
  Requires at least: 3.6.0
6
  Tested up to: 5.3
7
  Requires PHP: 5.1
8
- Stable tag: 3.4.3
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -68,6 +68,10 @@ Settings can be found trough Tools > Auto Updater
68
 
69
  == Changelog ==
70
 
 
 
 
 
71
  = 3.4.3 (November 8, 2019) =
72
  * New: Options for "Weekly", "Twice a month" and "Monthly" for scheduling
73
  * New: Added Database version to status page
5
  Requires at least: 3.6.0
6
  Tested up to: 5.3
7
  Requires PHP: 5.1
8
+ Stable tag: 3.4.4
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
68
 
69
  == Changelog ==
70
 
71
+ = 3.4.4 (November 16, 2019) =
72
+ * Sometimes the database wouldn't correctly update to the newest version, we've added a manual button for this now.
73
+ * Sometimes plugins excluded from the updater would still update, this should be fixed now.
74
+
75
  = 3.4.3 (November 8, 2019) =
76
  * New: Options for "Weekly", "Twice a month" and "Monthly" for scheduling
77
  * New: Added Database version to status page