Skip to content

Commit 0a43aea

Browse files
authored
Merge pull request #10 from iamsayan/develop
v1.1.0 release
2 parents 53b8b5e + 34b3d9a commit 0a43aea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1585
-320
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ If you like Advanced Cron Scheduler plugin, please take a moment to [give a 5-st
44

55
All notable changes to this project will be documented in this file.
66

7+
## 1.1.0
8+
Release Date: 25th June, 2023
9+
10+
* Added: Option to disable check for past-due actions.
11+
* Tweak: Changed `init` hook to `action_scheduler_init`.
12+
* Updated: Action Scheduler library to v3.6.1.
13+
* Tested up to WordPress 6.3.
14+
715
## 1.0.9
816
Release Date: 15th November, 2022
917

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{
88
"name": "Sayan Datta",
99
"email": "iamsayan@protonmail.com",
10-
"homepage": "http://sayandatta.in",
10+
"homepage": "http://www.sayandatta.co.in",
1111
"role": "Developer"
1212
}
1313
],

composer.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

includes/Base/Actions.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ public function register() {
3434
* Register settings link.
3535
*/
3636
public function settings_link( $links ) {
37+
$links[] = '<a href="' . admin_url( 'options-general.php#acswp-settings' ) . '">' . __( 'Settings', 'migrate-wp-cron-to-action-scheduler' ) . '</a>';
3738
$links[] = '<a href="' . admin_url( 'tools.php?page=action-scheduler' ) . '">' . __( 'Action Scheduler', 'migrate-wp-cron-to-action-scheduler' ) . '</a>';
38-
39+
3940
return $links;
4041
}
4142

includes/Base/AdminNotice.php

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,36 +34,12 @@ public function register() {
3434
* Show internal admin notices.
3535
*/
3636
public function notice() {
37-
global $wp_version;
38-
39-
// Show a warning to sites running PHP < 5.6
40-
if ( version_compare( $wp_version, '5.2.0', '<' ) ) {
41-
deactivate_plugins( $this->plugin );
42-
if ( isset( $_GET['activate'] ) ) { // phpcs:ignore
43-
unset( $_GET['activate'] ); // phpcs:ignore
44-
}
45-
/* translators: %s: Plugin Name */
46-
echo '<div class="error"><p>' . sprintf( esc_html__( 'Your version of WordPress is below the minimum version of WordPress required by %s plugin. Please upgrade WordPress to 5.2.0 or later.', 'migrate-wp-cron-to-action-scheduler' ), esc_html( $this->name ) ) . '</p></div>';
47-
return;
48-
}
49-
50-
// Show a warning to sites running PHP < 5.6
51-
if ( version_compare( PHP_VERSION, '5.6', '<' ) ) {
52-
deactivate_plugins( $this->plugin );
53-
if ( isset( $_GET['activate'] ) ) { // phpcs:ignore
54-
unset( $_GET['activate'] ); // phpcs:ignore
55-
}
56-
/* translators: %s: Plugin Name */
57-
echo '<div class="error"><p>' . sprintf( esc_html__( 'Your version of PHP is below the minimum version of PHP required by %s plugin. Please contact your host and request that your version be upgraded to 5.6 or later.', 'migrate-wp-cron-to-action-scheduler' ), esc_html( $this->name ) ) . '</p></div>';
58-
return;
59-
}
60-
6137
// Check transient, if available display notice
6238
if ( get_transient( 'acswp-show-notice-on-activation' ) !== false ) { ?>
6339
<div class="notice notice-success">
6440
<p><strong><?php
6541
/* translators: %s: Plugin Name */
66-
printf( esc_html__( 'Thanks for installing %1$s v%2$s plugin. Click <a href="%3$s">here</a> to view Action Scheduler tasks.', 'migrate-wp-cron-to-action-scheduler' ), 'Advanced Cron Scheduler', esc_html( ACSWP_PLUGIN_VERSION ), esc_url( admin_url( 'tools.php?page=action-scheduler' ) ) ); ?></strong></p>
42+
printf( wp_kses_post( __( 'Thanks for installing %1$s v%2$s plugin. Click <a href="%3$s">here</a> to view Action Scheduler tasks.', 'migrate-wp-cron-to-action-scheduler' ) ), 'Advanced Cron Scheduler', esc_html( ACSWP_VERSION ), esc_url( admin_url( 'tools.php?page=action-scheduler' ) ) ); ?></strong></p>
6743
</div> <?php
6844
delete_transient( 'acswp-show-notice-on-activation' );
6945
}
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
/**
1818
* Admin Bar class.
1919
*/
20-
class AdminBar
20+
class Admin
2121
{
2222
use Hooker;
2323

@@ -26,6 +26,7 @@ class AdminBar
2626
*/
2727
public function register() {
2828
$this->action( 'admin_bar_menu', 'admin_bar' );
29+
$this->filter( 'action_scheduler_check_pastdue_actions', 'past_due_actions', 100 );
2930
}
3031

3132
/**
@@ -45,4 +46,13 @@ public function admin_bar( $wp_admin_bar ) {
4546
$wp_admin_bar->add_node( $args );
4647
}
4748
}
49+
50+
/**
51+
* Add admin bar content.
52+
*/
53+
public function past_due_actions( $check ) {
54+
$is_disabled = (bool) get_option( 'acswp_disable_past_due_checking' );
55+
56+
return $is_disabled ? false : $check;
57+
}
4858
}

includes/Core/Connection.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public function register() {
4040
$this->filter( 'pre_clear_scheduled_hook', 'pre_clear_scheduled_hook', 10, 3 );
4141
$this->filter( 'pre_get_scheduled_event', 'pre_get_scheduled_event', 10, 4 );
4242
$this->filter( 'pre_get_ready_cron_jobs', 'pre_get_ready_cron_jobs' );
43-
$this->action( 'init', 'register_crons', 10 );
43+
$this->action( 'action_scheduler_init', 'register_crons' );
44+
$this->action( 'shutdown', 'clear_crons' );
4445
}
4546

4647
/**
@@ -421,7 +422,7 @@ public function pre_get_ready_cron_jobs( $pre ) {
421422
$action = \ActionScheduler::store()->fetch_action( $action_id );
422423

423424
$hook = $action->get_hook();
424-
$key = md5( serialize( $action->get_args() ) );
425+
$key = md5( serialize( $action->get_args() ) ); // PHPCS:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
425426
$value = [
426427
'args' => $action->get_args(),
427428
'_job' => $action,
@@ -463,4 +464,11 @@ public function register_crons() {
463464
\wp_schedule_event( $event->timestamp, $event->schedule, $event->hook, $event->args );
464465
}
465466
}
467+
468+
/**
469+
* Clean crons
470+
*/
471+
public function clear_crons() {
472+
$this->events = [];
473+
}
466474
}

includes/Core/MigrateActions.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function regenerate_crons() {
7474
}
7575

7676
$statement = $wpdb->prepare( "SELECT a.action_id, a.hook, a.scheduled_date_gmt, a.args, g.slug AS `group` FROM {$wpdb->actionscheduler_actions} a LEFT JOIN {$wpdb->actionscheduler_groups} g ON a.group_id=g.group_id WHERE a.status=%s AND g.slug=%s", 'pending', 'mwpcac' );
77-
$values = $wpdb->get_results( $statement, ARRAY_A );
77+
$values = $wpdb->get_results( $statement, ARRAY_A ); // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared
7878
foreach ( $values as $value ) {
7979
$this->generate_wp_cron( strtotime( $value['scheduled_date_gmt'] ), $value['hook'], json_decode( $value['args'], true ) );
8080
$this->cancel_scheduled_action( $value['action_id'] );
@@ -96,7 +96,7 @@ private function generate_wp_cron( $timestamp, $hook, $args ) {
9696
}
9797

9898
// get keys
99-
$key = md5( serialize( $args ) );
99+
$key = md5( serialize( $args ) ); // PHPCS:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
100100

101101
$crons[ $timestamp ][ $hook ][ $key ] = [
102102
'schedule' => false,
@@ -121,7 +121,7 @@ private function remove_wp_cron( $timestamp, $hook, $args ) {
121121
$crons = _get_cron_array();
122122

123123
// get keys
124-
$key = md5( serialize( $args ) );
124+
$key = md5( serialize( $args ) ); // PHPCS:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
125125

126126
unset( $crons[ $timestamp ][ $hook ][ $key ] );
127127

includes/Core/Settings.php

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,26 @@ public function register() {
3232
* Register custom settings.
3333
*/
3434
public function register_fields() {
35-
register_setting( 'general', 'acswp_admin_bar' );
36-
add_settings_field( 'acswp_admin_bar', __( 'Show Admin Bar', 'migrate-wp-cron-to-action-scheduler' ), [ $this, 'admin_bar_field' ], 'general' );
35+
$fields = [
36+
'acswp_admin_bar' => __( 'Show Admin Bar', 'migrate-wp-cron-to-action-scheduler' ),
37+
'acswp_unique_action' => __( 'Enable Unique Actions', 'migrate-wp-cron-to-action-scheduler' ),
38+
'acswp_disable_past_due_checking' => __( 'Disable Past-Due Checking', 'migrate-wp-cron-to-action-scheduler' ),
39+
];
3740

38-
register_setting( 'general', 'acswp_unique_action' );
39-
add_settings_field( 'acswp_unique_action', __( 'Enable Unique Actions', 'migrate-wp-cron-to-action-scheduler' ), [ $this, 'unique_action_field' ], 'general' );
41+
add_settings_section( 'acswp-settings', __( 'Advanced Cron Scheduler', 'migrate-wp-cron-to-action-scheduler' ), [ $this, 'description' ], 'general' );
42+
43+
foreach ( $fields as $field => $name ) {
44+
register_setting( 'general', $field );
45+
add_settings_field( $field, $name, [ $this, str_replace( 'acswp_', '', $field ) . '_field' ], 'general', 'acswp-settings' );
46+
}
47+
}
48+
49+
/*
50+
* Print settings field
51+
*/
52+
public function description() { ?>
53+
<div id="acswp-settings"><?php esc_html_e( 'Customize Advanced Cron Scheduler Plugin settings here.', 'migrate-wp-cron-to-action-scheduler' ); ?></div>
54+
<?php
4055
}
4156

4257
/*
@@ -54,4 +69,12 @@ public function unique_action_field() { ?>
5469
<label><input type="checkbox" name="acswp_unique_action" value="1" <?php checked( get_option( 'acswp_unique_action' ), 1 ); ?> /> <?php esc_html_e( 'Enabling Unique Actions will prevent actions from being duplicated', 'migrate-wp-cron-to-action-scheduler' ); ?></label>
5570
<?php
5671
}
72+
73+
/*
74+
* Print settings field
75+
*/
76+
public function disable_past_due_checking_field() { ?>
77+
<label><input type="checkbox" name="acswp_disable_past_due_checking" value="1" <?php checked( get_option( 'acswp_disable_past_due_checking' ), 1 ); ?> /> <?php esc_html_e( 'Disable Past-Due Actions Checking', 'migrate-wp-cron-to-action-scheduler' ); ?></label>
78+
<?php
79+
}
5780
}

includes/Helpers/HelperFunctions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ protected function cancel_scheduled_action( $job_id ) {
112112
* @since 1.0.8
113113
*/
114114
protected function is_as_initialized() {
115-
if ( ! did_action( 'init' ) || ! \ActionScheduler::is_initialized() ) {
115+
if ( ! did_action( 'action_scheduler_init' ) || ! \ActionScheduler::is_initialized() ) {
116116
return false;
117117
}
118118

0 commit comments

Comments
 (0)