Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Email notification for flooded past-due actions #1083

Open
wants to merge 34 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
e40091a
save
crstauf Aug 3, 2024
672bf1d
save
crstauf Aug 3, 2024
1d7c248
save
crstauf Aug 3, 2024
4e13f5f
save
crstauf Aug 3, 2024
3ea707d
save
crstauf Aug 3, 2024
0a01652
save
crstauf Aug 3, 2024
16dafb3
save
crstauf Aug 3, 2024
70b028e
save
crstauf Aug 5, 2024
c2e42d4
save
crstauf Aug 5, 2024
df102dc
save
crstauf Aug 5, 2024
fc8a8dc
save
crstauf Aug 5, 2024
36af56c
save
crstauf Aug 8, 2024
208c600
Merge branch 'trunk' into past-due-email-notify
crstauf Aug 12, 2024
914ec7f
Merge branch 'master' into past-due-email-notify
crstauf Aug 15, 2024
9426b7d
Merge branch 'trunk' into past-due-email-notify
crstauf Aug 21, 2024
2a5f7e1
Merge branch 'trunk' into past-due-email-notify
crstauf Aug 26, 2024
3b8cfc9
Merge branch 'trunk' into past-due-email-notify
crstauf Sep 5, 2024
25a186b
save
crstauf Sep 7, 2024
943f599
Merge branch 'trunk' into past-due-email-notify
crstauf Sep 14, 2024
4d643f5
add documentation for filter
crstauf Sep 17, 2024
21603ec
Merge branch 'trunk' into past-due-email-notify
crstauf Sep 18, 2024
5782f3c
Merge branch 'trunk' into past-due-email-notify
crstauf Oct 3, 2024
d39c77a
Merge branch 'trunk' into past-due-email-notify
crstauf Oct 23, 2024
9487bbd
Merge branch 'trunk' into past-due-email-notify
crstauf Oct 23, 2024
e94ebde
Merge branch 'trunk' into past-due-email-notify
crstauf Oct 23, 2024
080f7b8
Merge branch 'trunk' into past-due-email-notify
crstauf Oct 25, 2024
ad4f4ec
Merge branch 'trunk' into past-due-email-notify
crstauf Oct 29, 2024
d55cc2f
Merge branch 'trunk' into past-due-email-notify
crstauf Oct 30, 2024
0e59ee6
Merge branch 'trunk' into past-due-email-notify
crstauf Oct 30, 2024
4a91e71
Merge branch 'trunk' into past-due-email-notify
crstauf Oct 30, 2024
5d61aa8
Merge branch 'trunk' into past-due-email-notify
crstauf Oct 31, 2024
223c86b
Merge branch 'trunk' into past-due-email-notify
crstauf Nov 1, 2024
6291ff2
Merge branch 'trunk' into past-due-email-notify
crstauf Nov 2, 2024
887e2cc
Merge branch 'trunk' into past-due-email-notify
crstauf Nov 15, 2024
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
99 changes: 0 additions & 99 deletions classes/ActionScheduler_AdminView.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public function init() {
}

add_action( 'admin_menu', array( $this, 'register_menu' ) );
add_action( 'admin_notices', array( $this, 'maybe_check_pastdue_actions' ) );
add_action( 'current_screen', array( $this, 'add_help_tabs' ) );
}
}
Expand Down Expand Up @@ -117,104 +116,6 @@ protected function get_list_table() {
return $this->list_table;
}

/**
* Action: admin_notices
*
* Maybe check past-due actions, and print notice.
*
* @uses $this->check_pastdue_actions()
*/
public function maybe_check_pastdue_actions() {

// 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.
$last_check = get_transient( 'action_scheduler_last_pastdue_actions_check' );

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

// 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 fallback value for past-due actions count.
$num_pastdue_actions = 0;

// Allow third-parties to preempt the default check logic.
$check = apply_filters( 'action_scheduler_pastdue_actions_check_pre', null );

// If no third-party preempted and there are no past-due actions, return early.
if ( ! is_null( $check ) ) {
return;
}

// 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 ( is_null( $check ) ) {
$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 = ( $num_pastdue_actions >= $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 ( ! 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' ) );

// 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'
),
$num_pastdue_actions,
esc_attr( esc_url( $actions_url ) )
);
echo '</p></div>';

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

/**
* Provide more information about the screen and its data in the help tab.
*/
Expand Down
Loading
Loading