Skip to content

Commit 49ab937

Browse files
committed
Fix missing taxonomy column feature parity with post
1 parent d6d83bb commit 49ab937

File tree

1 file changed

+32
-11
lines changed

1 file changed

+32
-11
lines changed

src/TaxonomyAdmin.php

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
use WP_Post;
77
use WP_Taxonomy;
8+
use WP_Term;
9+
use DateTime;
10+
use Exception;
811

912
class TaxonomyAdmin {
1013

@@ -224,37 +227,44 @@ public function cols( array $cols ): array {
224227
* @param string $string Blank string.
225228
* @param string $col Name of the column.
226229
* @param int $term_id Term ID.
227-
* @return string Blank string.
228230
*/
229-
public function col( string $string, string $col, int $term_id ): string {
231+
public function col( string $string, string $col, int $term_id ): void {
230232
# Shorthand:
231233
$c = $this->args['admin_cols'];
232234

233235
# We're only interested in our custom columns:
234236
$custom_cols = array_filter( array_keys( $c ) );
235237

236238
if ( ! in_array( $col, $custom_cols, true ) ) {
237-
return $string;
239+
return;
240+
}
241+
242+
if ( isset( $c[ $col ]['term_cap'] ) && ! current_user_can( $c[ $col ]['term_cap'], get_the_ID() ) ) {
243+
return;
244+
}
245+
246+
$term = get_term( $term_id );
247+
248+
if ( ! $term ) {
249+
return;
238250
}
239251

240252
if ( isset( $c[ $col ]['function'] ) ) {
241-
call_user_func( $c[ $col ]['function'], $term_id );
253+
call_user_func( $c[ $col ]['function'], $term );
242254
} elseif ( isset( $c[ $col ]['meta_key'] ) ) {
243-
$this->col_term_meta( $c[ $col ]['meta_key'], $c[ $col ], $term_id );
255+
$this->col_term_meta( $term, $c[ $col ]['meta_key'], $c[ $col ] );
244256
}
245-
246-
return $string;
247257
}
248258

249259
/**
250260
* Output column data for a term meta field.
251261
*
262+
* @param WP_Term $term The term object.
252263
* @param string $meta_key The term meta key.
253264
* @param array<string,mixed> $args Array of arguments for this field.
254-
* @param int $term_id Term ID.
255265
*/
256-
public function col_term_meta( string $meta_key, array $args, int $term_id ): void {
257-
$vals = get_term_meta( $term_id, $meta_key, false );
266+
public function col_term_meta( WP_Term $term, string $meta_key, array $args ): void {
267+
$vals = get_term_meta( $term->term_id, $meta_key, false );
258268
$echo = [];
259269

260270
sort( $vals );
@@ -265,14 +275,25 @@ public function col_term_meta( string $meta_key, array $args, int $term_id ): vo
265275
}
266276

267277
foreach ( $vals as $val ) {
278+
try {
279+
$val_time = ( new DateTime( '@' . $val ) )->format( 'U' );
280+
} catch ( Exception $e ) {
281+
$val_time = strtotime( $val );
282+
}
283+
284+
if ( false !== $val_time ) {
285+
$val = $val_time;
286+
}
287+
268288
if ( is_numeric( $val ) ) {
269-
$echo[] = date( $args['date_format'], (int) $val );
289+
$echo[] = date_i18n( $args['date_format'], (int) $val );
270290
} elseif ( ! empty( $val ) ) {
271291
$echo[] = mysql2date( $args['date_format'], $val );
272292
}
273293
}
274294
} else {
275295
foreach ( $vals as $val ) {
296+
276297
if ( ! empty( $val ) || ( '0' === $val ) ) {
277298
$echo[] = $val;
278299
}

0 commit comments

Comments
 (0)