function my_picu_collection_add_tracking_admin_column( $columns ) {
$new_columns['tracking'] = _x( 'Tracking', 'column header', 'my-picu' );
$offset = 3;
$columns = array_slice( $columns, 0, $offset, true ) + $new_columns + array_slice( $columns, $offset, NULL, true );
return $columns;
}
add_filter( 'manage_picu_collection_posts_columns', 'my_picu_collection_add_tracking_admin_column', 11 );
function my_picu_column_content_tracking( $column, $post_id ) {
$post_status = get_post_status( $post_id );
$tracking_data = get_post_meta( $post_id, '_picu_delivery_download_tracking', true );
$output = '-';
if ( ( $post_status == 'delivery-draft' OR $post_status == 'delivered' ) && ! empty( $tracking_data ) && is_array( $tracking_data ) ) {
$last_access = end( $tracking_data );
$output = __( 'Last download:', 'my-picu' ) . '<br />' . wp_date( get_option( 'date_format' ) . ', ' . get_option( 'time_format' ), $last_access['time'] );
}
if ( $column == 'tracking' ) {
echo $output;
}
}
add_action( 'manage_picu_collection_posts_custom_column' , 'my_picu_column_content_tracking', 10, 2 );
Code language: PHP (php)