populate_event( $id_or_row ); } /** * Get and prepare the event data. * * @since 3.0.0 * * @param int|object $id_or_row The event ID or object with event attributes. */ private function populate_event( $id_or_row ) { $event = null; if ( is_numeric( $id_or_row ) ) { // Get by ID. $collection = new EventsCollection( [ 'id' => (int) $id_or_row ] ); $events = $collection->get(); if ( $events->valid() ) { $event = $events->current(); } } elseif ( is_object( $id_or_row ) && isset( $id_or_row->id, $id_or_row->content, $id_or_row->initiator, $id_or_row->event_type, $id_or_row->created_at ) ) { $event = $id_or_row; } if ( $event !== null ) { foreach ( get_object_vars( $event ) as $key => $value ) { $this->{$key} = $value; } } } /** * Event ID as per our DB table. * * @since 3.0.0 * * @return int */ public function get_id() { return (int) $this->id; } /** * Get the event title. * * @since 3.0.0 * * @return string */ public function get_title() { /* translators: %d the event ID. */ return sprintf( esc_html__( 'Event #%d', 'wp-mail-smtp' ), $this->get_id() ); } /** * Get the content of the event. * * @since 3.0.0 * * @return string */ public function get_content() { return $this->content; } /** * Get the event's type. * * @since 3.0.0 * * @return int */ public function get_type() { return (int) $this->event_type; } /** * Get the list of all event types. * * @since 3.0.0 * * @return array */ public static function get_types() { return [ self::TYPE_ERROR => esc_html__( 'Error', 'wp-mail-smtp' ), self::TYPE_DEBUG => esc_html__( 'Debug', 'wp-mail-smtp' ), ]; } /** * Get human readable type name. * * @since 3.0.0 * * @return string */ public function get_type_name() { $types = self::get_types(); return isset( $types[ $this->get_type() ] ) ? $types[ $this->get_type() ] : ''; } /** * Get the date/time when this event was created. * * @since 3.0.0 * * @throws \Exception Emits exception on incorrect date. * * @return \DateTime */ public function get_created_at() { $timezone = new \DateTimeZone( 'UTC' ); $date = false; if ( ! empty( $this->created_at ) ) { $date = \DateTime::createFromFormat( WP::datetime_mysql_format(), $this->created_at, $timezone ); } if ( $date === false ) { $date = new \DateTime( 'now', $timezone ); } return $date; } /** * Get the date/time when this event was created in a nicely formatted string. * * @since 3.0.0 * * @return string */ public function get_created_at_formatted() { try { $date = $this->get_created_at(); } catch ( \Exception $e ) { $date = null; } if ( empty( $date ) ) { return esc_html__( 'N/A', 'wp-mail-smtp' ); } return esc_html( date_i18n( WP::datetime_format(), strtotime( get_date_from_gmt( $date->format( WP::datetime_mysql_format() ) ) ) ) ); } /** * Get the event's initiator raw data. * Who called the `wp_mail` function? * * @since 3.0.0 * * @return array */ public function get_initiator_raw() { return json_decode( $this->initiator, true ); } /** * Get the event's initiator name. * Which plugin/theme (or WP core) called the `wp_mail` function? * * @since 3.0.0 * * @return string */ public function get_initiator() { $initiator = (array) $this->get_initiator_raw(); if ( empty( $initiator['file'] ) ) { return ''; } return WP::get_initiator_name( $initiator['file'] ); } /** * Get the event's initiator file path. * * @since 3.0.0 * * @return string */ public function get_initiator_file_path() { $initiator = (array) $this->get_initiator_raw(); if ( empty( $initiator['file'] ) ) { return ''; } return $initiator['file']; } /** * Get the event's initiator file line. * * @since 3.0.0 * * @return string */ public function get_initiator_file_line() { $initiator = (array) $this->get_initiator_raw(); if ( empty( $initiator['line'] ) ) { return ''; } return $initiator['line']; } /** * Get the event's initiator backtrace. * * @since 3.6.0 * * @return array */ private function get_initiator_backtrace() { $initiator = (array) $this->get_initiator_raw(); if ( empty( $initiator['backtrace'] ) ) { return []; } return $initiator['backtrace']; } /** * Get the event preview HTML. * * @since 3.0.0 * * @return string */ public function get_details_html() { $initiator = $this->get_initiator(); $initiator_backtrace = $this->get_initiator_backtrace(); ob_start(); ?>
get_initiator_file_path() ),
esc_html( $this->get_initiator_file_line() )
);
?>
$item ) {
printf(
/* translators: %1$d - index number; %2$s - function name; %3$s - file path; %4$s - line number. */
esc_html__( '[%1$d] %2$s called at [%3$s:%4$s]', 'wp-mail-smtp' ),
$i,
isset( $item['class'] ) ? esc_html( $item['class'] . $item['type'] . $item['function'] ) : esc_html( $item['function'] ),
isset( $item['file'] ) ? esc_html( $item['file'] ) : '', // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
isset( $item['line'] ) ? esc_html( $item['line'] ) : '' // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
);
echo '
';
}
?>