From 32e4a1f4054983751797a41630a06587cee9de93 Mon Sep 17 00:00:00 2001 From: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Wed, 16 Oct 2024 13:55:07 +0200 Subject: [PATCH] Render password expiration date in post list tables --- includes/functions/_setup-meta-fields.php | 38 +++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/includes/functions/_setup-meta-fields.php b/includes/functions/_setup-meta-fields.php index ca7c0d9a..279859c6 100644 --- a/includes/functions/_setup-meta-fields.php +++ b/includes/functions/_setup-meta-fields.php @@ -4712,3 +4712,41 @@ function fictioneer_bulk_edit_save_chapter_fields( $post_id ) { } } add_action( 'save_post', 'fictioneer_bulk_edit_save_chapter_fields' ); + +// ============================================================================= +// PASSWORD EXPIRATION NOTE IN POST TABLE +// ============================================================================= + +/** + * Renders expiration date in post list table password note + * + * @since 5.25.0 + * + * @param string[] $post_states An array of post display states. + * @param WP_Post $post The current post object. + * + * @return string[] Filtered post display states used in the posts list table. + */ + +function fictioneer_add_post_table_pw_expiration( $post_states, $post ) { + if ( isset( $post_states['protected'] ) ) { + $expiration_date = get_post_meta( $post->ID, 'fictioneer_post_password_expiration_date', true ); + + if ( $expiration_date ) { + $timestamp = strtotime( $expiration_date ); + + $post_states['protected'] = sprintf( + _x( '%1$s (until %2$s)', 'Expiration suffix for protected note in post list tables.', 'fictioneer' ), + $post_states['protected'], + sprintf( + __( '%1$s at %2$s' ), // WP post table default + date_i18n( __( 'Y/m/d' ), $timestamp ), // WP post table default + date_i18n( __( 'g:i a' ), $timestamp ) // WP post table default + ) + ); + } + } + + return $post_states; +} +add_filter( 'display_post_states', 'fictioneer_add_post_table_pw_expiration', 10, 2 );