Skip to content

Commit

Permalink
Update action scheduler's package
Browse files Browse the repository at this point in the history
  • Loading branch information
wordpressfan committed Jan 21, 2025
1 parent aea1cc0 commit 915adba
Show file tree
Hide file tree
Showing 70 changed files with 1,970 additions and 943 deletions.
20 changes: 10 additions & 10 deletions inc/Dependencies/ActionScheduler/action-scheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
* Description: A robust scheduling library for use in WordPress plugins.
* Author: Automattic
* Author URI: https://automattic.com/
* Version: 3.8.1
* Version: 3.9.0
* License: GPLv3
* Requires at least: 6.2
* Tested up to: 6.5
* Requires PHP: 5.6
* Requires at least: 6.5
* Tested up to: 6.7
* Requires PHP: 7.1
*
* Copyright 2019 Automattic, Inc. (https://automattic.com/contact/)
*
Expand All @@ -29,29 +29,29 @@
* @package ActionScheduler
*/

if ( ! function_exists( 'action_scheduler_register_3_dot_8_dot_1' ) && function_exists( 'add_action' ) ) { // WRCS: DEFINED_VERSION.
if ( ! function_exists( 'action_scheduler_register_3_dot_9_dot_0' ) && function_exists( 'add_action' ) ) { // WRCS: DEFINED_VERSION.

if ( ! class_exists( 'ActionScheduler_Versions', false ) ) {
require_once __DIR__ . '/classes/ActionScheduler_Versions.php';
add_action( 'plugins_loaded', array( 'ActionScheduler_Versions', 'initialize_latest_version' ), 1, 0 );
}

add_action( 'plugins_loaded', 'action_scheduler_register_3_dot_8_dot_1', 0, 0 ); // WRCS: DEFINED_VERSION.
add_action( 'plugins_loaded', 'action_scheduler_register_3_dot_9_dot_0', 0, 0 ); // WRCS: DEFINED_VERSION.

// phpcs:disable Generic.Functions.OpeningFunctionBraceKernighanRitchie.ContentAfterBrace
/**
* Registers this version of Action Scheduler.
*/
function action_scheduler_register_3_dot_8_dot_1() { // WRCS: DEFINED_VERSION.
function action_scheduler_register_3_dot_9_dot_0() { // WRCS: DEFINED_VERSION.
$versions = ActionScheduler_Versions::instance();
$versions->register( '3.8.1', 'action_scheduler_initialize_3_dot_8_dot_1' ); // WRCS: DEFINED_VERSION.
$versions->register( '3.9.0', 'action_scheduler_initialize_3_dot_9_dot_0' ); // WRCS: DEFINED_VERSION.
}

// phpcs:disable Generic.Functions.OpeningFunctionBraceKernighanRitchie.ContentAfterBrace
/**
* Initializes this version of Action Scheduler.
*/
function action_scheduler_initialize_3_dot_8_dot_1() { // WRCS: DEFINED_VERSION.
function action_scheduler_initialize_3_dot_9_dot_0() { // WRCS: DEFINED_VERSION.
// A final safety check is required even here, because historic versions of Action Scheduler
// followed a different pattern (in some unusual cases, we could reach this point and the
// ActionScheduler class is already defined—so we need to guard against that).
Expand All @@ -63,7 +63,7 @@ function action_scheduler_initialize_3_dot_8_dot_1() { // WRCS: DEFINED_VERSION.

// Support usage in themes - load this version if no plugin has loaded a version yet.
if ( did_action( 'plugins_loaded' ) && ! doing_action( 'plugins_loaded' ) && ! class_exists( 'ActionScheduler', false ) ) {
action_scheduler_initialize_3_dot_8_dot_1(); // WRCS: DEFINED_VERSION.
action_scheduler_initialize_3_dot_9_dot_0(); // WRCS: DEFINED_VERSION.
do_action( 'action_scheduler_pre_theme_init' );
ActionScheduler_Versions::initialize_latest_version();
}
Expand Down
14 changes: 14 additions & 0 deletions inc/Dependencies/ActionScheduler/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
*** Changelog ***

= 3.9.0 - 2024-11-14 =
* Minimum required version of PHP is now 7.1.
* Performance improvements for the `as_pending_actions_due()` function.
* Existing filter hook `action_scheduler_claim_actions_order_by` enhanced to provide callbacks with additional information.
* Improved compatibility with PHP 8.4, specifically by making implicitly nullable parameters explicitly nullable.
* A large number of coding standards-enhancements, to help reduce friction when submitting plugins to marketplaces and plugin directories. Special props @crstauf for this effort.
* Minor documentation tweaks and improvements.

= 3.8.2 - 2024-09-12 =
* Add missing parameter to the `pre_as_enqueue_async_action` hook.
* Bump minimum PHP version to 7.0.
* Bump minimum WordPress version to 6.4.
* Make the batch size adjustable during processing.

= 3.8.1 - 2024-06-20 =
* Fix typos.
* Improve the messaging in our unidentified action exceptions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,42 @@
* Class ActionScheduler_ActionClaim
*/
class ActionScheduler_ActionClaim {
/**
* Claim ID.
*
* @var string
*/
private $id = '';

/**
* Claimed action IDs.
*
* @var int[]
*/
private $action_ids = array();

/**
* Construct.
*
* @param string $id Claim ID.
* @param int[] $action_ids Action IDs.
*/
public function __construct( $id, array $action_ids ) {
$this->id = $id;
$this->id = $id;
$this->action_ids = $action_ids;
}

/**
* Get claim ID.
*/
public function get_id() {
return $this->id;
}

/**
* Get IDs of claimed actions.
*/
public function get_actions() {
return $this->action_ids;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ public function create( array $options = array() ) {
break;

default:
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
error_log( "Unknown action type '{$options['type']}' specified when trying to create an action for '{$options['hook']}'." );
return 0;
}
Expand All @@ -318,6 +319,7 @@ public function create( array $options = array() ) {
try {
$action_id = $options['unique'] ? $this->store_unique_action( $action ) : $this->store( $action );
} catch ( Exception $e ) {
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
error_log(
sprintf(
/* translators: %1$s is the name of the hook to be enqueued, %2$s is the exception message. */
Expand Down
104 changes: 68 additions & 36 deletions inc/Dependencies/ActionScheduler/classes/ActionScheduler_AdminView.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,55 @@

/**
* Class ActionScheduler_AdminView
*
* @codeCoverageIgnore
*/
class ActionScheduler_AdminView extends ActionScheduler_AdminView_Deprecated {

private static $admin_view = NULL;
/**
* Instance.
*
* @var null|self
*/
private static $admin_view = null;

/**
* Screen ID.
*
* @var string
*/
private static $screen_id = 'tools_page_action-scheduler';

/** @var ActionScheduler_ListTable */
/**
* ActionScheduler_ListTable instance.
*
* @var ActionScheduler_ListTable
*/
protected $list_table;

/**
* Get instance.
*
* @return ActionScheduler_AdminView
* @codeCoverageIgnore
*/
public static function instance() {

if ( empty( self::$admin_view ) ) {
$class = apply_filters('action_scheduler_admin_view_class', 'ActionScheduler_AdminView');
$class = apply_filters( 'action_scheduler_admin_view_class', 'ActionScheduler_AdminView' );
self::$admin_view = new $class();
}

return self::$admin_view;
}

/**
* Initialize.
*
* @codeCoverageIgnore
*/
public function init() {
if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || false == DOING_AJAX ) ) {
if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {

if ( class_exists( 'WooCommerce' ) ) {
add_action( 'woocommerce_admin_status_content_action-scheduler', array( $this, 'render_admin_ui' ) );
Expand All @@ -45,6 +64,9 @@ public function init() {
}
}

/**
* Print system status report.
*/
public function system_status_report() {
$table = new ActionScheduler_wcSystemStatus( ActionScheduler::store() );
$table->render();
Expand Down Expand Up @@ -78,7 +100,7 @@ public function register_menu() {
'action-scheduler',
array( $this, 'render_admin_ui' )
);
add_action( 'load-' . $hook_suffix , array( $this, 'process_admin_ui' ) );
add_action( 'load-' . $hook_suffix, array( $this, 'process_admin_ui' ) );
}

/**
Expand Down Expand Up @@ -119,33 +141,31 @@ protected function get_list_table() {
*/
public function maybe_check_pastdue_actions() {

# Filter to prevent checking actions (ex: inappropriate user).
// Filter to prevent checking actions (ex: inappropriate user).
if ( ! apply_filters( 'action_scheduler_check_pastdue_actions', current_user_can( 'manage_options' ) ) ) {
return;
}

# Get last check transient.
// Get last check transient.
$last_check = get_transient( 'action_scheduler_last_pastdue_actions_check' );

# If transient exists, we're within interval, so bail.
// If transient exists, we're within interval, so bail.
if ( ! empty( $last_check ) ) {
return;
}

# Perform the check.
// Perform the check.
$this->check_pastdue_actions();
}

/**
* Check past-due actions, and print notice.
*
* @todo update $link_url to "Past-due" filter when released (see issue #510, PR #511)
*/
protected function check_pastdue_actions() {

# Set thresholds.
$threshold_seconds = ( int ) apply_filters( 'action_scheduler_pastdue_actions_seconds', DAY_IN_SECONDS );
$threshold_min = ( int ) apply_filters( 'action_scheduler_pastdue_actions_min', 1 );
// Set thresholds.
$threshold_seconds = (int) apply_filters( 'action_scheduler_pastdue_actions_seconds', DAY_IN_SECONDS );
$threshold_min = (int) apply_filters( 'action_scheduler_pastdue_actions_min', 1 );

// Set fallback value for past-due actions count.
$num_pastdue_actions = 0;
Expand All @@ -158,53 +178,65 @@ protected function check_pastdue_actions() {
return;
}

# Scheduled actions query arguments.
// Scheduled actions query arguments.
$query_args = array(
'date' => as_get_datetime_object( time() - $threshold_seconds ),
'status' => ActionScheduler_Store::STATUS_PENDING,
'per_page' => $threshold_min,
);

# If no third-party preempted, run default check.
// If no third-party preempted, run default check.
if ( is_null( $check ) ) {
$store = ActionScheduler_Store::instance();
$num_pastdue_actions = ( int ) $store->query_actions( $query_args, 'count' );
$store = ActionScheduler_Store::instance();
$num_pastdue_actions = (int) $store->query_actions( $query_args, 'count' );

# Check if past-due actions count is greater than or equal to threshold.
// Check if past-due actions count is greater than or equal to threshold.
$check = ( $num_pastdue_actions >= $threshold_min );
$check = ( bool ) apply_filters( 'action_scheduler_pastdue_actions_check', $check, $num_pastdue_actions, $threshold_seconds, $threshold_min );
$check = (bool) apply_filters( 'action_scheduler_pastdue_actions_check', $check, $num_pastdue_actions, $threshold_seconds, $threshold_min );
}

# If check failed, set transient and abort.
// If check failed, set transient and abort.
if ( ! boolval( $check ) ) {
$interval = apply_filters( 'action_scheduler_pastdue_actions_check_interval', round( $threshold_seconds / 4 ), $threshold_seconds );
set_transient( 'action_scheduler_last_pastdue_actions_check', time(), $interval );

return;
}

$actions_url = add_query_arg( array(
'page' => 'action-scheduler',
'status' => 'past-due',
'order' => 'asc',
), admin_url( 'tools.php' ) );
$actions_url = add_query_arg(
array(
'page' => 'action-scheduler',
'status' => 'past-due',
'order' => 'asc',
),
admin_url( 'tools.php' )
);

# Print notice.
// Print notice.
echo '<div class="notice notice-warning"><p>';
printf(
// translators: 1) is the number of affected actions, 2) is a link to an admin screen.
_n(
'<strong>Action Scheduler:</strong> %1$d <a href="%2$s">past-due action</a> found; something may be wrong. <a href="https://actionscheduler.org/faq/#my-site-has-past-due-actions-what-can-i-do" target="_blank">Read documentation &raquo;</a>',
'<strong>Action Scheduler:</strong> %1$d <a href="%2$s">past-due actions</a> found; something may be wrong. <a href="https://actionscheduler.org/faq/#my-site-has-past-due-actions-what-can-i-do" target="_blank">Read documentation &raquo;</a>',
$num_pastdue_actions,
'action-scheduler'
wp_kses(
// translators: 1) is the number of affected actions, 2) is a link to an admin screen.
_n(
'<strong>Action Scheduler:</strong> %1$d <a href="%2$s">past-due action</a> found; something may be wrong. <a href="https://actionscheduler.org/faq/#my-site-has-past-due-actions-what-can-i-do" target="_blank">Read documentation &raquo;</a>',
'<strong>Action Scheduler:</strong> %1$d <a href="%2$s">past-due actions</a> found; something may be wrong. <a href="https://actionscheduler.org/faq/#my-site-has-past-due-actions-what-can-i-do" target="_blank">Read documentation &raquo;</a>',
$num_pastdue_actions,
'action-scheduler'
),
array(
'strong' => array(),
'a' => array(
'href' => true,
'target' => true,
),
)
),
$num_pastdue_actions,
absint( $num_pastdue_actions ),
esc_attr( esc_url( $actions_url ) )
);
echo '</p></div>';

# Facilitate third-parties to evaluate and print notices.
// Facilitate third-parties to evaluate and print notices.
do_action( 'action_scheduler_pastdue_actions_extra_notices', $query_args );
}

Expand All @@ -214,7 +246,7 @@ protected function check_pastdue_actions() {
public function add_help_tabs() {
$screen = get_current_screen();

if ( ! $screen || self::$screen_id != $screen->id ) {
if ( ! $screen || self::$screen_id !== $screen->id ) {
return;
}

Expand Down
Loading

0 comments on commit 915adba

Please sign in to comment.