Skip to content

Commit

Permalink
Merge pull request #10 from iamsayan/develop
Browse files Browse the repository at this point in the history
v1.1.0 release
  • Loading branch information
iamsayan authored Jun 25, 2023
2 parents 53b8b5e + 34b3d9a commit 0a43aea
Show file tree
Hide file tree
Showing 47 changed files with 1,585 additions and 320 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ If you like Advanced Cron Scheduler plugin, please take a moment to [give a 5-st

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

## 1.1.0
Release Date: 25th June, 2023

* Added: Option to disable check for past-due actions.
* Tweak: Changed `init` hook to `action_scheduler_init`.
* Updated: Action Scheduler library to v3.6.1.
* Tested up to WordPress 6.3.

## 1.0.9
Release Date: 15th November, 2022

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{
"name": "Sayan Datta",
"email": "iamsayan@protonmail.com",
"homepage": "http://sayandatta.in",
"homepage": "http://www.sayandatta.co.in",
"role": "Developer"
}
],
Expand Down
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion includes/Base/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ public function register() {
* Register settings link.
*/
public function settings_link( $links ) {
$links[] = '<a href="' . admin_url( 'options-general.php#acswp-settings' ) . '">' . __( 'Settings', 'migrate-wp-cron-to-action-scheduler' ) . '</a>';
$links[] = '<a href="' . admin_url( 'tools.php?page=action-scheduler' ) . '">' . __( 'Action Scheduler', 'migrate-wp-cron-to-action-scheduler' ) . '</a>';

return $links;
}

Expand Down
26 changes: 1 addition & 25 deletions includes/Base/AdminNotice.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,36 +34,12 @@ public function register() {
* Show internal admin notices.
*/
public function notice() {
global $wp_version;

// Show a warning to sites running PHP < 5.6
if ( version_compare( $wp_version, '5.2.0', '<' ) ) {
deactivate_plugins( $this->plugin );
if ( isset( $_GET['activate'] ) ) { // phpcs:ignore
unset( $_GET['activate'] ); // phpcs:ignore
}
/* translators: %s: Plugin Name */
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>';
return;
}

// Show a warning to sites running PHP < 5.6
if ( version_compare( PHP_VERSION, '5.6', '<' ) ) {
deactivate_plugins( $this->plugin );
if ( isset( $_GET['activate'] ) ) { // phpcs:ignore
unset( $_GET['activate'] ); // phpcs:ignore
}
/* translators: %s: Plugin Name */
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>';
return;
}

// Check transient, if available display notice
if ( get_transient( 'acswp-show-notice-on-activation' ) !== false ) { ?>
<div class="notice notice-success">
<p><strong><?php
/* translators: %s: Plugin Name */
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>
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>
</div> <?php
delete_transient( 'acswp-show-notice-on-activation' );
}
Expand Down
12 changes: 11 additions & 1 deletion includes/Core/AdminBar.php → includes/Core/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* Admin Bar class.
*/
class AdminBar
class Admin
{
use Hooker;

Expand All @@ -26,6 +26,7 @@ class AdminBar
*/
public function register() {
$this->action( 'admin_bar_menu', 'admin_bar' );
$this->filter( 'action_scheduler_check_pastdue_actions', 'past_due_actions', 100 );
}

/**
Expand All @@ -45,4 +46,13 @@ public function admin_bar( $wp_admin_bar ) {
$wp_admin_bar->add_node( $args );
}
}

/**
* Add admin bar content.
*/
public function past_due_actions( $check ) {
$is_disabled = (bool) get_option( 'acswp_disable_past_due_checking' );

return $is_disabled ? false : $check;
}
}
12 changes: 10 additions & 2 deletions includes/Core/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public function register() {
$this->filter( 'pre_clear_scheduled_hook', 'pre_clear_scheduled_hook', 10, 3 );
$this->filter( 'pre_get_scheduled_event', 'pre_get_scheduled_event', 10, 4 );
$this->filter( 'pre_get_ready_cron_jobs', 'pre_get_ready_cron_jobs' );
$this->action( 'init', 'register_crons', 10 );
$this->action( 'action_scheduler_init', 'register_crons' );
$this->action( 'shutdown', 'clear_crons' );
}

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

$hook = $action->get_hook();
$key = md5( serialize( $action->get_args() ) );
$key = md5( serialize( $action->get_args() ) ); // PHPCS:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
$value = [
'args' => $action->get_args(),
'_job' => $action,
Expand Down Expand Up @@ -463,4 +464,11 @@ public function register_crons() {
\wp_schedule_event( $event->timestamp, $event->schedule, $event->hook, $event->args );
}
}

/**
* Clean crons
*/
public function clear_crons() {
$this->events = [];
}
}
6 changes: 3 additions & 3 deletions includes/Core/MigrateActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function regenerate_crons() {
}

$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' );
$values = $wpdb->get_results( $statement, ARRAY_A );
$values = $wpdb->get_results( $statement, ARRAY_A ); // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared
foreach ( $values as $value ) {
$this->generate_wp_cron( strtotime( $value['scheduled_date_gmt'] ), $value['hook'], json_decode( $value['args'], true ) );
$this->cancel_scheduled_action( $value['action_id'] );
Expand All @@ -96,7 +96,7 @@ private function generate_wp_cron( $timestamp, $hook, $args ) {
}

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

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

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

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

Expand Down
31 changes: 27 additions & 4 deletions includes/Core/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,26 @@ public function register() {
* Register custom settings.
*/
public function register_fields() {
register_setting( 'general', 'acswp_admin_bar' );
add_settings_field( 'acswp_admin_bar', __( 'Show Admin Bar', 'migrate-wp-cron-to-action-scheduler' ), [ $this, 'admin_bar_field' ], 'general' );
$fields = [
'acswp_admin_bar' => __( 'Show Admin Bar', 'migrate-wp-cron-to-action-scheduler' ),
'acswp_unique_action' => __( 'Enable Unique Actions', 'migrate-wp-cron-to-action-scheduler' ),
'acswp_disable_past_due_checking' => __( 'Disable Past-Due Checking', 'migrate-wp-cron-to-action-scheduler' ),
];

register_setting( 'general', 'acswp_unique_action' );
add_settings_field( 'acswp_unique_action', __( 'Enable Unique Actions', 'migrate-wp-cron-to-action-scheduler' ), [ $this, 'unique_action_field' ], 'general' );
add_settings_section( 'acswp-settings', __( 'Advanced Cron Scheduler', 'migrate-wp-cron-to-action-scheduler' ), [ $this, 'description' ], 'general' );

foreach ( $fields as $field => $name ) {
register_setting( 'general', $field );
add_settings_field( $field, $name, [ $this, str_replace( 'acswp_', '', $field ) . '_field' ], 'general', 'acswp-settings' );
}
}

/*
* Print settings field
*/
public function description() { ?>
<div id="acswp-settings"><?php esc_html_e( 'Customize Advanced Cron Scheduler Plugin settings here.', 'migrate-wp-cron-to-action-scheduler' ); ?></div>
<?php
}

/*
Expand All @@ -54,4 +69,12 @@ public function unique_action_field() { ?>
<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>
<?php
}

/*
* Print settings field
*/
public function disable_past_due_checking_field() { ?>
<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>
<?php
}
}
2 changes: 1 addition & 1 deletion includes/Helpers/HelperFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ protected function cancel_scheduled_action( $job_id ) {
* @since 1.0.8
*/
protected function is_as_initialized() {
if ( ! did_action( 'init' ) || ! \ActionScheduler::is_initialized() ) {
if ( ! did_action( 'action_scheduler_init' ) || ! \ActionScheduler::is_initialized() ) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion includes/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static function get_services() {
Base\Localization::class,
Core\Connection::class,
Core\MigrateActions::class,
Core\AdminBar::class,
Core\Admin::class,
Core\Settings::class,
];

Expand Down
2 changes: 1 addition & 1 deletion languages/migrate-wp-cron-to-action-scheduler.pot
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ msgid "Sayan Datta"
msgstr ""

#. Author URI of the plugin
msgid "https://sayandatta.in"
msgid "https://www.sayandatta.co.in"
msgstr ""

#: includes/Base/Actions.php:37
Expand Down
Loading

0 comments on commit 0a43aea

Please sign in to comment.