$value ) {
if ( strpos( $key, '_field_' ) !== 0 || empty( $value[0] ) ) {
continue;
}
$field = str_replace( '_field_', '', $key );
if ( in_array( $field, $selected_fields, true ) ) {
$output = maybe_unserialize( $value[0] );
if ( is_array( $output ) ) {
$output = array_map( 'sanitize_text_field', $output );
$output = implode( ', ', $output );
} else {
$output = sanitize_text_field( $output );
}
$submission_data[ $field ] = $output;
}
}
if ( empty( $submission_data ) ) {
echo '' . esc_html__( 'No selected submission details available.', 'ac-advanced-flamingo-settings' ) . '';
return;
}
echo '
';
foreach ( $submission_data as $field => $value ) {
echo '- ' . esc_html( ucwords( str_replace( '_', ' ', $field ) ) ) . ': ' . esc_html( $value ) . '
';
}
echo '
';
}
/**
* Add "Last Message" column to the address book
*/
public function acafs_address_book_columns( $columns ) {
$columns['last_message'] = __( 'Last Message', 'ac-advanced-flamingo-settings' );
return $columns;
}
/**
* Render "Last Message" column content
*/
public function acafs_render_address_book_column( $column, $post_id ) {
if ( $column !== 'last_message' ) {
return;
}
$email = sanitize_email( get_post_meta( $post_id, '_email', true ) );
if ( empty( $email ) ) {
echo '' . esc_html__( 'No messages found', 'ac-advanced-flamingo-settings' ) . '';
return;
}
$args = array(
'post_type' => 'flamingo_inbound',
'posts_per_page' => 1,
'fields' => 'ids',
'no_found_rows' => true,
'update_post_term_cache' => false,
'meta_query' => array(
array(
'key' => '_from_email',
'value' => $email,
'compare' => '=',
),
),
'orderby' => 'date',
'order' => 'DESC',
);
$messages = get_posts( $args );
if ( empty( $messages ) ) {
echo '' . esc_html__( 'No messages found', 'ac-advanced-flamingo-settings' ) . '';
return;
}
$last_id = (int) $messages[0];
$message = get_post_meta( $last_id, '_field_your-message', true );
$preview = $message ? wp_trim_words( $message, 10, '...' ) : esc_html__( 'Message unavailable', 'ac-advanced-flamingo-settings' );
$view_url = admin_url( 'admin.php?page=flamingo_inbound&post=' . $last_id . '&action=edit' );
echo '';
}
}