Skip to content
This repository has been archived by the owner on Oct 30, 2020. It is now read-only.

Added a option to manually set when the next Auto Clean-up will trigger. #88

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions wp-optimize-main.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,9 @@ function fCheck() {
echo '<a href="?page=WP-Optimize">';
_e('Refresh', 'wp-optimize');
echo '</a>';
echo ' <a href="?page=WP-Optimize&tab=wp_optimize_settings">';
_e('Edit', 'wp-optimize');
echo '</a>';
echo '</i>';
//echo $timestamp;
}
Expand Down
25 changes: 23 additions & 2 deletions wp-optimize-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
} else {
update_option( OPTION_NAME_SCHEDULE_TYPE, 'wpo_weekly' );
}
wpo_cron_activate();
$cron_time = isset($_POST["wpo_cron_time"]) ? strtotime($_POST["wpo_cron_time"]) : null;
wpo_cron_activate($cron_time);
add_action('wpo_cron_event2', 'wpo_cron_action');
//wpo_debugLog('We are at setting page form submission and reached wpo_cron_activate()');
} else {
Expand Down Expand Up @@ -228,6 +229,26 @@
<option value="wpo_monthly"><?php _e('Every month (every 31 days)', 'wp-optimize'); ?></option>
</select>
<br /><br />
<?php
if (wp_next_scheduled('wpo_cron_event2')) {
$timestamp = wp_next_scheduled( 'wpo_cron_event2' );
echo '<i>';
_e('Next schedule', 'wp-optimize');
echo ' : ';
echo '<span id="cron_time_display">';
echo '<font color="green">';
echo gmdate(get_option('date_format') . ' ' . get_option('time_format'), $timestamp );
echo '</font>';
echo ' - ';
echo '<a href="#" onclick="jQuery(\'#cron_time_display\').hide(); jQuery(\'#cron_time_edit\').css(\'display\', \'block\');">';
_e('Edit', 'wp-optimize');
echo '</a>';
echo '</i>';
echo '</span>';
echo '<input id="cron_time_edit" type="datetime-local" name="wpo_cron_time" value="'.gmdate("Y-m-d\TH:i", $timestamp ).'" min="'.gmdate("Y-m-d\TH:i").'" style="display: none" />';
echo '<br /><br />';
}
?>
<small><?php _e('Automatic cleanup will perform the following:', 'wp-optimize');
echo '<br/>';
_e('Remove revisions, auto drafts, posts/comments in trash, transient options. After that it will optimize the db.', 'wp-optimize');?></small>
Expand Down Expand Up @@ -277,7 +298,7 @@
<p>
<label for="enable-email-address">
<?php //_e('Send email to', 'wp-optimize');?>
<input name="enable-email-address" id="enable-email-address" type="text" value ="<?php //echo // esc_attr( get_option( OPTION_NAME_ENABLE_EMAIL_ADDRESS, get_bloginfo ( 'admin_email' ) ) ); ?>" />
<input name="enable-email-address" id="enable-email-address" type="email" value ="<?php //echo // esc_attr( get_option( OPTION_NAME_ENABLE_EMAIL_ADDRESS, get_bloginfo ( 'admin_email' ) ) ); ?>" />
</label>
</p> -->
<p>
Expand Down
45 changes: 26 additions & 19 deletions wp-optimize.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,48 +123,55 @@ function wpo_admin_actions()
}

// TODO: Need to find out why the schedule time is not refreshing
function wpo_cron_activate() {
//wpo_debugLog('running wpo_cron_activate()');
function wpo_cron_activate($cron_time = null) {
//wpo_debugLog('running wpo_cron_activate()');
$gmtoffset = (int) (3600 * ((double) get_option('gmt_offset')));

!empty($cron_time) && $cron_time = (int) $cron_time + $gmtoffset;

if ( get_option( OPTION_NAME_SCHEDULE ) !== false ) {
if ( get_option(OPTION_NAME_SCHEDULE) == 'true') {
if (!wp_next_scheduled('wpo_cron_event2')) {

$schedule_type = get_option(OPTION_NAME_SCHEDULE_TYPE, 'wpo_weekly');

switch ($schedule_type) {
if ( get_option(OPTION_NAME_SCHEDULE) == 'true') {
if (!wp_next_scheduled('wpo_cron_event2')) {

$schedule_type = get_option(OPTION_NAME_SCHEDULE_TYPE, 'wpo_weekly');
$this_time = current_time( "timestamp", 0 );

if (empty($cron_time)) {
switch ($schedule_type) {
case "wpo_daily":
//
$this_time = 60*60*24;
$this_time += 60*60*24;
break;

case "wpo_weekly":
//
$this_time = 60*60*24*7;
$this_time += 60*60*24*7;
break;

case "wpo_otherweekly":
//
$this_time = 60*60*24*14;
$this_time += 60*60*24*14;
break;

case "wpo_monthly":
//
$this_time = 60*60*24*31;
$this_time += 60*60*24*31;
break;

default:
$this_time = 60*60*24*7;
$this_time += 60*60*24*7;
break;

}

} else {
$this_time = $cron_time;
}

add_action('wpo_cron_event2', 'wpo_cron_action');
wp_schedule_event(current_time( "timestamp", 0 ) + $this_time , $schedule_type, 'wpo_cron_event2');
wp_schedule_event($this_time , $schedule_type, 'wpo_cron_event2');
wpo_debugLog('running wp_schedule_event()');
}
}
} else wpo_PluginOptionsSetDefaults();
}
}
} else wpo_PluginOptionsSetDefaults();
}

function wpo_cron_deactivate() {
Expand Down