ID; } elseif ( is_object( $order_or_post ) && method_exists( $order_or_post, 'get_id' ) ) { $order_id = (int) $order_or_post->get_id(); } if ( $order_id < 1 ) { return; } $result = orderping_signed_post( ORDERPING_TIMELINE_PATH, array( 'type' => 'order_timeline', 'order_id' => (string) $order_id, ) ); // The markup is built from escaped values only. // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo orderping_timeline_html( $result ); } /** * Builds the panel markup from a backend answer. Every dynamic value is escaped. * * @param array $result Answer of orderping_signed_post(): status and decoded body. * @return string HTML. */ function orderping_timeline_html( array $result ) { $timeline = isset( $result['body']['timeline'] ) && is_array( $result['body']['timeline'] ) ? $result['body']['timeline'] : null; if ( 200 !== ( $result['status'] ?? 0 ) || null === $timeline || ! isset( $timeline['events'] ) || ! is_array( $timeline['events'] ) ) { return '

' . esc_html__( 'The history could not be loaded from CommercePing right now. Reload this page in a moment.', 'commerceping' ) . '

'; } if ( empty( $timeline['found'] ) || array() === $timeline['events'] ) { return '

' . esc_html__( 'Nothing is recorded for this order yet.', 'commerceping' ) . '

'; } $tones = array( 'good' => __( 'Done', 'commerceping' ), 'neutral' => __( 'Info', 'commerceping' ), 'pending' => __( 'Waiting', 'commerceping' ), 'warning' => __( 'Check', 'commerceping' ), 'critical' => __( 'Problem', 'commerceping' ), ); $zone = isset( $timeline['timezone_label'] ) && is_string( $timeline['timezone_label'] ) ? $timeline['timezone_label'] : 'UTC'; /* translators: %s: timezone name. */ $html = '

' . esc_html( sprintf( __( 'Oldest first, newest last. Times are shown in %s.', 'commerceping' ), $zone ) ) . '

'; if ( ! empty( $timeline['truncated'] ) ) { $html .= '

' . esc_html__( 'Older events are not shown; this is the latest part of the history.', 'commerceping' ) . '

'; } $html .= '
    '; $shown = 0; foreach ( $timeline['events'] as $event ) { if ( ! is_array( $event ) || ! isset( $event['label'], $event['when'] ) || ! is_string( $event['label'] ) || ! is_string( $event['when'] ) ) { continue; } if ( ++$shown > ORDERPING_TIMELINE_EVENTS ) { break; } $tone = isset( $event['tone'] ) && is_string( $event['tone'] ) && isset( $tones[ $event['tone'] ] ) ? $event['tone'] : 'neutral'; $detail = isset( $event['detail'] ) && is_string( $event['detail'] ) && '' !== $event['detail'] ? '
    ' . esc_html( $event['detail'] ) : ''; $at = isset( $event['at'] ) && is_string( $event['at'] ) ? $event['at'] : ''; $html .= '
  1. ' . esc_html( $event['label'] ) . ' (' . esc_html( $tones[ $tone ] ) . ')' . $detail . '
  2. '; } return $html . '
'; }