updated plugin `Companion Auto Update` version 3.8.2

This commit is contained in:
KawaiiPunk 2021-07-25 23:24:59 +00:00 committed by Gitium
parent e80e4be44b
commit d7964b08bd
7 changed files with 3556 additions and 3482 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,480 +1,512 @@
<?php <?php
// Check if emails should be send or not // Check if emails should be send or not
function cau_check_updates_mail() { function cau_check_updates_mail() {
// Notify of pending updates // Notify of pending updates
if( cau_get_db_value( 'send' ) == 'on' ) { if( cau_get_db_value( 'send' ) == 'on' ) {
cau_list_theme_updates(); // Check for theme updates cau_list_theme_updates(); // Check for theme updates
cau_list_plugin_updates(); // Check for plugin updates cau_list_plugin_updates(); // Check for plugin updates
} }
// Notify of completed updates // Notify of completed updates
if( cau_get_db_value( 'sendupdate' ) == 'on' && cau_get_db_value( 'plugins' ) == 'on' ) { if( cau_get_db_value( 'sendupdate' ) == 'on' && cau_get_db_value( 'plugins' ) == 'on' ) {
cau_plugin_updated(); // Check for updated plugins cau_plugin_updated(); // Check for updated plugins
} }
} // Notify of required db update
if( cau_get_db_value( 'dbupdateemails' ) == 'on' ) {
// Notify of out of date software cau_notify_outofdate_db();
function cau_outdated_notifier_mail() { }
if( cau_get_db_value( 'sendoutdated' ) == 'on' ) {
cau_list_outdated_software(); // Check for oudated plugins }
}
} // Notify of out of date software
function cau_outdated_notifier_mail() {
// Ge the emailadresses it should be send to if( cau_get_db_value( 'sendoutdated' ) == 'on' ) {
function cau_set_email() { cau_list_outdated_software(); // Check for oudated plugins
}
$emailArray = array(); }
if( cau_get_db_value( 'email' ) == '' ) { // Ge the emailadresses it should be send to
array_push( $emailArray, get_option('admin_email') ); function cau_set_email() {
} else {
$emailAdresses = cau_get_db_value( 'email' ); $emailArray = array();
$list = explode( ", ", $emailAdresses );
foreach ( $list as $key ) { if( cau_get_db_value( 'email' ) == '' ) {
array_push( $emailArray, $list ); array_push( $emailArray, get_option('admin_email') );
} } else {
} $emailAdresses = cau_get_db_value( 'email' );
$list = explode( ", ", $emailAdresses );
return $emailArray; foreach ( $list as $key ) {
array_push( $emailArray, $list );
} }
}
// Mail format
function cau_is_html() { return $emailArray;
// Check if cau_get_db_value() function exists. }
if ( !function_exists( 'cau_get_db_value' ) ) require_once( plugin_dir_path( __FILE__ ) . 'cau_function.php' );
// Mail format
// Check if html function cau_is_html() {
if( cau_get_db_value( 'html_or_text' ) == 'html' ) {
$html = true; // Check if cau_get_db_value() function exists.
} else { if ( !function_exists( 'cau_get_db_value' ) ) require_once( plugin_dir_path( __FILE__ ) . 'cau_function.php' );
$html = false;
} // Check if html
if( cau_get_db_value( 'html_or_text' ) == 'html' ) {
} $html = true;
} else {
// Set the content for the emails about pending updates $html = false;
function cau_outdated_message( $single, $plural, $list ) { }
// WP version }
$wpversion = get_bloginfo( 'version' );
// Set the content for the emails about pending updates
// Base text function cau_outdated_message( $single, $plural, $list ) {
$text = sprintf( esc_html__( "You have %s on your WordPress site at %s that have not been tested with the latest 3 major releases of WordPress.", "companion-auto-update" ), $plural, get_site_url() );
$text .= "\n"; // WP version
$text .= "\n"; $wpversion = get_bloginfo( 'version' );
// The list // Base text
if( !empty( $list ) ) { $text = sprintf( esc_html__( "You have %s on your WordPress site at %s that have not been tested with the latest 3 major releases of WordPress.", "companion-auto-update" ), $plural, get_site_url() );
$text .= "\n";
$text .= sprintf( esc_html__( "The following %s have not been tested with WordPress %s:", "companion-auto-update" ), $plural, $wpversion ); $text .= "\n";
$text .= "\n";
$text .= "\n"; // The list
if( !empty( $list ) ) {
foreach ( $list as $plugin => $version ) {
if( $version == '' ) $version = __( "Unknown", "companion-auto-update" ); $text .= sprintf( esc_html__( "The following %s have not been tested with WordPress %s:", "companion-auto-update" ), $plural, $wpversion );
$text .= "- ".sprintf( esc_html__( "%s tested up to: %s", "companion-auto-update" ), $plugin, $version )."\n"; $text .= "\n";
} $text .= "\n";
} foreach ( $list as $plugin => $version ) {
if( $version == '' ) $version = __( "Unknown", "companion-auto-update" );
return $text; $text .= "- ".sprintf( esc_html__( "%s tested up to: %s", "companion-auto-update" ), $plugin, $version )."\n";
}
}
}
// Set the content for the emails about pending updates
function cau_pending_message( $single, $plural, $list ) { return $text;
// What markup to use }
if( cau_is_html() ) $break = '<br />';
else $break = "\n"; // Set the content for the emails about pending updates
function cau_pending_message( $single, $plural, $list ) {
// Base text
$text = sprintf( esc_html__( 'You have pending %1$s updates on your WordPress site at %2$s.', 'companion-auto-update' ), $single, get_site_url() ); // What markup to use
$text .= $break; if( cau_is_html() ) $break = '<br />';
else $break = "\n";
if( !empty( $list ) ) {
// Base text
$text .= $break; $text = sprintf( esc_html__( 'You have pending %1$s updates on your WordPress site at %2$s.', 'companion-auto-update' ), $single, get_site_url() );
$text .= sprintf( esc_html__( 'The following %1$s have new versions available.', 'companion-auto-update' ), $plural ); $text .= $break;
$text .= $break;
if( !empty( $list ) ) {
if( cau_is_html() ) $text .= "<ol>";
foreach ( $list as $key => $value ) { $text .= $break;
if( cau_is_html() ) { $text .= sprintf( esc_html__( 'The following %1$s have new versions available.', 'companion-auto-update' ), $plural );
$text .= "<li>$value</li>"; $text .= $break;
} else {
$text .= "-$value\n"; if( cau_is_html() ) $text .= "<ol>";
} foreach ( $list as $key => $value ) {
} if( cau_is_html() ) {
if( cau_is_html() ) $text .= "</ol>"; $text .= "<li>$value</li>";
} else {
$text .= $break; $text .= "-$value\n";
} }
}
$text .= __( 'Leaving your site outdated is a security risk so please consider manually updating them.', 'companion-auto-update' ); if( cau_is_html() ) $text .= "</ol>";
$text .= $break;
$text .= $break;
// End }
$text .= sprintf( esc_html__( 'Head over to %1$s and check the ones you want to update.', 'companion-auto-update' ), get_admin_url().'update-core.php' );
$text .= __( 'Leaving your site outdated is a security risk so please consider manually updating them.', 'companion-auto-update' );
return $text; $text .= $break;
} // End
$text .= sprintf( esc_html__( 'Head over to %1$s and check the ones you want to update.', 'companion-auto-update' ), get_admin_url().'update-core.php' );
// Set the content for the emails about recent updates
function cau_updated_message( $type, $updatedList ) { return $text;
// What markup to use }
if( cau_is_html() ) $break = '<br />';
else $break = "\n"; // Set the content for the emails about recent updates
function cau_updated_message( $type, $updatedList ) {
// The message
$text = sprintf( esc_html__( // What markup to use
'One or more %1$s on your WordPress site at %2$s have been updated by Companion Auto Update. No further action is needed on your part. if( cau_is_html() ) $break = '<br />';
For more info on what is new visit your dashboard and check the changelog.', 'companion-auto-update' else $break = "\n";
), $type, get_site_url() );
// The message
$text .= $break; $text = sprintf( esc_html__(
$text .= $break; 'One or more %1$s on your WordPress site at %2$s have been updated by Companion Auto Update. No further action is needed on your part.
$text .= sprintf( esc_html__( For more info on what is new visit your dashboard and check the changelog.', 'companion-auto-update'
'The following %1$s have been updated:', 'companion-auto-update' ), $type, get_site_url() );
), $type );
$text .= $break;
$text .= $break; $text .= $break;
$text .= $updatedList; $text .= sprintf( esc_html__(
'The following %1$s have been updated:', 'companion-auto-update'
$text .= $break; ), $type );
$text .= __( "(You'll also receive this email if you manually updated a plugin or theme)", "companion-auto-update" );
$text .= $break;
return $text; $text .= $updatedList;
} $text .= $break;
$text .= __( "(You'll also receive this email if you manually updated a plugin or theme)", "companion-auto-update" );
// Checks if plugins are out of date
function cau_list_outdated_software() { return $text;
// Check if cau_get_db_value() function exists. }
if ( !function_exists( 'cau_get_db_value' ) ) require_once( plugin_dir_path( __FILE__ ) . 'cau_function.php' );
// Checks if plugins are out of date
// Set up mail function cau_list_outdated_software() {
$subject = '['.get_bloginfo( 'name' ).'] ' . __( 'You have outdated plugins on your site.', 'companion-auto-update' );
$type = __( 'plugin', 'companion-auto-update' ); // Check if cau_get_db_value() function exists.
$type_plural = __( 'plugins', 'companion-auto-update' ); if ( !function_exists( 'cau_get_db_value' ) ) require_once( plugin_dir_path( __FILE__ ) . 'cau_function.php' );
$message = cau_outdated_message( $type, $type_plural, cau_list_outdated() );
// Set up mail
// Send to all addresses $subject = '['.get_bloginfo( 'name' ).'] ' . __( 'You have outdated plugins on your site.', 'companion-auto-update' );
foreach ( cau_set_email() as $key => $value ) { $type = __( 'plugin', 'companion-auto-update' );
foreach ( $value as $k => $v ) { $type_plural = __( 'plugins', 'companion-auto-update' );
wp_mail( $v, $subject, $message ); $message = cau_outdated_message( $type, $type_plural, cau_list_outdated() );
}
break; // Send to all addresses
} foreach ( cau_set_email() as $key => $value ) {
foreach ( $value as $k => $v ) {
} wp_mail( $v, $subject, $message );
}
// Checks if theme updates are available break;
function cau_list_theme_updates() { }
global $wpdb; }
$table_name = $wpdb->prefix . "auto_updates";
// Checks if theme updates are available
$configs = $wpdb->get_results( "SELECT * FROM $table_name WHERE name = 'themes'"); function cau_list_theme_updates() {
foreach ( $configs as $config ) {
global $wpdb;
if( $config->onoroff != 'on' ) { $table_name = $wpdb->prefix . "auto_updates";
require_once ABSPATH . '/wp-admin/includes/update.php'; $configs = $wpdb->get_results( "SELECT * FROM $table_name WHERE name = 'themes'");
$themes = get_theme_updates(); foreach ( $configs as $config ) {
$list = array();
if( $config->onoroff != 'on' ) {
if ( !empty( $themes ) ) {
require_once ABSPATH . '/wp-admin/includes/update.php';
foreach ( $themes as $stylesheet => $theme ) { $themes = get_theme_updates();
array_push( $list, $theme->get( 'Name' ) ); $list = array();
}
if ( !empty( $themes ) ) {
$subject = '[' . get_bloginfo( 'name' ) . '] ' . __( 'Theme update available.', 'companion-auto-update' );
$type = __('theme', 'companion-auto-update'); foreach ( $themes as $stylesheet => $theme ) {
$type_plural = __('themes', 'companion-auto-update'); array_push( $list, $theme->get( 'Name' ) );
$message = cau_pending_message( $type, $type_plural, $list ); }
foreach ( cau_set_email() as $key => $value) { $subject = '[' . get_bloginfo( 'name' ) . '] ' . __( 'Theme update available.', 'companion-auto-update' );
foreach ($value as $k => $v) { $type = __('theme', 'companion-auto-update');
wp_mail( $v, $subject, $message ); $type_plural = __('themes', 'companion-auto-update');
} $message = cau_pending_message( $type, $type_plural, $list );
break;
} foreach ( cau_set_email() as $key => $value) {
} foreach ($value as $k => $v) {
wp_mail( $v, $subject, $message );
} }
break;
} }
}
}
}
// Checks if plugin updates are available
function cau_list_plugin_updates() { }
global $wpdb; }
$table_name = $wpdb->prefix . "auto_updates";
// Checks if plugin updates are available
$configs = $wpdb->get_results( "SELECT * FROM $table_name WHERE name = 'plugins'"); function cau_list_plugin_updates() {
foreach ( $configs as $config ) {
global $wpdb;
if( $config->onoroff != 'on' ) { $table_name = $wpdb->prefix . "auto_updates";
require_once(ABSPATH . 'wp-admin/includes/plugin-install.php'); $configs = $wpdb->get_results( "SELECT * FROM $table_name WHERE name = 'plugins'");
$plugins = get_plugin_updates(); foreach ( $configs as $config ) {
if ( !empty( $plugins ) ) { if( $config->onoroff != 'on' ) {
$list = array(); require_once(ABSPATH . 'wp-admin/includes/plugin-install.php');
foreach ( (array) $plugins as $plugin_file => $plugin_data ) {
$plugin_data = (object) _get_plugin_data_markup_translate( $plugin_file, (array) $plugin_data, false, true ); if ( !function_exists( 'get_plugin_updates' ) ) require_once ABSPATH . 'wp-admin/includes/update.php';
$name = $plugin_data->Name; $plugins = get_plugin_updates();
array_push( $list, $name );
} if ( !empty( $plugins ) ) {
$subject = '[' . get_bloginfo( 'name' ) . '] ' . __( 'Plugin update available.', 'companion-auto-update' ); $list = array();
$type = __( 'plugin', 'companion-auto-update' ); foreach ( (array) $plugins as $plugin_file => $plugin_data ) {
$type_plural = __( 'plugins', 'companion-auto-update' ); $plugin_data = (object) _get_plugin_data_markup_translate( $plugin_file, (array) $plugin_data, false, true );
$message = cau_pending_message( $type, $type_plural, $list ); $name = $plugin_data->Name;
array_push( $list, $name );
foreach ( cau_set_email() as $key => $value) { }
foreach ($value as $k => $v) {
wp_mail( $v, $subject, $message ); $subject = '[' . get_bloginfo( 'name' ) . '] ' . __( 'Plugin update available.', 'companion-auto-update' );
} $type = __( 'plugin', 'companion-auto-update' );
break; $type_plural = __( 'plugins', 'companion-auto-update' );
} $message = cau_pending_message( $type, $type_plural, $list );
}
foreach ( cau_set_email() as $key => $value) {
} foreach ($value as $k => $v) {
wp_mail( $v, $subject, $message );
} }
} break;
}
// Alerts when plugin has been updated }
function cau_plugin_updated() {
}
// Check if cau_get_db_value() function exists.
if ( !function_exists( 'cau_get_db_value' ) ) require_once( plugin_dir_path( __FILE__ ) . 'cau_function.php' ); }
}
// Set the correct timezone for emails
date_default_timezone_set( cau_get_proper_timezone() ); // Alerts when plugin has been updated
function cau_plugin_updated() {
// Create arrays
$pluginNames = array(); // Check if cau_get_db_value() function exists.
$pluginDates = array(); if ( !function_exists( 'cau_get_db_value' ) ) require_once( plugin_dir_path( __FILE__ ) . 'cau_function.php' );
$pluginVersion = array();
$pluginSlug = array(); // Set the correct timezone for emails
$pluginTimes = array(); date_default_timezone_set( cau_get_proper_timezone() );
$themeNames = array();
$themeDates = array(); // Create arrays
$themeTimes = array(); $pluginNames = array();
$pluginDates = array();
// Where to look for plugins $pluginVersion = array();
$plugdir = plugin_dir_path( __DIR__ ); $pluginSlug = array();
if ( !function_exists( 'get_plugins' ) ) require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); // Check if get_plugins() function exists. $pluginTimes = array();
$allPlugins = get_plugins(); $themeNames = array();
$themeDates = array();
// Where to look for themes $themeTimes = array();
$themedir = get_theme_root();
$allThemes = wp_get_themes(); // Where to look for plugins
$plugdir = plugin_dir_path( __DIR__ );
// Mail schedule if ( !function_exists( 'get_plugins' ) ) require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); // Check if get_plugins() function exists.
$schedule_mail = wp_get_schedule( 'cau_set_schedule_mail' ); $allPlugins = get_plugins();
// Loop trough all plugins // Where to look for themes
foreach ( $allPlugins as $key => $value ) { $themedir = get_theme_root();
$allThemes = wp_get_themes();
// Get plugin data
$fullPath = $plugdir.'/'.$key; // Mail schedule
$getFile = $path_parts = pathinfo( $fullPath ); $schedule_mail = wp_get_schedule( 'cau_set_schedule_mail' );
$pluginData = get_plugin_data( $fullPath );
// Loop trough all plugins
// Get the slug foreach ( $allPlugins as $key => $value ) {
$explosion = explode( '/', $key );
$actualSlug = array_shift( $explosion ); // Get plugin data
$fullPath = $plugdir.'/'.$key;
// Get last update date $getFile = $path_parts = pathinfo( $fullPath );
$fileDate = date ( 'YmdHi', filemtime( $fullPath ) ); $pluginData = get_plugin_data( $fullPath );
switch ( $schedule_mail ) { // Get the slug
case 'hourly': $explosion = explode( '/', $key );
$lastday = date( 'YmdHi', strtotime( '-1 hour', time() ) ); $actualSlug = array_shift( $explosion );
break;
case 'twicedaily': // Get last update date
$lastday = date( 'YmdHi', strtotime( '-12 hours', time() ) ); $fileDate = date ( 'YmdHi', filemtime( $fullPath ) );
break;
default: switch ( $schedule_mail ) {
$lastday = date( 'YmdHi', strtotime( '-1 day', time() ) ); case 'hourly':
break; $lastday = date( 'YmdHi', strtotime( '-1 hour', time() ) );
} break;
case 'twicedaily':
$dateFormat = get_option( 'date_format' ); $lastday = date( 'YmdHi', strtotime( '-12 hours', time() ) );
$timestamp = date_i18n( $dateFormat, filemtime( $fullPath ) ); break;
$timestamp .= ' - '.date( 'H:i', filemtime( $fullPath ) ); default:
$lastday = date( 'YmdHi', strtotime( '-1 day', time() ) );
if( $fileDate >= $lastday ) { break;
}
// Get plugin name
foreach ( $pluginData as $dataKey => $dataValue ) { $dateFormat = get_option( 'date_format' );
if( $dataKey == 'Name') { $timestamp = date_i18n( $dateFormat, filemtime( $fullPath ) );
array_push( $pluginNames , $dataValue ); $timestamp .= ' - '.date( 'H:i', filemtime( $fullPath ) );
}
if( $dataKey == 'Version') { if( $fileDate >= $lastday ) {
array_push( $pluginVersion , $dataValue );
} // Get plugin name
} foreach ( $pluginData as $dataKey => $dataValue ) {
if( $dataKey == 'Name') {
array_push( $pluginDates, $fileDate ); array_push( $pluginNames , $dataValue );
array_push( $pluginSlug, $actualSlug ); }
array_push( $pluginTimes, $timestamp ); if( $dataKey == 'Version') {
} array_push( $pluginVersion , $dataValue );
}
} }
// Loop trough all themes array_push( $pluginDates, $fileDate );
foreach ( $allThemes as $key => $value ) { array_push( $pluginSlug, $actualSlug );
array_push( $pluginTimes, $timestamp );
// Get theme data }
$fullPath = $themedir.'/'.$key;
$getFile = $path_parts = pathinfo( $fullPath ); }
// Get last update date // Loop trough all themes
$dateFormat = get_option( 'date_format' ); foreach ( $allThemes as $key => $value ) {
$fileDate = date ( 'YmdHi', filemtime( $fullPath ) );
// Get theme data
if( $schedule_mail == 'hourly' ) { $fullPath = $themedir.'/'.$key;
$lastday = date( 'YmdHi', strtotime( '-1 hour', time() ) ); $getFile = $path_parts = pathinfo( $fullPath );
} elseif( $schedule_mail == 'twicedaily' ) {
$lastday = date( 'YmdHi', strtotime( '-12 hours', time() ) ); // Get last update date
} elseif( $schedule_mail == 'daily' ) { $dateFormat = get_option( 'date_format' );
$lastday = date( 'YmdHi', strtotime( '-1 day', time() ) ); $fileDate = date ( 'YmdHi', filemtime( $fullPath ) );
}
if( $schedule_mail == 'hourly' ) {
$dateFormat = get_option( 'date_format' ); $lastday = date( 'YmdHi', strtotime( '-1 hour', time() ) );
$timestamp = date_i18n( $dateFormat, filemtime( $fullPath ) ); } elseif( $schedule_mail == 'twicedaily' ) {
$timestamp .= ' - '.date( 'H:i', filemtime( $fullPath ) ); $lastday = date( 'YmdHi', strtotime( '-12 hours', time() ) );
} elseif( $schedule_mail == 'daily' ) {
if( $fileDate >= $lastday ) { $lastday = date( 'YmdHi', strtotime( '-1 day', time() ) );
array_push( $themeNames, $path_parts['filename'] ); }
array_push( $themeDates, $fileDate );
array_push( $themeTimes, $timestamp ); $dateFormat = get_option( 'date_format' );
} $timestamp = date_i18n( $dateFormat, filemtime( $fullPath ) );
$timestamp .= ' - '.date( 'H:i', filemtime( $fullPath ) );
}
if( $fileDate >= $lastday ) {
$totalNumP = 0; array_push( $themeNames, $path_parts['filename'] );
$totalNumT = 0; array_push( $themeDates, $fileDate );
$updatedListP = ''; array_push( $themeTimes, $timestamp );
$updatedListT = ''; }
if( cau_get_db_value( 'html_or_text' ) == 'html' ) { }
$updatedListP .= '<ol>';
$updatedListT .= '<ol>'; $totalNumP = 0;
} $totalNumT = 0;
$updatedListP = '';
foreach ( $pluginDates as $key => $value ) { $updatedListT = '';
if( cau_get_db_value( 'html_or_text' ) == 'html' ) { if( cau_get_db_value( 'html_or_text' ) == 'html' ) {
$updatedListP .= '<ol>';
$more_info = ''; $updatedListT .= '<ol>';
if( cau_get_db_value( 'advanced_info_emails' ) == 'on' ) $more_info = "<br /><span style='opacity: 0.5;'>".__( "Time of update", "companion-auto-update" ).": ".$pluginTimes[$key]."</span>"; }
$updatedListP .= "<li> foreach ( $pluginDates as $key => $value ) {
<strong>".$pluginNames[$key]." </strong><br />
".__( "to version", "companion-auto-update" )." ".$pluginVersion[$key]." <a href='https://wordpress.org/plugins/".$pluginSlug[$key]."/#developers'>".__( "Release notes", "companion-auto-update" )."</a> if( cau_get_db_value( 'html_or_text' ) == 'html' ) {
".$more_info."
</li>"; $more_info = '';
if( cau_get_db_value( 'advanced_info_emails' ) == 'on' ) $more_info = "<br /><span style='opacity: 0.5;'>".__( "Time of update", "companion-auto-update" ).": ".$pluginTimes[$key]."</span>";
} else {
$updatedListP .= "<li>
$updatedListP .= "- ".$pluginNames[$key]." ".__( "to version", "companion-auto-update" )." ".$pluginVersion[$key]."\n"; <strong>".$pluginNames[$key]." </strong><br />
$updatedListP .= " ".__( "Release notes", "companion-auto-update" ).": https://wordpress.org/plugins/".$pluginSlug[$key]."/#developers\n"; ".__( "to version", "companion-auto-update" )." ".$pluginVersion[$key]." <a href='https://wordpress.org/plugins/".$pluginSlug[$key]."/#developers'>".__( "Release notes", "companion-auto-update" )."</a>
".$more_info."
} </li>";
$totalNumP++; } else {
}
$updatedListP .= "- ".$pluginNames[$key]." ".__( "to version", "companion-auto-update" )." ".$pluginVersion[$key]."\n";
foreach ( $themeNames as $key => $value ) { $updatedListP .= " ".__( "Release notes", "companion-auto-update" ).": https://wordpress.org/plugins/".$pluginSlug[$key]."/#developers\n";
if( cau_get_db_value( 'html_or_text' ) == 'html' ) { }
$more_info = ''; $totalNumP++;
if( cau_get_db_value( 'advanced_info_emails' ) == 'on' ) $more_info = "<br /><span style='opacity: 0.5;'>".__( "Time of update", "companion-auto-update" ).": ".$themeTimes[$key]."</span>"; }
$updatedListT .= "<li><strong>".$themeNames[$key]."</strong>".$more_info."</li>";
foreach ( $themeNames as $key => $value ) {
} else {
$updatedListT .= "- ".$themeNames[$key]."\n"; if( cau_get_db_value( 'html_or_text' ) == 'html' ) {
}
$more_info = '';
$totalNumT++; if( cau_get_db_value( 'advanced_info_emails' ) == 'on' ) $more_info = "<br /><span style='opacity: 0.5;'>".__( "Time of update", "companion-auto-update" ).": ".$themeTimes[$key]."</span>";
} $updatedListT .= "<li><strong>".$themeNames[$key]."</strong>".$more_info."</li>";
if( cau_get_db_value( 'html_or_text' ) == 'html' ) { } else {
$updatedListP .= '</ol>'; $updatedListT .= "- ".$themeNames[$key]."\n";
$updatedListT .= '</ol>'; }
}
$totalNumT++;
// Set the email content type }
if( cau_get_db_value( 'html_or_text' ) == 'html' ) {
function cau_mail_content_type() { if( cau_get_db_value( 'html_or_text' ) == 'html' ) {
return 'text/html'; $updatedListP .= '</ol>';
} $updatedListT .= '</ol>';
add_filter( 'wp_mail_content_type', 'cau_mail_content_type' ); }
}
// Set the email content type
// If plugins have been updated, send email if( cau_get_db_value( 'html_or_text' ) == 'html' ) {
if( $totalNumP > 0 ) { function cau_mail_content_type() {
return 'text/html';
// E-mail content }
$subject = '[' . get_bloginfo( 'name' ) . '] ' . __('One or more plugins have been updated.', 'companion-auto-update'); add_filter( 'wp_mail_content_type', 'cau_mail_content_type' );
$type = __('plugins', 'companion-auto-update'); }
$message = cau_updated_message( $type, $updatedListP );
// If plugins have been updated, send email
// Send to all addresses if( $totalNumP > 0 ) {
foreach ( cau_set_email() as $key => $value) {
foreach ($value as $k => $v) { // E-mail content
wp_mail( $v, $subject, $message ); $subject = '[' . get_bloginfo( 'name' ) . '] ' . __('One or more plugins have been updated.', 'companion-auto-update');
} $type = __('plugins', 'companion-auto-update');
break; $message = cau_updated_message( $type, $updatedListP );
}
// Send to all addresses
} foreach ( cau_set_email() as $key => $value) {
foreach ($value as $k => $v) {
// If themes have been updated, send email wp_mail( $v, $subject, $message );
if( $totalNumT > 0 ) { }
break;
// E-mail content }
$subject = '[' . get_bloginfo( 'name' ) . '] ' . __('One or more themes have been updated.', 'companion-auto-update');
$type = __('themes', 'companion-auto-update'); }
$message = cau_updated_message( $type, $updatedListT );
// If themes have been updated, send email
// Send to all addresses if( $totalNumT > 0 ) {
foreach ( cau_set_email() as $key => $value) {
foreach ($value as $k => $v) { // E-mail content
wp_mail( $v, $subject, $message ); $subject = '[' . get_bloginfo( 'name' ) . '] ' . __('One or more themes have been updated.', 'companion-auto-update');
} $type = __('themes', 'companion-auto-update');
break; $message = cau_updated_message( $type, $updatedListT );
}
// Send to all addresses
} foreach ( cau_set_email() as $key => $value) {
foreach ($value as $k => $v) {
if( cau_get_db_value( 'html_or_text' ) == 'html' ) remove_filter( 'wp_mail_content_type', 'cau_mail_content_type' ); wp_mail( $v, $subject, $message );
}
// Prevent duplicate emails by setting the event again break;
if( $totalNumT > 0 OR $totalNumP > 0 ) { }
if( $schedule_mail == 'hourly' ) {
wp_clear_scheduled_hook('cau_set_schedule_mail'); }
wp_schedule_event( strtotime( '+1 hour', time() ) , 'hourly', 'cau_set_schedule_mail' );
} if( cau_get_db_value( 'html_or_text' ) == 'html' ) remove_filter( 'wp_mail_content_type', 'cau_mail_content_type' );
}
// Prevent duplicate emails by setting the event again
} if( $totalNumT > 0 OR $totalNumP > 0 ) {
if( $schedule_mail == 'hourly' ) {
wp_clear_scheduled_hook('cau_set_schedule_mail');
wp_schedule_event( strtotime( '+1 hour', time() ) , 'hourly', 'cau_set_schedule_mail' );
}
}
}
function cau_notify_outofdate_db() {
// Check if cau_get_db_value() function exists.
if ( !function_exists( 'cau_get_db_value' ) ) require_once( plugin_dir_path( __FILE__ ) . 'cau_function.php' );
// Database requires an update
if ( cau_incorrectDatabaseVersion() ) {
// Set up mail
$subject = '[' . get_bloginfo( 'name' ) . '] ' . __( 'We need your help with something', 'companion-auto-update' );
$message = __( 'Hi there! We need your help updating the database of Companion Auto Update to the latest version. No rush, old features will continue to work but some new features might not work until you update the database.', 'companion-auto-update' );
// Send to all addresses
foreach ( cau_set_email() as $key => $value ) {
foreach ( $value as $k => $v ) {
wp_mail( $v, $subject, $message );
}
break;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,465 +1,466 @@
<?php <?php
/* /*
* Plugin Name: Companion Auto Update * Plugin Name: Companion Auto Update
* Plugin URI: http://codeermeneer.nl/portfolio/companion-auto-update/ * Plugin URI: http://codeermeneer.nl/portfolio/companion-auto-update/
* Description: This plugin auto updates all plugins, all themes and the wordpress core. * Description: This plugin auto updates all plugins, all themes and the wordpress core.
* Version: 3.8.0 * Version: 3.8.2
* Author: Papin Schipper * Author: Papin Schipper
* Author URI: http://codeermeneer.nl/ * Author URI: http://codeermeneer.nl/
* Contributors: papin * Contributors: papin
* License: GPLv2 or later * License: GPLv2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html * License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: companion-auto-update * Text Domain: companion-auto-update
* Domain Path: /languages/ * Domain Path: /languages/
*/ */
// Disable direct access // Disable direct access
defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
// Load translations // Load translations
function cau_init() { function cau_init() {
load_plugin_textdomain( 'companion-auto-update', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); // Load language files (for backwards compat mostly) load_plugin_textdomain( 'companion-auto-update', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); // Load language files (for backwards compat mostly)
add_filter( 'plugins_auto_update_enabled', '__return_false' ); // Turn off default WP5.5 plugin update features to avoid confusion add_filter( 'plugins_auto_update_enabled', '__return_false' ); // Turn off default WP5.5 plugin update features to avoid confusion
add_filter( 'themes_auto_update_enabled', '__return_false' ); // Turn off default WP5.5 theme update features to avoid confusion add_filter( 'themes_auto_update_enabled', '__return_false' ); // Turn off default WP5.5 theme update features to avoid confusion
} }
add_action( 'init', 'cau_init' ); add_action( 'init', 'cau_init' );
// Set up the database and required schedules // Set up the database and required schedules
function cau_install( $network_wide ) { function cau_install( $network_wide ) {
if ( is_multisite() && $network_wide ) { if ( is_multisite() && $network_wide ) {
global $wpdb; global $wpdb;
$blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
foreach ( $blog_ids as $blog_id ) { foreach ( $blog_ids as $blog_id ) {
switch_to_blog( $blog_id ); switch_to_blog( $blog_id );
cau_database_creation(); cau_database_creation();
restore_current_blog(); restore_current_blog();
} }
} else { } else {
cau_database_creation(); cau_database_creation();
} }
if (! wp_next_scheduled ( 'cau_set_schedule_mail' )) wp_schedule_event( time(), 'daily', 'cau_set_schedule_mail'); // Set schedule for basic notifcations if (! wp_next_scheduled ( 'cau_set_schedule_mail' )) wp_schedule_event( time(), 'daily', 'cau_set_schedule_mail'); // Set schedule for basic notifcations
if (! wp_next_scheduled ( 'cau_custom_hooks_plugins' )) wp_schedule_event( time(), 'daily', 'cau_custom_hooks_plugins'); // Run custom hooks on plugin updates if (! wp_next_scheduled ( 'cau_custom_hooks_plugins' )) wp_schedule_event( time(), 'daily', 'cau_custom_hooks_plugins'); // Run custom hooks on plugin updates
if (! wp_next_scheduled ( 'cau_custom_hooks_themes' )) wp_schedule_event( time(), 'daily', 'cau_custom_hooks_themes'); // Run custom hooks on theme updates if (! wp_next_scheduled ( 'cau_custom_hooks_themes' )) wp_schedule_event( time(), 'daily', 'cau_custom_hooks_themes'); // Run custom hooks on theme updates
if (! wp_next_scheduled ( 'cau_log_updater' )) wp_schedule_event( ( time() - 1800 ), 'daily', 'cau_log_updater'); // Keep the log up to date if (! wp_next_scheduled ( 'cau_log_updater' )) wp_schedule_event( ( time() - 1800 ), 'daily', 'cau_log_updater'); // Keep the log up to date
if (! wp_next_scheduled ( 'cau_outdated_notifier' )) wp_schedule_event( time(), 'daily', 'cau_outdated_notifier'); // Set schedule for basic notifcations if (! wp_next_scheduled ( 'cau_outdated_notifier' )) wp_schedule_event( time(), 'daily', 'cau_outdated_notifier'); // Set schedule for basic notifcations
} }
add_action( 'cau_set_schedule_mail', 'cau_check_updates_mail' ); add_action( 'cau_set_schedule_mail', 'cau_check_updates_mail' );
add_action( 'cau_outdated_notifier', 'cau_outdated_notifier_mail' ); add_action( 'cau_outdated_notifier', 'cau_outdated_notifier_mail' );
add_action( 'wp_update_plugins', 'cau_run_custom_hooks_p' ); add_action( 'wp_update_plugins', 'cau_run_custom_hooks_p' );
add_action( 'wp_update_themes', 'cau_run_custom_hooks_t' ); add_action( 'wp_update_themes', 'cau_run_custom_hooks_t' );
add_action( 'wp_version_check', 'cau_run_custom_hooks_c' ); add_action( 'wp_version_check', 'cau_run_custom_hooks_c' );
// Hourly event to keep the log up to date // Hourly event to keep the log up to date
function cau_keep_log_uptodate() { function cau_keep_log_uptodate() {
cau_savePluginInformation(); // Check for new plugins and themes cau_savePluginInformation(); // Check for new plugins and themes
cau_check_delayed(); // Check for plugin delays cau_check_delayed(); // Check for plugin delays
} }
add_action( 'cau_log_updater', 'cau_keep_log_uptodate' ); add_action( 'cau_log_updater', 'cau_keep_log_uptodate' );
// Redirect to welcome screen on activation of plugin // Redirect to welcome screen on activation of plugin
function cau_pluginActivateWelcome() { function cau_pluginActivateWelcome() {
add_option( 'cau_redirectToWelcomeScreen', true ); add_option( 'cau_redirectToWelcomeScreen', true );
} }
register_activation_hook(__FILE__, 'cau_pluginActivateWelcome'); register_activation_hook(__FILE__, 'cau_pluginActivateWelcome');
function cau_pluginRedirectWelcomeScreen() { function cau_pluginRedirectWelcomeScreen() {
if ( get_option( 'cau_redirectToWelcomeScreen', false ) ) { if ( get_option( 'cau_redirectToWelcomeScreen', false ) ) {
delete_option( 'cau_redirectToWelcomeScreen' ); delete_option( 'cau_redirectToWelcomeScreen' );
if( !isset( $_GET['activate-multi'] ) ) { if( !isset( $_GET['activate-multi'] ) ) {
wp_redirect( admin_url( cau_menloc().'?page=cau-settings&welcome=1' ) ); wp_redirect( admin_url( cau_menloc().'?page=cau-settings&welcome=1' ) );
} }
} }
} }
add_action( 'admin_init', 'cau_pluginRedirectWelcomeScreen' ); add_action( 'admin_init', 'cau_pluginRedirectWelcomeScreen' );
// Donate url // Donate url
function cau_donateUrl() { function cau_donateUrl() {
return 'https://www.paypal.me/dakel/10/'; return 'https://www.paypal.me/dakel/10/';
} }
// Database version // Database version
function cau_db_version() { function cau_db_version() {
return '3.7.2'; return '3.8.1';
} }
function cau_database_creation() { function cau_database_creation() {
global $wpdb; global $wpdb;
// Plugin db info // Plugin db info
$cau_db_version = cau_db_version(); $cau_db_version = cau_db_version();
$autoupdates = $wpdb->prefix."auto_updates"; $autoupdates = $wpdb->prefix."auto_updates";
$updateLog = $wpdb->prefix."update_log"; $updateLog = $wpdb->prefix."update_log";
// WordPress db info // WordPress db info
$charset_collate = $wpdb->get_charset_collate(); $charset_collate = $wpdb->get_charset_collate();
// DB table creation queries // DB table creation queries
$sql = "CREATE TABLE $autoupdates ( $sql = "CREATE TABLE $autoupdates (
id INT(9) NOT NULL AUTO_INCREMENT, id INT(9) NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL,
onoroff TEXT NOT NULL, onoroff TEXT NOT NULL,
UNIQUE KEY id (id) UNIQUE KEY id (id)
) $charset_collate;"; ) $charset_collate;";
$sql2 = "CREATE TABLE $updateLog ( $sql2 = "CREATE TABLE $updateLog (
id INT(9) NOT NULL AUTO_INCREMENT, id INT(9) NOT NULL AUTO_INCREMENT,
slug VARCHAR(255) NOT NULL, slug VARCHAR(255) NOT NULL,
oldVersion VARCHAR(10) NOT NULL, oldVersion VARCHAR(10) NOT NULL,
newVersion VARCHAR(10) NOT NULL, newVersion VARCHAR(10) NOT NULL,
method VARCHAR(10) NOT NULL, method VARCHAR(10) NOT NULL,
put_on_hold VARCHAR(100) DEFAULT '0', put_on_hold VARCHAR(100) DEFAULT '0',
UNIQUE KEY id (id) UNIQUE KEY id (id)
) $charset_collate;"; ) $charset_collate;";
// Create DB tables // Create DB tables
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql ); dbDelta( $sql );
dbDelta( $sql2 ); dbDelta( $sql2 );
// Database version // Database version
add_option( "cau_db_version", "$cau_db_version" ); add_option( "cau_db_version", "$cau_db_version" );
// Insert data // Insert data
cau_install_data(); cau_install_data();
} }
// Check if database table exists before creating // Check if database table exists before creating
function cau_check_if_exists( $whattocheck, $id = 'name', $db_table = 'auto_updates' ) { function cau_check_if_exists( $whattocheck, $id = 'name', $db_table = 'auto_updates' ) {
global $wpdb; global $wpdb;
$table_name = $wpdb->prefix.$db_table; $table_name = $wpdb->prefix.$db_table;
$rows = $wpdb->get_col( "SELECT COUNT(*) as num_rows FROM {$table_name} WHERE {$id} = '{$whattocheck}'" ); $rows = $wpdb->get_col( "SELECT COUNT(*) as num_rows FROM {$table_name} WHERE {$id} = '{$whattocheck}'" );
$check = $rows[0]; $check = $rows[0];
if( $check > 0 ) { if( $check > 0 ) {
return true; return true;
} else { } else {
return false; return false;
} }
} }
// Insert date into database // Insert date into database
function cau_install_data() { function cau_install_data() {
global $wpdb; global $wpdb;
$table_name = $wpdb->prefix . "auto_updates"; $table_name = $wpdb->prefix . "auto_updates";
$toemail = get_option('admin_email'); $toemail = get_option('admin_email');
// Update configs // Update configs
if( !cau_check_if_exists( 'plugins' ) ) $wpdb->insert( $table_name, array( 'name' => 'plugins', 'onoroff' => 'on' ) ); if( !cau_check_if_exists( 'plugins' ) ) $wpdb->insert( $table_name, array( 'name' => 'plugins', 'onoroff' => 'on' ) );
if( !cau_check_if_exists( 'themes' ) ) $wpdb->insert( $table_name, array( 'name' => 'themes', 'onoroff' => 'on' ) ); if( !cau_check_if_exists( 'themes' ) ) $wpdb->insert( $table_name, array( 'name' => 'themes', 'onoroff' => 'on' ) );
if( !cau_check_if_exists( 'minor' ) ) $wpdb->insert( $table_name, array( 'name' => 'minor', 'onoroff' => 'on' ) ); if( !cau_check_if_exists( 'minor' ) ) $wpdb->insert( $table_name, array( 'name' => 'minor', 'onoroff' => 'on' ) );
if( !cau_check_if_exists( 'major' ) ) $wpdb->insert( $table_name, array( 'name' => 'major', 'onoroff' => '' ) ); if( !cau_check_if_exists( 'major' ) ) $wpdb->insert( $table_name, array( 'name' => 'major', 'onoroff' => '' ) );
// Email configs // Email configs
if( !cau_check_if_exists( 'email' ) ) $wpdb->insert( $table_name, array( 'name' => 'email', 'onoroff' => '' ) ); if( !cau_check_if_exists( 'email' ) ) $wpdb->insert( $table_name, array( 'name' => 'email', 'onoroff' => '' ) );
if( !cau_check_if_exists( 'send' ) ) $wpdb->insert( $table_name, array( 'name' => 'send', 'onoroff' => '' ) ); if( !cau_check_if_exists( 'send' ) ) $wpdb->insert( $table_name, array( 'name' => 'send', 'onoroff' => '' ) );
if( !cau_check_if_exists( 'sendupdate' ) ) $wpdb->insert( $table_name, array( 'name' => 'sendupdate', 'onoroff' => '' ) ); if( !cau_check_if_exists( 'sendupdate' ) ) $wpdb->insert( $table_name, array( 'name' => 'sendupdate', 'onoroff' => '' ) );
if( !cau_check_if_exists( 'sendoutdated' ) ) $wpdb->insert( $table_name, array( 'name' => 'sendoutdated', 'onoroff' => '' ) ); if( !cau_check_if_exists( 'sendoutdated' ) ) $wpdb->insert( $table_name, array( 'name' => 'sendoutdated', 'onoroff' => '' ) );
// Advanced // Advanced
if( !cau_check_if_exists( 'notUpdateList' ) ) $wpdb->insert( $table_name, array( 'name' => 'notUpdateList', 'onoroff' => '' ) ); if( !cau_check_if_exists( 'notUpdateList' ) ) $wpdb->insert( $table_name, array( 'name' => 'notUpdateList', 'onoroff' => '' ) );
if( !cau_check_if_exists( 'translations' ) ) $wpdb->insert( $table_name, array( 'name' => 'translations', 'onoroff' => 'on' ) ); if( !cau_check_if_exists( 'translations' ) ) $wpdb->insert( $table_name, array( 'name' => 'translations', 'onoroff' => 'on' ) );
if( !cau_check_if_exists( 'wpemails' ) ) $wpdb->insert( $table_name, array( 'name' => 'wpemails', 'onoroff' => 'on' ) ); if( !cau_check_if_exists( 'wpemails' ) ) $wpdb->insert( $table_name, array( 'name' => 'wpemails', 'onoroff' => 'on' ) );
if( !cau_check_if_exists( 'notUpdateListTh' ) ) $wpdb->insert( $table_name, array( 'name' => 'notUpdateListTh', 'onoroff' => '' ) ); if( !cau_check_if_exists( 'notUpdateListTh' ) ) $wpdb->insert( $table_name, array( 'name' => 'notUpdateListTh', 'onoroff' => '' ) );
// Stuff // Stuff
if( !cau_check_if_exists( 'html_or_text' ) ) $wpdb->insert( $table_name, array( 'name' => 'html_or_text', 'onoroff' => 'html' ) ); if( !cau_check_if_exists( 'html_or_text' ) ) $wpdb->insert( $table_name, array( 'name' => 'html_or_text', 'onoroff' => 'html' ) );
if( !cau_check_if_exists( 'dbupdateemails' ) ) $wpdb->insert( $table_name, array( 'name' => 'dbupdateemails', 'onoroff' => '' ) );
// Advanced
if( !cau_check_if_exists( 'allow_administrator' ) ) $wpdb->insert( $table_name, array( 'name' => 'allow_administrator', 'onoroff' => 'on' ) ); // Advanced
if( !cau_check_if_exists( 'allow_editor' ) ) $wpdb->insert( $table_name, array( 'name' => 'allow_editor', 'onoroff' => '' ) ); if( !cau_check_if_exists( 'allow_administrator' ) ) $wpdb->insert( $table_name, array( 'name' => 'allow_administrator', 'onoroff' => 'on' ) );
if( !cau_check_if_exists( 'allow_author' ) ) $wpdb->insert( $table_name, array( 'name' => 'allow_author', 'onoroff' => '' ) ); if( !cau_check_if_exists( 'allow_editor' ) ) $wpdb->insert( $table_name, array( 'name' => 'allow_editor', 'onoroff' => '' ) );
if( !cau_check_if_exists( 'ignore_seo' ) ) $wpdb->insert( $table_name, array( 'name' => 'ignore_seo', 'onoroff' => '' ) ); if( !cau_check_if_exists( 'allow_author' ) ) $wpdb->insert( $table_name, array( 'name' => 'allow_author', 'onoroff' => '' ) );
if( !cau_check_if_exists( 'ignore_cron' ) ) $wpdb->insert( $table_name, array( 'name' => 'ignore_cron', 'onoroff' => '' ) ); if( !cau_check_if_exists( 'ignore_seo' ) ) $wpdb->insert( $table_name, array( 'name' => 'ignore_seo', 'onoroff' => '' ) );
if( !cau_check_if_exists( 'advanced_info_emails' ) ) $wpdb->insert( $table_name, array( 'name' => 'advanced_info_emails', 'onoroff' => '' ) ); if( !cau_check_if_exists( 'ignore_cron' ) ) $wpdb->insert( $table_name, array( 'name' => 'ignore_cron', 'onoroff' => '' ) );
if( !cau_check_if_exists( 'update_delay' ) ) $wpdb->insert( $table_name, array( 'name' => 'update_delay', 'onoroff' => '' ) ); if( !cau_check_if_exists( 'advanced_info_emails' ) ) $wpdb->insert( $table_name, array( 'name' => 'advanced_info_emails', 'onoroff' => '' ) );
if( !cau_check_if_exists( 'update_delay_days' ) ) $wpdb->insert( $table_name, array( 'name' => 'update_delay_days', 'onoroff' => '' ) ); if( !cau_check_if_exists( 'update_delay' ) ) $wpdb->insert( $table_name, array( 'name' => 'update_delay', 'onoroff' => '' ) );
if( !cau_check_if_exists( 'update_delay_days' ) ) $wpdb->insert( $table_name, array( 'name' => 'update_delay_days', 'onoroff' => '' ) );
}
register_activation_hook( __FILE__, 'cau_install' ); }
register_activation_hook( __FILE__, 'cau_install' );
// Clear everything on deactivation
function cau_remove() { // Clear everything on deactivation
function cau_remove() {
// Delete tables
global $wpdb; // Delete tables
$autoupdates = $wpdb->prefix."auto_updates"; global $wpdb;
$updateLog = $wpdb->prefix."update_log"; $autoupdates = $wpdb->prefix."auto_updates";
$wpdb->query( "DROP TABLE IF EXISTS $autoupdates" ); $updateLog = $wpdb->prefix."update_log";
$wpdb->query( "DROP TABLE IF EXISTS $updateLog" ); $wpdb->query( "DROP TABLE IF EXISTS $autoupdates" );
$wpdb->query( "DROP TABLE IF EXISTS $updateLog" );
// Clear schedules
wp_clear_scheduled_hook( 'cau_set_schedule_mail' ); // Clear schedules
wp_clear_scheduled_hook( 'cau_custom_hooks_plugins' ); wp_clear_scheduled_hook( 'cau_set_schedule_mail' );
wp_clear_scheduled_hook( 'cau_custom_hooks_themes' ); wp_clear_scheduled_hook( 'cau_custom_hooks_plugins' );
wp_clear_scheduled_hook( 'cau_log_updater' ); wp_clear_scheduled_hook( 'cau_custom_hooks_themes' );
wp_clear_scheduled_hook( 'cau_log_updater' );
// Restore WordPress default update functionality
add_filter( 'plugins_auto_update_enabled', '__return_true' ); // Restore WordPress default update functionality
add_filter( 'themes_auto_update_enabled', '__return_true' ); add_filter( 'plugins_auto_update_enabled', '__return_true' );
add_filter( 'auto_plugin_update_send_email', '__return_true' ); add_filter( 'themes_auto_update_enabled', '__return_true' );
add_filter( 'auto_theme_update_send_email', '__return_true' ); add_filter( 'auto_plugin_update_send_email', '__return_true' );
} add_filter( 'auto_theme_update_send_email', '__return_true' );
register_deactivation_hook( __FILE__, 'cau_remove' ); }
register_deactivation_hook( __FILE__, 'cau_remove' );
// Update
function cau_update_db_check() { // Update
function cau_update_db_check() {
$cau_db_version = cau_db_version();
$cau_db_version = cau_db_version();
if ( get_site_option( 'cau_db_version' ) != $cau_db_version ) {
if ( get_site_option( 'cau_db_version' ) != $cau_db_version ) {
cau_database_creation();
cau_database_creation();
// In 3.7.2 we've added $wpdb->get_charset_collate
if( get_site_option( 'cau_db_version' ) < '3.7.2' ) { // In 3.7.2 we've added $wpdb->get_charset_collate
if( get_site_option( 'cau_db_version' ) < '3.7.2' ) {
global $wpdb;
$autoupdates = $wpdb->prefix."auto_updates"; global $wpdb;
$updateLog = $wpdb->prefix."update_log"; $autoupdates = $wpdb->prefix."auto_updates";
$db_charset = constant( 'DB_CHARSET' ); $updateLog = $wpdb->prefix."update_log";
$wpdb->query( "ALTER TABLE $autoupdates CONVERT TO CHARACTER SET $db_charset" ); $db_charset = constant( 'DB_CHARSET' );
$wpdb->query( "ALTER TABLE $updateLog CONVERT TO CHARACTER SET $db_charset" ); $wpdb->query( "ALTER TABLE $autoupdates CONVERT TO CHARACTER SET $db_charset" );
$wpdb->query( "ALTER TABLE $updateLog CONVERT TO CHARACTER SET $db_charset" );
}
}
update_option( "cau_db_version", $cau_db_version );
} update_option( "cau_db_version", $cau_db_version );
}
}
add_action( 'upgrader_process_complete', 'cau_update_db_check' ); }
add_action( 'upgrader_process_complete', 'cau_update_db_check' );
// Manual update
function cau_manual_update() { // Manual update
cau_update_db_check(); function cau_manual_update() {
} cau_update_db_check();
}
// Load custom functions
require_once( plugin_dir_path( __FILE__ ) . 'cau_functions.php' ); // Load custom functions
require_once( plugin_dir_path( __FILE__ ) . 'cau_functions.php' );
// Add plugin to menu
function register_cau_menu_page() { // Add plugin to menu
if( cau_allowed_user_rights() ) add_submenu_page( cau_menloc() , __( 'Auto Updater', 'companion-auto-update' ), __( 'Auto Updater', 'companion-auto-update' ), 'manage_options', 'cau-settings', 'cau_frontend' ); function register_cau_menu_page() {
} if( cau_allowed_user_rights() ) add_submenu_page( cau_menloc() , __( 'Auto Updater', 'companion-auto-update' ), __( 'Auto Updater', 'companion-auto-update' ), 'manage_options', 'cau-settings', 'cau_frontend' );
add_action( 'admin_menu', 'register_cau_menu_page' ); }
add_action( 'admin_menu', 'register_cau_menu_page' );
// Settings page
function cau_frontend() { ?> // Settings page
function cau_frontend() { ?>
<div class='wrap cau_content_wrap cau_content'>
<div class='wrap cau_content_wrap cau_content'>
<h1 class="wp-heading-inline"><?php _e( 'Companion Auto Update', 'companion-auto-update' ); ?></h1>
<h1 class="wp-heading-inline"><?php _e( 'Companion Auto Update', 'companion-auto-update' ); ?></h1>
<hr class="wp-header-end">
<hr class="wp-header-end">
<?php
<?php
// Make sure the correct timezone is used
date_default_timezone_set( cau_get_proper_timezone() ); // Make sure the correct timezone is used
date_default_timezone_set( cau_get_proper_timezone() );
// Allow only access to these pages
$allowedPages = array( // Allow only access to these pages
'dashboard' => __( 'Dashboard' ), $allowedPages = array(
'pluginlist' => __( 'Update filter', 'companion-auto-update' ), 'dashboard' => __( 'Dashboard' ),
'log' => __( 'Update log', 'companion-auto-update' ), 'pluginlist' => __( 'Update filter', 'companion-auto-update' ),
'status' => __( 'Status', 'companion-auto-update' ), 'log' => __( 'Update log', 'companion-auto-update' ),
); 'status' => __( 'Status', 'companion-auto-update' ),
);
// Show subtabs
echo "<h2 class='nav-tab-wrapper wp-clearfix'>"; // Show subtabs
foreach ( $allowedPages as $page => $title ) { echo "<h2 class='nav-tab-wrapper wp-clearfix'>";
echo "<a href='".cau_url( $page )."' id='tab-".$page."' class='nav-tab "._active_tab( $page )."'>".$title; foreach ( $allowedPages as $page => $title ) {
if( $page == 'status' ) { echo "<a href='".cau_url( $page )."' id='tab-".$page."' class='nav-tab "._active_tab( $page )."'>".$title;
if( cau_pluginHasIssues() ) { if( $page == 'status' ) {
echo "<span class='cau_melding level-".cau_pluginIssueLevels()."'></span>"; if( cau_pluginHasIssues() ) {
} else { echo "<span class='cau_melding level-".cau_pluginIssueLevels()."'></span>";
echo "<span class='cau_melding level-okay'></span>"; } else {
} echo "<span class='cau_melding level-okay'></span>";
} }
echo "</a>"; }
} echo "</a>";
echo "</h2>"; }
echo "</h2>";
// Show page content
if( !isset( $_GET['tab'] ) ) { // Show page content
$requestedPage = 'dashboard'; if( !isset( $_GET['tab'] ) ) {
echo "<script>jQuery('#tab-dashboard').addClass('nav-tab-active');</script>"; // Set active tab class $requestedPage = 'dashboard';
} else { echo "<script>jQuery('#tab-dashboard').addClass('nav-tab-active');</script>"; // Set active tab class
$requestedPage = sanitize_key( $_GET['tab'] ); } else {
} $requestedPage = sanitize_key( $_GET['tab'] );
}
if( array_key_exists( $requestedPage, $allowedPages ) ) {
require_once( plugin_dir_path( __FILE__ ) . 'admin/'.$requestedPage.'.php' ); if( array_key_exists( $requestedPage, $allowedPages ) ) {
} else { require_once( plugin_dir_path( __FILE__ ) . 'admin/'.$requestedPage.'.php' );
wp_die( 'You\'re not allowed to view <strong>'.$requestedPage.'</strong>.' ); } else {
} wp_die( 'You\'re not allowed to view <strong>'.$requestedPage.'</strong>.' );
}
?>
?>
</div>
</div>
<?php }
<?php }
// Add a widget to the dashboard.
function cau_add_widget() { // Add a widget to the dashboard.
if ( cau_allowed_user_rights() ) wp_add_dashboard_widget( 'cau-update-log', __('Update log', 'companion-auto-update'), 'cau_widget' ); function cau_add_widget() {
} if ( cau_allowed_user_rights() ) wp_add_dashboard_widget( 'cau-update-log', __('Update log', 'companion-auto-update'), 'cau_widget' );
add_action( 'wp_dashboard_setup', 'cau_add_widget' ); }
add_action( 'wp_dashboard_setup', 'cau_add_widget' );
function cau_widget() {
function cau_widget() {
echo '<style>table.autoupdatewidget { border: 0px solid transparent; border-bottom: 1px solid #EEEEEE; margin: 0 -12px; width: calc(100% + 24px); } table.autoupdatewidget tr td { border-top: 1px solid #EEEEEE; padding: 9px 12px 5px 12px; background: #FAFAFA; } .cau_divide { display: inline-block; color: #E7E0DF; padding: 0 2px; } </style>';
echo '<p>'.__('Below are the last 7 updates ran on this site. Includes plugins and themes, both automatically updated and manually updated.', 'companion-auto-update').'</p>'; echo '<style>table.autoupdatewidget { border: 0px solid transparent; border-bottom: 1px solid #EEEEEE; margin: 0 -12px; width: calc(100% + 24px); } table.autoupdatewidget tr td { border-top: 1px solid #EEEEEE; padding: 9px 12px 5px 12px; background: #FAFAFA; } .cau_divide { display: inline-block; color: #E7E0DF; padding: 0 2px; } </style>';
cau_fetch_log( '7' ); echo '<p>'.__('Below are the last 7 updates ran on this site. Includes plugins and themes, both automatically updated and manually updated.', 'companion-auto-update').'</p>';
echo '<p> cau_fetch_log( '7' );
<a href="'.cau_url( 'log' ).'">'.__('View full changelog', 'companion-auto-update').'</a> echo '<p>
<span class="cau_divide">|</span> <a href="'.cau_url( 'log' ).'">'.__('View full changelog', 'companion-auto-update').'</a>
<a href="'.cau_url( 'dashboard' ).'">'.__( 'Settings' ).'</a> <span class="cau_divide">|</span>
</p>'; <a href="'.cau_url( 'dashboard' ).'">'.__( 'Settings' ).'</a>
</p>';
}
}
// Load admin styles
function load_cau_global_styles( $hook ) { // Load admin styles
function load_cau_global_styles( $hook ) {
// Plugin scripts
wp_enqueue_style( 'cau_admin_styles', plugins_url( 'backend/style.css' , __FILE__ ) ); // Plugin scripts
wp_enqueue_style( 'cau_admin_styles', plugins_url( 'backend/style.css' , __FILE__ ) );
// Check for issues
wp_enqueue_style( 'cau_warning_styles', plugins_url( 'backend/warningbar.css' , __FILE__ ) ); // Check for issues
wp_enqueue_style( 'cau_warning_styles', plugins_url( 'backend/warningbar.css' , __FILE__ ) );
}
add_action( 'admin_enqueue_scripts', 'load_cau_global_styles', 99 ); }
add_action( 'admin_enqueue_scripts', 'load_cau_global_styles', 99 );
// Load admin styles
function load_cau_page_styles( $hook ) { // Load admin styles
function load_cau_page_styles( $hook ) {
// Only load on plugins' pages
if( $hook != 'tools_page_cau-settings' && $hook != 'index_page_cau-settings' ) return; // Only load on plugins' pages
if( $hook != 'tools_page_cau-settings' && $hook != 'index_page_cau-settings' ) return;
// WordPress scripts we need
wp_enqueue_style( 'thickbox' ); // WordPress scripts we need
wp_enqueue_script( 'thickbox' ); wp_enqueue_style( 'thickbox' );
wp_enqueue_script( 'plugin-install' ); wp_enqueue_script( 'thickbox' );
wp_enqueue_script( 'plugin-install' );
}
add_action( 'admin_enqueue_scripts', 'load_cau_page_styles', 100 ); }
add_action( 'admin_enqueue_scripts', 'load_cau_page_styles', 100 );
// Send e-mails
require_once( plugin_dir_path( __FILE__ ) . 'cau_emails.php' ); // Send e-mails
require_once( plugin_dir_path( __FILE__ ) . 'cau_emails.php' );
// Add settings link on plugin page
function cau_settings_link( $links ) { // Add settings link on plugin page
function cau_settings_link( $links ) {
$settings_link = '<a href="'.cau_url( 'dashboard' ).'">'.__( 'Settings' ).'</a>';
$settings_link2 = '<a href="https://translate.wordpress.org/projects/wp-plugins/companion-auto-update">'.__( 'Help us translate', 'companion-auto-update' ).'</a>'; $settings_link = '<a href="'.cau_url( 'dashboard' ).'">'.__( 'Settings' ).'</a>';
$settings_link3 = '<a href="'.cau_donateUrl().'">'.__( 'Donate to help development', 'companion-auto-update' ).'</a>'; $settings_link2 = '<a href="https://translate.wordpress.org/projects/wp-plugins/companion-auto-update">'.__( 'Help us translate', 'companion-auto-update' ).'</a>';
$settings_link3 = '<a href="'.cau_donateUrl().'">'.__( 'Donate to help development', 'companion-auto-update' ).'</a>';
array_unshift( $links, $settings_link2 );
array_unshift( $links, $settings_link3 ); array_unshift( $links, $settings_link2 );
if( cau_allowed_user_rights() ) array_unshift( $links, $settings_link ); array_unshift( $links, $settings_link3 );
if( cau_allowed_user_rights() ) array_unshift( $links, $settings_link );
return $links;
return $links;
}
$plugin = plugin_basename(__FILE__); }
add_filter( "plugin_action_links_$plugin", "cau_settings_link" ); $plugin = plugin_basename(__FILE__);
add_filter( "plugin_action_links_$plugin", "cau_settings_link" );
// Auto Update Class
class CAU_auto_update { // Auto Update Class
class CAU_auto_update {
public function __construct() {
public function __construct() {
// Enable Update filters
add_action( 'plugins_loaded', array( &$this, 'CAU_auto_update_filters' ), 1 ); // Enable Update filters
add_action( 'plugins_loaded', array( &$this, 'CAU_auto_update_filters' ), 1 );
}
}
public function CAU_auto_update_filters() {
public function CAU_auto_update_filters() {
global $wpdb;
$table_name = $wpdb->prefix . "auto_updates"; global $wpdb;
$table_name = $wpdb->prefix . "auto_updates";
// Disable WP emails
add_filter( 'auto_plugin_update_send_email', '__return_false' ); // Plugin updates // Disable WP emails
add_filter( 'auto_theme_update_send_email', '__return_false' ); // Theme updates add_filter( 'auto_plugin_update_send_email', '__return_false' ); // Plugin updates
add_filter( 'auto_theme_update_send_email', '__return_false' ); // Theme updates
// Enable for major updates
$configs = $wpdb->get_results( "SELECT * FROM {$table_name} WHERE name = 'major'"); // Enable for major updates
foreach ( $configs as $config ) { $configs = $wpdb->get_results( "SELECT * FROM {$table_name} WHERE name = 'major'");
if( $config->onoroff == 'on' ) add_filter( 'allow_major_auto_core_updates', '__return_true', 1 ); // Turn on foreach ( $configs as $config ) {
else add_filter( 'allow_major_auto_core_updates', '__return_false', 1 ); // Turn off if( $config->onoroff == 'on' ) add_filter( 'allow_major_auto_core_updates', '__return_true', 1 ); // Turn on
} else add_filter( 'allow_major_auto_core_updates', '__return_false', 1 ); // Turn off
}
// Enable for minor updates
$configs = $wpdb->get_results( "SELECT * FROM {$table_name} WHERE name = 'minor'"); // Enable for minor updates
foreach ( $configs as $config ) { $configs = $wpdb->get_results( "SELECT * FROM {$table_name} WHERE name = 'minor'");
if( $config->onoroff == 'on' ) add_filter( 'allow_minor_auto_core_updates', '__return_true', 1 ); // Turn on foreach ( $configs as $config ) {
else add_filter( 'allow_minor_auto_core_updates', '__return_false', 1 ); // Turn off if( $config->onoroff == 'on' ) add_filter( 'allow_minor_auto_core_updates', '__return_true', 1 ); // Turn on
} else add_filter( 'allow_minor_auto_core_updates', '__return_false', 1 ); // Turn off
}
// Enable for plugins
$configs = $wpdb->get_results( "SELECT * FROM {$table_name} WHERE name = 'plugins'"); // Enable for plugins
foreach ( $configs as $config ) { $configs = $wpdb->get_results( "SELECT * FROM {$table_name} WHERE name = 'plugins'");
if( $config->onoroff == 'on' ) add_filter( 'auto_update_plugin', 'cau_dontUpdatePlugins', 10, 2 ); // Turn on foreach ( $configs as $config ) {
else add_filter( 'auto_update_plugin', '__return_false', 1 ); // Turn off if( $config->onoroff == 'on' ) add_filter( 'auto_update_plugin', 'cau_dontUpdatePlugins', 10, 2 ); // Turn on
} else add_filter( 'auto_update_plugin', '__return_false', 1 ); // Turn off
}
// Enable for themes
$configs = $wpdb->get_results( "SELECT * FROM {$table_name} WHERE name = 'themes'"); // Enable for themes
foreach ( $configs as $config ) { $configs = $wpdb->get_results( "SELECT * FROM {$table_name} WHERE name = 'themes'");
if( $config->onoroff == 'on' ) add_filter( 'auto_update_theme', '__return_true' ); // Turn on foreach ( $configs as $config ) {
else add_filter( 'auto_update_theme', '__return_false', 1 ); // Turn off if( $config->onoroff == 'on' ) add_filter( 'auto_update_theme', '__return_true' ); // Turn on
} else add_filter( 'auto_update_theme', '__return_false', 1 ); // Turn off
}
// Enable for translation files
$configs = $wpdb->get_results( "SELECT * FROM {$table_name} WHERE name = 'translations'"); // Enable for translation files
foreach ( $configs as $config ) { $configs = $wpdb->get_results( "SELECT * FROM {$table_name} WHERE name = 'translations'");
if( $config->onoroff == 'on' ) add_filter( 'auto_update_translation', '__return_true', 1 ); // Turn on foreach ( $configs as $config ) {
else add_filter( 'auto_update_translation', '__return_false', 1 ); // Turn off if( $config->onoroff == 'on' ) add_filter( 'auto_update_translation', '__return_true', 1 ); // Turn on
} else add_filter( 'auto_update_translation', '__return_false', 1 ); // Turn off
}
// WP Email Config
$configs = $wpdb->get_results( "SELECT * FROM {$table_name} WHERE name = 'wpemails'"); // WP Email Config
foreach ( $configs as $config ) { $configs = $wpdb->get_results( "SELECT * FROM {$table_name} WHERE name = 'wpemails'");
if( $config->onoroff == 'on' ) { foreach ( $configs as $config ) {
add_filter( 'auto_core_update_send_email', '__return_true' ); // Core updates if( $config->onoroff == 'on' ) {
} else { add_filter( 'auto_core_update_send_email', '__return_true' ); // Core updates
add_filter( 'auto_core_update_send_email', '__return_false' ); // Core updates } else {
} add_filter( 'auto_core_update_send_email', '__return_false' ); // Core updates
} }
}
}
}
}
new CAU_auto_update(); }
new CAU_auto_update();
// Check for issues
function cau_checkForIssues( $admin_bar ) { // Check for issues
function cau_checkForIssues( $admin_bar ) {
if( cau_pluginHasIssues() && is_admin() ) {
if( cau_pluginHasIssues() && is_admin() ) {
if( cau_pluginIssueLevels() == 'high' ) {
$cauWaningBarTitle = __( 'Companion Auto Update ran into a critical error. View the status log for more info.', 'companion-auto-update' ); if( cau_pluginIssueLevels() == 'high' ) {
$cauWaningBarTitle = __( 'Companion Auto Update ran into a critical error. View the status log for more info.', 'companion-auto-update' );
$admin_bar->add_menu( array(
'id' => 'cau-has-issues', $admin_bar->add_menu( array(
'title' => '<span class="ab-icon"></span><span class="cau-level-'.cau_pluginIssueLevels().'">'.cau_pluginIssueCount().'</span>', 'id' => 'cau-has-issues',
'href' => cau_url( 'status' ), 'title' => '<span class="ab-icon"></span><span class="cau-level-'.cau_pluginIssueLevels().'">'.cau_pluginIssueCount().'</span>',
'meta' => array( 'href' => cau_url( 'status' ),
'target' => '_self', 'meta' => array(
'title' => $cauWaningBarTitle, 'target' => '_self',
), 'title' => $cauWaningBarTitle,
)); ),
));
}
}
}
}
}
add_action( 'admin_bar_menu', 'cau_checkForIssues', 150 ); }
add_action( 'admin_bar_menu', 'cau_checkForIssues', 150 );

