diff --git a/functions/admin.php b/functions/admin.php index 12a30392..543ec5f1 100644 --- a/functions/admin.php +++ b/functions/admin.php @@ -219,6 +219,61 @@ function sunflower_admin_style() { add_action( 'admin_enqueue_scripts', 'sunflower_admin_style' ); +/** + * Add the last modified column to post, page and event list tables. + * + * @param array $columns Existing list table columns. + * @return array List table columns including last modified. + */ +function sunflower_add_modified_by_column( $columns ) { + $columns['last_modified_by'] = __( 'Last modified', 'sunflower' ); + + return $columns; +} + +add_filter( 'manage_posts_columns', 'sunflower_add_modified_by_column' ); +add_filter( 'manage_pages_columns', 'sunflower_add_modified_by_column' ); +add_filter( 'manage_sunflower_event_posts_columns', 'sunflower_add_modified_by_column' ); + +/** + * Show the last editor and modification timestamp in the custom list table column. + * + * @param string $column Current column name. + * @param int $post_id Current post ID. + */ +function sunflower_fill_modified_by_column( $column, $post_id ) { + if ( 'last_modified_by' !== $column ) { + return; + } + + $last_user_id = (int) get_post_meta( $post_id, '_edit_last', true ); + if ( ! $last_user_id ) { + $last_user_id = (int) get_post_field( 'post_author', $post_id ); + } + + $user = get_userdata( $last_user_id ); + $user_name = $user ? $user->user_login : __( 'Unknown', 'sunflower' ); + + $modified_date = get_the_modified_date( 'd.m.Y', $post_id ); + $modified_time = get_the_modified_time( 'H:i', $post_id ); + $modified_at = sprintf( + /* translators: %1$s is the modification date, %2$s is the modification time. */ + __( '%1$s at %2$s', 'sunflower' ), + $modified_date, + $modified_time + ); + + printf( + '%1$s
%2$s', + esc_html( $user_name ), + esc_html( $modified_at ) + ); +} + +add_action( 'manage_posts_custom_column', 'sunflower_fill_modified_by_column', 10, 2 ); +add_action( 'manage_pages_custom_column', 'sunflower_fill_modified_by_column', 10, 2 ); +add_action( 'manage_sunflower_event_posts_custom_column', 'sunflower_fill_modified_by_column', 10, 2 ); + /** * Add footer note to all backend pages. */ diff --git a/languages/de_DE.mo b/languages/de_DE.mo index aff3a203..afb433a9 100644 Binary files a/languages/de_DE.mo and b/languages/de_DE.mo differ diff --git a/languages/de_DE.po b/languages/de_DE.po index dd5b6c61..304cec0a 100644 --- a/languages/de_DE.po +++ b/languages/de_DE.po @@ -1424,3 +1424,15 @@ msgstr "" #~ msgctxt "block title" #~ msgid "Accordion (Sunflower)" #~ msgstr "Akkordeon (Sunflower)" +#: functions/admin.php +msgid "Last modified" +msgstr "Zuletzt geƤndert" + +#: functions/admin.php +msgid "Unknown" +msgstr "Unbekannt" + +#. translators: %1$s is the modification date, %2$s is the modification time. +#: functions/admin.php +msgid "%1$s at %2$s" +msgstr "%1$s um %2$s Uhr" diff --git a/languages/sunflower.pot b/languages/sunflower.pot index 1a327fa8..1fd3fae7 100644 --- a/languages/sunflower.pot +++ b/languages/sunflower.pot @@ -1218,3 +1218,15 @@ msgstr "" msgctxt "Font family name" msgid "GrueneType Neue" msgstr "" +#: functions/admin.php +msgid "Last modified" +msgstr "" + +#: functions/admin.php +msgid "Unknown" +msgstr "" + +#. translators: %1$s is the modification date, %2$s is the modification time. +#: functions/admin.php +msgid "%1$s at %2$s" +msgstr ""