-
Notifications
You must be signed in to change notification settings - Fork 0
/
scheduled-actions-meta-box.php
67 lines (55 loc) · 1.8 KB
/
scheduled-actions-meta-box.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/**
* Plugin Name: Scheduled Actions Meta Box
* Plugin URI: https://shopplugins.com
* Description: Add a meta box to Subscription post types to view upcoming scheduled actions.
* Version: 0.0.1
* Author: Shop Plugins
* Author URI: https://shopplugins.com
* Text Domain: scheduled-actions-meta-box
*/
namespace ShopPlugins\ScheduledActionsMetaBox;
if ( is_admin() ) {
add_action( 'add_meta_boxes', __NAMESPACE__ . '\add_meta_boxes', 30 );
}
/**
* Add metabox to shop_subscription pages.
*
* @hook `add_meta_boxes`
*/
function add_meta_boxes() {
global $current_screen, $post_ID;
add_meta_box( 'subscription_scheduled_actions', __( 'Scheduled Actions', 'scheduled-actions-meta-box' ), __NAMESPACE__ . '\display_meta_box', 'shop_subscription', 'normal', 'low' );
}
/**
* Add scheduled actions meta box to Edit Subscription page.
*/
function display_meta_box() {
global $post;
if ( ! class_exists( 'ActionScheduler_Store' ) ) {
return;
}
$scheduled_actions = as_get_scheduled_actions(
array(
'args' => array( 'subscription_id' => absint( $post->ID ) ),
'status' => \ActionScheduler_Store::STATUS_PENDING,
'per_page' => -1,
'order' => 'ASC',
)
);
if ( ! empty( $scheduled_actions ) ) {
echo '<ol>';
foreach ( $scheduled_actions as $action_id => $action ) {
$schedule = $action->get_schedule();
if ( ! $schedule->next() ) {
continue;
}
$next_scheduled_date_string = $schedule->next()->format( 'Y-m-d H:i:s' ) . ' GMT';
$action_display_string = sprintf( '%s - %s - %s', $next_scheduled_date_string, $action->get_hook(), wp_json_encode( $action->get_args() ) );
printf( '<li class="default_sa">%s</li>', esc_html( $action_display_string ) );
}
echo '</ol>';
} else {
echo 'There are currently no pending scheduled actions for this subscription';
}
}