View File

@ -1,2 +1,2 @@
<?php <?php
# Silence is golden. # Silence is golden.

View File

@ -3,9 +3,9 @@ Contributors: Papin, qweb
Donate link: https://www.paypal.me/dakel/10/ Donate link: https://www.paypal.me/dakel/10/
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 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
Requires at least: 3.6.0 Requires at least: 3.6.0
Tested up to: 5.6 Tested up to: 5.7
Requires PHP: 5.1 Requires PHP: 5.1
Stable tag: 3.8.0 Stable tag: 3.8.2
License: GPLv2 or later License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html License URI: http://www.gnu.org/licenses/gpl-2.0.html
@ -81,7 +81,14 @@ So obviously, some of you wondered what the difference would be between the defa
== Changelog == == Changelog ==
= 3.8.0 (January 14, 2020) = = 3.8.2 (July 1, 2021) =
* Fix: Error: Call to undefined function get_plugin_updates()
= 3.8.1 (June 4, 2021) =
* New: Be notified when we need your help updating to a new database version [Feature Request](https://wordpress.org/support/topic/feature-request-839/)
* Tweak: Made some under the hood performance improvements
= 3.8.0 (January 14, 2021) =
* New: Better handling of plugins with an unknown WP version * New: Better handling of plugins with an unknown WP version
* New: More intervals for notifications * New: More intervals for notifications
* Fix: Call to undefined function errors * Fix: Call to undefined function errors