current_time( 'mysql' ), 'plugin' => $plugin_name, 'action' => $action, 'user' => $user_display_name, 'old_version' => $old_version, 'new_version' => $new_version, ]; $buffer = get_transient( 'astr_email_buffer' ); if ( ! is_array( $buffer ) ) { $buffer = []; } $buffer[] = $new_event; $delay_opt = get_option( 'astr_email_delay', '5min' ); $delay_map = [ '10sec' => 10,//testing '5min' => 5 * MINUTE_IN_SECONDS, '1h' => HOUR_IN_SECONDS, '6h' => 6 * HOUR_IN_SECONDS, '1d' => DAY_IN_SECONDS, '1w' => WEEK_IN_SECONDS, ]; $delay = isset( $delay_map[ $delay_opt ] ) ? $delay_map[ $delay_opt ] : 5 * MINUTE_IN_SECONDS; set_transient( 'astr_email_buffer', $buffer, $delay * 2 ); $next = wp_next_scheduled( 'astr_send_notification_event' ); if ( ! $next ) { wp_schedule_single_event( time() + $delay, 'astr_send_notification_event' ); } elseif ( $next > time() + $delay ) { wp_unschedule_event( $next, 'astr_send_notification_event' ); wp_schedule_single_event( time() + $delay, 'astr_send_notification_event' ); } } function astr_send_buffered_email_notification() { $buffer = get_transient( 'astr_email_buffer' ); if ( empty( $buffer ) || ! is_array( $buffer ) ) { return; } usort( $buffer, function ( $a, $b ) { return strtotime( $b['time'] ) - strtotime( $a['time'] ); } ); $emails = array_filter( array_map( 'trim', (array) get_option( 'astr_notification_emails', [] ) ) ); if ( empty( $emails ) ) { return; } $rows = ''; foreach ( $buffer as $event ) { $action_label = ucfirst( $event['action'] ); if ( $event['action'] === 'updated' && ! empty( $event['old_version'] ) && ! empty( $event['new_version'] ) ) { $action_label = 'Updated (' . $event['old_version'] . ' → ' . $event['new_version'] . ')'; } if ( $event['action'] === 'rolled_back' && ! empty( $event['old_version'] ) && ! empty( $event['new_version'] ) ) { $action_label = 'Reverted (' . $event['old_version'] . ' → ' . $event['new_version'] . ')'; } $rows .= sprintf( '
The following plugin actions occurred:
| Action | Plugin | Time | User |
|---|
This is a test email to verify that notifications are working correctly.
Time: ' . esc_html( current_time( 'mysql' ) ) . '