updated plugin Companion Auto Update version 3.8.5

This commit is contained in:
2022-03-21 13:35:00 +00:00
committed by Gitium
parent 350836f064
commit 2bfae7880a
23 changed files with 3693 additions and 3693 deletions

View File

@ -1,9 +1,10 @@
<?php
/*
* Plugin Name: 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.
* Version: 3.8.3
* Version: 3.8.5
* Author: Papin Schipper
* Author URI: http://codeermeneer.nl/
* Contributors: papin
@ -26,6 +27,7 @@ add_action( 'init', 'cau_init' );
// Set up the database and required schedules
function cau_install( $network_wide ) {
if ( is_multisite() && $network_wide ) {
global $wpdb;
$blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
@ -37,12 +39,14 @@ function cau_install( $network_wide ) {
} else {
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_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_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
}
add_action( 'cau_set_schedule_mail', 'cau_check_updates_mail' );
add_action( 'cau_outdated_notifier', 'cau_outdated_notifier_mail' );
add_action( 'wp_update_plugins', 'cau_run_custom_hooks_p' );
@ -62,6 +66,7 @@ function cau_pluginActivateWelcome() {
}
register_activation_hook(__FILE__, 'cau_pluginActivateWelcome');
// Redirect to welcome screen on activation of plugin
function cau_pluginRedirectWelcomeScreen() {
if ( get_option( 'cau_redirectToWelcomeScreen', false ) ) {
delete_option( 'cau_redirectToWelcomeScreen' );
@ -81,35 +86,22 @@ function cau_donateUrl() {
function cau_db_version() {
return '3.8.3';
}
function cau_database_creation() {
global $wpdb;
// Plugin db info
$cau_db_version = cau_db_version();
$autoupdates = $wpdb->prefix."auto_updates";
$updateLog = $wpdb->prefix."update_log";
$cau_db_version = cau_db_version();
$autoupdates = $wpdb->prefix."auto_updates";
$updateLog = $wpdb->prefix."update_log";
// WordPress db info
$charset_collate = $wpdb->get_charset_collate();
$charset_collate = $wpdb->get_charset_collate();
// DB table creation queries
$sql = "CREATE TABLE $autoupdates (
id INT(9) NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
onoroff TEXT NOT NULL,
UNIQUE KEY id (id)
) $charset_collate;";
$sql2 = "CREATE TABLE $updateLog (
id INT(9) NOT NULL AUTO_INCREMENT,
slug VARCHAR(255) NOT NULL,
oldVersion VARCHAR(10) NOT NULL,
newVersion VARCHAR(10) NOT NULL,
method VARCHAR(10) NOT NULL,
put_on_hold VARCHAR(100) DEFAULT '0',
UNIQUE KEY id (id)
) $charset_collate;";
$sql = "CREATE TABLE $autoupdates ( id INT(9) NOT NULL AUTO_INCREMENT, name VARCHAR(255) NOT NULL, onoroff TEXT NOT NULL, UNIQUE KEY id (id) ) $charset_collate;";
$sql2 = "CREATE TABLE $updateLog ( id INT(9) NOT NULL AUTO_INCREMENT, slug VARCHAR(255) NOT NULL, oldVersion VARCHAR(10) NOT NULL, newVersion VARCHAR(10) NOT NULL, method VARCHAR(10) NOT NULL, put_on_hold VARCHAR(100) DEFAULT '0', UNIQUE KEY id (id) ) $charset_collate;";
// Create DB tables
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
@ -121,23 +113,18 @@ function cau_database_creation() {
// Insert data
cau_install_data();
}
// Check if database table exists before creating
function cau_check_if_exists( $whattocheck, $id = 'name', $db_table = 'auto_updates' ) {
global $wpdb;
$table_name = $wpdb->prefix.$db_table;
$rows = $wpdb->get_col( "SELECT COUNT(*) as num_rows FROM {$table_name} WHERE {$id} = '{$whattocheck}'" );
$check = $rows[0];
$rows = $wpdb->get_col( "SELECT COUNT(*) as num_rows FROM {$table_name} WHERE {$id} = '{$whattocheck}'" );
$check = $rows[0];
if( $check > 0 ) {
return true;
} else {
return false;
}
return ( $check > 0 ) ? true : false;
}
@ -145,6 +132,7 @@ function cau_check_if_exists( $whattocheck, $id = 'name', $db_table = 'auto_upda
function cau_install_data() {
global $wpdb;
$table_name = $wpdb->prefix . "auto_updates";
$toemail = get_option('admin_email');
@ -200,11 +188,12 @@ function cau_remove() {
wp_clear_scheduled_hook( 'cau_custom_hooks_themes' );
wp_clear_scheduled_hook( 'cau_log_updater' );
// Restore WordPress default update functionality
// Restore WordPress 5.5 default update functionality
add_filter( 'plugins_auto_update_enabled', '__return_true' );
add_filter( 'themes_auto_update_enabled', '__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' );
@ -226,13 +215,13 @@ function cau_update_db_check() {
$db_charset = constant( '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 );
}
}
add_action( 'upgrader_process_complete', 'cau_update_db_check' );
// Manual update
@ -250,19 +239,15 @@ function register_cau_menu_page() {
add_action( 'admin_menu', 'register_cau_menu_page' );
// Settings page
function cau_frontend() { ?>
<div class='wrap cau_content_wrap cau_content'>
function cau_frontend() {
<h1 class="wp-heading-inline"><?php _e( 'Companion Auto Update', 'companion-auto-update' ); ?></h1>
<hr class="wp-header-end">
<?php
echo "<div class='wrap cau_content_wrap cau_content'>
<h1 class='wp-heading-inline'>".__( 'Companion Auto Update', 'companion-auto-update' )."</h1>
<hr class='wp-header-end'>";
// Make sure the correct timezone is used
date_default_timezone_set( cau_get_proper_timezone() );
// Allow only access to these pages
$allowedPages = array(
'dashboard' => __( 'Dashboard' ),
@ -273,17 +258,13 @@ function cau_frontend() { ?>
// Show subtabs
echo "<h2 class='nav-tab-wrapper wp-clearfix'>";
foreach ( $allowedPages as $page => $title ) {
echo "<a href='".cau_url( $page )."' id='tab-".$page."' class='nav-tab "._active_tab( $page )."'>".$title;
if( $page == 'status' ) {
if( cau_pluginHasIssues() ) {
echo "<span class='cau_melding level-".cau_pluginIssueLevels()."'></span>";
} else {
echo "<span class='cau_melding level-okay'></span>";
}
}
if( $page == 'status' ) echo cau_pluginHasIssues() ? "<span class='cau_melding level-".cau_pluginIssueLevels()."'></span>" : "<span class='cau_melding level-okay'></span>"; // Show status icon
echo "</a>";
}
echo "</h2>";
// Show page content
@ -300,11 +281,9 @@ function cau_frontend() { ?>
wp_die( 'You\'re not allowed to view <strong>'.$requestedPage.'</strong>.' );
}
?>
echo '</div>';
</div>
<?php }
}
// Add a widget to the dashboard.
function cau_add_widget() {
@ -312,28 +291,18 @@ function cau_add_widget() {
}
add_action( 'wp_dashboard_setup', 'cau_add_widget' );
// Widget content
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>';
cau_fetch_log( '7' );
echo '<p>
<a href="'.cau_url( 'log' ).'">'.__('View full changelog', 'companion-auto-update').'</a>
<span class="cau_divide">|</span>
<a href="'.cau_url( 'dashboard' ).'">'.__( 'Settings' ).'</a>
</p>';
echo '<p><a href="'.cau_url( 'log' ).'">'.__( 'View full changelog', 'companion-auto-update' ).'</a> <span class="cau_divide">|</span> <a href="'.cau_url( 'dashboard' ).'">'.__( 'Settings' ).'</a></p>';
}
// Load admin styles
function load_cau_global_styles( $hook ) {
// 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__ ) );
wp_enqueue_style( 'cau_admin_styles', plugins_url( 'backend/style.css' , __FILE__ ) ); // Plugin scripts
wp_enqueue_style( 'cau_warning_styles', plugins_url( 'backend/warningbar.css' , __FILE__ ) ); // Check for issues
}
add_action( 'admin_enqueue_scripts', 'load_cau_global_styles', 99 );
@ -347,7 +316,6 @@ function load_cau_page_styles( $hook ) {
wp_enqueue_style( 'thickbox' );
wp_enqueue_script( 'thickbox' );
wp_enqueue_script( 'plugin-install' );
}
add_action( 'admin_enqueue_scripts', 'load_cau_page_styles', 100 );
@ -360,7 +328,7 @@ 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_link3 = '<a href="'.cau_donateUrl().'">'.__( 'Donate to help development', 'companion-auto-update' ).'</a>';
array_unshift( $links, $settings_link2 );
array_unshift( $links, $settings_link3 );
if( cau_allowed_user_rights() ) array_unshift( $links, $settings_link );
@ -374,11 +342,9 @@ add_filter( "plugin_action_links_$plugin", "cau_settings_link" );
// Auto Update Class
class CAU_auto_update {
// Enable Update filters
public function __construct() {
// Enable Update filters
add_action( 'plugins_loaded', array( &$this, 'CAU_auto_update_filters' ), 1 );
}
public function CAU_auto_update_filters() {
@ -428,13 +394,9 @@ class CAU_auto_update {
// WP Email Config
$configs = $wpdb->get_results( "SELECT * FROM {$table_name} WHERE name = 'wpemails'");
foreach ( $configs as $config ) {
if( $config->onoroff == 'on' ) {
add_filter( 'auto_core_update_send_email', '__return_true' ); // Core updates
} else {
add_filter( 'auto_core_update_send_email', '__return_false' ); // Core updates
}
if( $config->onoroff == 'on' ) add_filter( 'auto_core_update_send_email', '__return_true', 1 ); // Turn on
else add_filter( 'auto_core_update_send_email', '__return_false', 1 ); // Turn off
}
}
@ -443,25 +405,16 @@ new CAU_auto_update();
// Check for issues
function cau_checkForIssues( $admin_bar ) {
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' );
$admin_bar->add_menu( array(
'id' => 'cau-has-issues',
'title' => '<span class="ab-icon"></span><span class="cau-level-'.cau_pluginIssueLevels().'">'.cau_pluginIssueCount().'</span>',
'href' => cau_url( 'status' ),
'meta' => array(
'target' => '_self',
'title' => $cauWaningBarTitle,
),
));
}
if( cau_pluginHasIssues() && is_admin() && cau_pluginIssueLevels() == 'high' ) {
$admin_bar->add_menu( array(
'id' => 'cau-has-issues',
'title' => '<span class="ab-icon"></span><span class="cau-level-'.cau_pluginIssueLevels().'">'.cau_pluginIssueCount().'</span>',
'href' => cau_url( 'status' ),
'meta' => array(
'target' => '_self',
'title' => __( 'Companion Auto Update ran into a critical error. View the status log for more info.', 'companion-auto-update' ),
),
));
}
}
add_action( 'admin_bar_menu', 'cau_checkForIssues', 150 );
add_action( 'admin_bar_menu', 'cau_checkForIssues', 150 );