1, 'woocommerce_scheduled_subscription_payment' => 1, 'woocommerce_scheduled_subscription_payment_retry' => 1, 'woocommerce_scheduled_subscription_expiration' => 1, 'woocommerce_scheduled_subscription_end_of_prepaid_term' => 1, ); /** * WC Logger instance for logging messages. * * @var WC_Logger */ protected $logger; /** * Constructor. * * @param WC_Logger $logger The WC Logger instance. * @since 2.2.19 */ public function __construct( WC_Logger $logger ) { $this->logger = $logger; } /** * Attach callbacks. * * @since 2.2.19 */ public function init() { add_action( 'action_scheduler_failed_action', array( $this, 'log_action_scheduler_failure' ), 10, 2 ); add_action( 'admin_notices', array( $this, 'maybe_show_admin_notice' ) ); } /** * Log a message to the failed-scheduled-actions log. * * @param string $message the message to be written to the log. * @since 2.2.19 */ protected function log( $message ) { $this->logger->add( 'failed-scheduled-actions', $message ); } /** * When a scheduled action failure is triggered, log information about the failed action to a WC logger. * * @param int $action_id the action which failed. * @param int $timeout the number of seconds an action can run for before timing out. * @since 2.2.19 */ public function log_action_scheduler_failure( $action_id, $timeout ) { $action = $this->get_action( $action_id ); if ( ! isset( $this->tracked_scheduled_actions[ $action->get_hook() ] ) ) { return; } $subscription_action = $this->get_action_hook_label( $action->get_hook() ); $this->log( sprintf( 'scheduled action %s (%s) failed to finish processing after %s seconds', $action_id, $subscription_action , $timeout ) ); $this->log( sprintf( 'action args: %s', $this->get_action_args_string( $action->get_args() ) ) ); // Store information about the scheduled action for displaying an admin notice $failed_scheduled_actions = get_option( WC_Subscriptions_Admin::$option_prefix . '_failed_scheduled_actions', array() ); $failed_scheduled_actions[ $action_id ] = array( 'args' => $action->get_args(), 'type' => $subscription_action, ); update_option( WC_Subscriptions_Admin::$option_prefix . '_failed_scheduled_actions', $failed_scheduled_actions ); } /** * Display an admin notice when a scheduled action failure has occurred. * * @since 2.2.19 */ public function maybe_show_admin_notice() { $this->maybe_disable_admin_notice(); $failed_scheduled_actions = get_option( WC_Subscriptions_Admin::$option_prefix . '_failed_scheduled_actions', array() ); if ( empty( $failed_scheduled_actions ) ) { return; } $affected_subscription_events = $separator = ''; foreach ( array_slice( $failed_scheduled_actions, -10, 10 ) as $action ) { if ( isset( $action['args']['subscription_id'] ) ) { $subject = '#' . $action['args']['subscription_id'] . ''; } elseif ( isset( $action['args']['order_id'] ) ) { $subject = '#' . $action['args']['order_id'] . ''; } else { $subject = 'unknown'; } $affected_subscription_events .= $separator . $action['type'] . ' for ' . $subject; $separator = "\n"; }?>
', '', '
', '', '
', '' . wp_kses( $affected_subscription_events, array( 'a' => array( 'href' => array() ) ) ) . '
',
'failed-scheduled-actions
',
'',
''
);?>