updated plugin Companion Auto Update version 3.8.0

This commit is contained in:
2021-01-17 21:29:01 +00:00
committed by Gitium
parent 8a03c72181
commit 93745b9ce4
7 changed files with 264 additions and 224 deletions

View File

@ -173,6 +173,11 @@ function cau_incorrectDatabaseVersion() {
// Run custom hooks on plugin update
function cau_run_custom_hooks_p() {
// Check if function exists
if ( ! function_exists( 'get_plugins' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
// Create array
$allDates = array();
@ -551,7 +556,12 @@ function cau_fetch_log( $limit, $format = 'simple' ) {
$dateFormat = get_option( 'date_format' );
// PLUGINS
if( $plugins ) {
if( $plugins ) {
// Check if function exists
if ( ! function_exists( 'get_plugins' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
// Where to look for plugins
$plugdir = plugin_dir_path( __DIR__ );
@ -1010,7 +1020,12 @@ function cau_plugin_info( $slug, $what ) {
// Get list of outdated plugins
function cau_list_outdated() {
$outdatedList = array();
$outdatedList = array();
// Check if function exists
if ( ! function_exists( 'get_plugins' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
foreach ( get_plugins() as $key => $value) {
@ -1052,6 +1067,11 @@ function cau_version_compare( $ver1, $ver2, $operator = null ) {
// Get plugin information of currently installed plugins
function cau_active_plugin_info( $slug, $what ) {
// Check if function exists
if ( ! function_exists( 'get_plugins' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$allPlugins = get_plugins();
foreach ($allPlugins as $key => $value) {
@ -1081,19 +1101,19 @@ function cau_addMoreIntervals( $schedules ) {
// Add a weekly interval.
$schedules['weekly'] = array(
'interval' => 604800,
'display' => __( 'Once Weekly', 'companion-auto-update' ),
'display' => __( 'Every week', 'companion-auto-update' ),
);
// Add a twice montly interval.
$schedules['twice_monthly'] = array(
'interval' => 1317600,
'display' => __( 'Twice a month', 'companion-auto-update' ),
'interval' => 1209600,
'display' => __( 'Every 2 weeks', 'companion-auto-update' ),
);
// Add a montly interval.
$schedules['once_monthly'] = array(
'interval' => 2635200,
'display' => __( 'Once a month', 'companion-auto-update' ),
'interval' => 2419200,
'display' => __( 'Every 4 weeks', 'companion-auto-update' ),
);
return $schedules;
@ -1118,19 +1138,48 @@ function cau_wp_get_schedules() {
// Do a bunch of checks to format them the right way
foreach ( $value as $display => $interval ) {
if( $display == 'display' ) {
$intervalNames[$counter] = $interval; // Add the display name (i.e. "Once a month" or "Once Daily")
$counter++; // Make sure the next interval gets a new "key" value
} else {
if( $interval == '86400' ) $key = 'daily'; // Force the daily interval to be called daily, requires by a bunch of handles of this plugin
if( $display == 'interval' ) {
if( $interval == '86400' ) $key = 'daily'; // Force the daily interval to be called daily, required by a bunch of handles of this plugin
$intervalTimes[$counter] = $key; // Add the backend name (i.e. "once_monthly" or "daily")
$intervalUniques[$counter] = $interval; // Add the unix timestamp of this interval, used to identify unique items
// Format display name in a proper way
$numOfMinutes = ($interval/60);
$identifier = __( 'minutes', 'companion-auto-update' );
// I just know there's an easier way for this, but I can't come up with it and this works so...
if( $interval >= (60*60) ) {
$numOfMinutes = ($numOfMinutes/60);
$identifier = __( 'hours', 'companion-auto-update' );
}
if( $interval >= (60*60*24) ) {
$numOfMinutes = ($numOfMinutes/24);
$identifier = __( 'days', 'companion-auto-update' );
}
if( $interval >= (60*60*24*7) ) {
$numOfMinutes = ($numOfMinutes/7);
$identifier = __( 'weeks', 'companion-auto-update' );
}
if( $interval >= (60*60*24*7*(52/12)) ) {
$numOfMinutes = ($numOfMinutes/(52/12));
$identifier = __( 'months', 'companion-auto-update' );
}
$display = sprintf( esc_html__( 'Every %s %s', 'companion-auto-update' ), round( $numOfMinutes, 2 ), $identifier ); // Translateble
$intervalNames[$counter] = $display; // Add the display name (i.e. "Once a month" or "Once Daily")
$counter++; // Make sure the next interval gets a new "key" value
}
}
}
// Sort the interval from smallest to largest
asort( $intervalUniques );
// Prevent duplicates
foreach ( array_unique( $intervalUniques ) as $key => $value ) {
// $value is the timestamp
@ -1162,6 +1211,12 @@ function cau_updateLogDBisEmpty() {
// Plugin information to DB
function cau_savePluginInformation( $method = 'New' ) {
// Check if function exists
if ( ! function_exists( 'get_plugins' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
// Set variables
global $wpdb;
$updateDB = "update_log";
$updateLog = $wpdb->prefix.$updateDB;