Skip to content

Commit

Permalink
Merge pull request #12 from iamsayan/develop
Browse files Browse the repository at this point in the history
Update plugin to version 1.1.2, add new build script for localization…
  • Loading branch information
iamsayan authored Jan 2, 2025
2 parents 81b97de + 9acc76c commit a93f6d8
Show file tree
Hide file tree
Showing 88 changed files with 2,602 additions and 1,139 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ jobs:
environment: wp.org plugin

steps:
- name: Install Subversion
run: sudo apt-get install subversion

- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: WordPress Plugin Deploy
id: deploy
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
},
"scripts": {
"build": [
"composer dump-autoload"
"composer dump-autoload",
"composer pot"
],
"pot" : [
"wp i18n make-pot . languages/migrate-wp-cron-to-action-scheduler.pot --exclude=\"/vendor\""
Expand Down
20 changes: 10 additions & 10 deletions composer.lock

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

13 changes: 7 additions & 6 deletions includes/Base/AdminNotice.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,17 @@ public function dismiss_notice() {
$notice_action = join( '_', $notice );

if ( 'dismiss' === $notice_action ) {
update_option( 'acswp_plugin_dismiss_' . $notice_type . '_notice', '1' );
update_option( 'acswp_plugin_dismiss_' . $notice_type . '_notice', '1', false );
}

if ( 'no_thanks' === $notice_action ) {
update_option( 'acswp_plugin_no_thanks_' . $notice_type . '_notice', '1' );
update_option( 'acswp_plugin_dismiss_' . $notice_type . '_notice', '1' );
update_option( 'acswp_plugin_no_thanks_' . $notice_type . '_notice', '1', false );
update_option( 'acswp_plugin_dismiss_' . $notice_type . '_notice', '1', false );

if ( 'donate' === $notice_type ) {
update_option( 'acswp_plugin_dismissed_time_donate', time() );
update_option( 'acswp_plugin_dismissed_time_donate', time(), false );
} else {
update_option( 'acswp_plugin_dismissed_time', time() );
update_option( 'acswp_plugin_dismissed_time', time(), false );
}
}

Expand All @@ -141,7 +142,7 @@ private function calculate_time() {

if ( ! $installed_time ) {
$installed_time = time();
update_option( 'acswp_plugin_installed_time', $installed_time );
update_option( 'acswp_plugin_installed_time', $installed_time, false );
}

return $installed_time;
Expand Down
65 changes: 61 additions & 4 deletions includes/Core/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace ACSWP\Plugin\Core;

use ACSWP\Plugin\Helpers\Hooker;
use ACSWP\Plugin\Helpers\HelperFunctions;

defined( 'ABSPATH' ) || exit;

Expand All @@ -19,21 +20,27 @@
*/
class Admin
{
use Hooker;
use Hooker, HelperFunctions;

/**
* Register functions.
*/
public function register() {
$this->action( 'admin_bar_menu', 'admin_bar' );
$this->filter( 'action_scheduler_check_pastdue_actions', 'past_due_actions', 100 );
$this->filter( 'action_scheduler_retention_period', 'retention_period', 100 );
$this->filter( 'action_scheduler_queue_runner_batch_size', 'queue_batch_size', 10000 );
$this->filter( 'action_scheduler_queue_runner_concurrent_batches', 'concurrent_batches', 10000 );
$this->filter( 'action_scheduler_timeout_period', 'timeout', 100 );
$this->filter( 'action_scheduler_failure_period', 'timeout', 100 );
$this->filter( 'action_scheduler_queue_runner_time_limit', 'time_limit', 100 );
}

/**
* Add admin bar content.
*/
public function admin_bar( $wp_admin_bar ) {
$item = (bool) $this->do_filter( 'show_admin_bar_item', get_option( 'acswp_admin_bar' ) );
$item = (bool) $this->do_filter( 'show_admin_bar_item', $this->get_settings( 'admin_bar' ) );

if ( $item ) {
$args = array(
Expand All @@ -48,11 +55,61 @@ public function admin_bar( $wp_admin_bar ) {
}

/**
* Add admin bar content.
* Disable past-due actions checking.
*/
public function past_due_actions( $check ) {
$is_disabled = (bool) get_option( 'acswp_disable_past_due_checking' );
$is_disabled = (bool) $this->get_settings( 'disable_past_due_checking' );

return $is_disabled ? false : $check;
}

/**
* Change retention period.
*/
public function retention_period( $retention_period ) {
$units = [
'minutes' => MINUTE_IN_SECONDS,
'hours' => HOUR_IN_SECONDS,
'days' => DAY_IN_SECONDS,
'weeks' => WEEK_IN_SECONDS,
'months' => MONTH_IN_SECONDS,
'years' => YEAR_IN_SECONDS,
];
$retention_period = $this->get_settings( 'data_retention_period', 0 );
$selected_unit = $this->get_settings( 'data_retention_unit', 'days' );

if ( $retention_period > 0 && isset( $units[ $selected_unit ] ) ) {
return $retention_period * $units[ $selected_unit ];
}

return $retention_period;
}

/**
* Change queue batch size.
*/
public function queue_batch_size( $batch_size ) {
return $this->get_settings( 'queue_batch_size', $batch_size );
}

/**
* Change concurrent batches.
*/
public function concurrent_batches( $concurrent_batches ) {
return $this->get_settings( 'concurrent_batches', $concurrent_batches );
}

/**
* Change timeout.
*/
public function timeout( $timeout ) {
return $this->get_settings( 'timeout', $timeout );
}

/**
* Change time limit.
*/
public function time_limit( $time_limit ) {
return $this->get_settings( 'time_limit', $time_limit );
}
}
44 changes: 24 additions & 20 deletions includes/Core/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,15 +356,15 @@ public function pre_get_scheduled_event( $pre, $hook, $args, $timestamp ) {
'args' => $args,
);

$job = $this->get_next_action_by_data( $hook, $args, $timestamp );

if ( ! empty( $job ) ) {
$schedule = $this->get_schedule( $job[0] );
if ( $schedule->is_recurring() ) {
if ( method_exists( $schedule, 'get_recurrence' ) ) {
$event->schedule = $this->get_schedule_by_interval( $schedule->get_recurrence() );
$event->interval = (int) $schedule->get_recurrence();
}
$action = $this->get_next_action_by_data( $hook, $args, $timestamp );

if ( ! empty( $action ) ) {
$schedule = $this->get_schedule( $action[0] );

if ( $schedule && $schedule->is_recurring() && method_exists( $schedule, 'get_recurrence' ) ) {
$recurrence = (int) $schedule->get_recurrence();
$event->schedule = $this->get_schedule_by_interval( $recurrence );
$event->interval = $recurrence;
}
}

Expand Down Expand Up @@ -398,11 +398,11 @@ public function pre_get_ready_cron_jobs( $pre ) {
}

if ( $proceed ) {
foreach ( $wp_crons as $timestamp => $cronhooks ) {
foreach ( $wp_crons as $timestamp => $cron_hooks ) {
if ( $timestamp > $gmt_time ) {
break;
}
$crons[ $timestamp ] = $cronhooks;
$crons[ $timestamp ] = $cron_hooks;
}
}
}
Expand All @@ -419,22 +419,26 @@ public function pre_get_ready_cron_jobs( $pre ) {
] );

foreach ( $results as $action_id ) {
$action = \ActionScheduler::store()->fetch_action( $action_id );
$action = $this->get_action( $action_id );
if ( ! $action ) {
continue;
}

$hook = $action->get_hook();
$key = md5( serialize( $action->get_args() ) ); // PHPCS:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
$value = [
$schedule = $action->get_schedule();
$hook = $action->get_hook();
$key = md5( serialize( $action->get_args() ) ); // PHPCS:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
$value = [
'args' => $action->get_args(),
'_job' => $action,
];

$timestamp = $action->get_schedule();
if ( method_exists( $timestamp, 'get_recurrence' ) ) {
$value['schedule'] = $this->get_schedule_by_interval( $timestamp->get_recurrence() );
$value['interval'] = (int) $timestamp->get_recurrence();
if ( $schedule && method_exists( $schedule, 'get_recurrence' ) ) {
$recurrence = (int) $schedule->get_recurrence();
$value['schedule'] = $this->get_schedule_by_interval( $recurrence );
$value['interval'] = $recurrence;
}

$next = $timestamp->get_date();
$next = $schedule->get_date();
if ( $next ) {
$timestamp = $next->getTimestamp();
} else {
Expand Down
Loading

0 comments on commit a93f6d8

Please sign in to comment.