Skip to content

Add Created, Created by, Last edited, Last edited by columns#38

Merged
priethor merged 4 commits into
mainfrom
priethor/add/system-fields
Apr 30, 2026
Merged

Add Created, Created by, Last edited, Last edited by columns#38
priethor merged 4 commits into
mainfrom
priethor/add/system-fields

Conversation

@priethor

@priethor priethor commented Apr 30, 2026

Copy link
Copy Markdown
Collaborator

What

Part of #99

Adds Created, Created by, Last edited, and Last edited by as read-only columns. Default-hidden, addable from the column visibility menu.

Why

The block didn't expose who created or last edited a row.

How

  • save_post hook on entry CPTs writes _modified_by post meta. Skipped when no user is signed in, so CLI and cron writes don't clobber it with 0.

  • format_row returns the four keys (RFC3339 UTC timestamps and resolved display names). cache_users primes once per page so name lookup stays at two queries regardless of row count.

  • validate_fields splits into sort-context and filter-context helpers; without the split, a filter on created_at would no-op through meta_query.

Testing

  1. wp cortext seed --reset --force.
  2. Open a seeded collection. Toggle the four system fields on via View options.
  3. Cells render formatted dates and a display name; clicking doesn't open an editor.
  4. Sort by Created or Last edited works; _by columns expose no sort.
  5. Edit a row as a second user. Last edited by switches; Created by stays.
  6. wp post update <id> --post_title="cli edit". Last edited by stays at the previous editor.

WP core stores when a post was last modified, but not who. A save_post
hook on entry CPTs records the current user ID. Skipped when no user is
signed in, so CLI and cron writes don't overwrite the real editor with
0.
`format_row` emits `created_at` and `modified_at` as RFC3339 UTC plus
the resolved display names for `created_by` and `modified_by`. A
one-shot `cache_users` prime keeps name lookup at two queries regardless
of row count.

`validate_fields` splits into sort-context and filter-context helpers so
`created_at` and `modified_at` can be sorted but no system field is
silently routed through `meta_query` as a filter. Sort branches map
`created_at` to `orderby: 'date'` and `modified_at` to
`orderby: 'modified'`.
Appends four system fields to `useCollectionFields` with `editable:
false` (PR A's seed effect leaves them default-hidden) and
`enableSorting` only on the timestamps. Cells render plain spans, not
EditableCell, so they're never editable in place.

Sort on the `_by` columns is deferred to RSM-1793 alongside relations
and rollups: stored value is a user ID, useful sort is on the displayed
name, and the same shape applies to all display-value properties. Tech
debt entries cover that, plus `_modified_by` being plugin-stored and
system-field filtering being deferred.
`wp_insert_post` defaults `post_author` to `get_current_user_id()`, which
is 0 in CLI context, so seeded entries had no author. Set the current
user to the first administrator at the start of the seed so seeded rows
demo the Created by / Last edited by columns instead of showing empty
cells.
@priethor priethor marked this pull request as ready for review April 30, 2026 11:56
@priethor priethor merged commit 2f76997 into main Apr 30, 2026
6 checks passed
@priethor priethor deleted the priethor/add/system-fields branch April 30, 2026 11:58
priethor added a commit that referenced this pull request May 1, 2026
WordPress runs the_title filter on title.rendered (wptexturize, HTML
entity encoding), which converts & to &#38; and similar. JSX
auto-escapes text children, so the entity makes it through the render
verbatim and the column header reads 'Date &#38; time' instead of
'Date & time'. Prefer title.raw, which carries the unfiltered string.
priethor added a commit that referenced this pull request May 1, 2026
The Title column's getValue still preferred title.rendered, which
WordPress runs through the_title (encoding & as &#38; among other
substitutions). That made sort comparisons sort by the literal
entity. mapField was already fixed; this brings TITLE_FIELD in line.

Also adds a unit test asserting mapField returns the raw title for
the column label, so a future refactor can't silently flip the
preference back.
@priethor priethor added this to the 0.1.0 milestone May 28, 2026
@priethor priethor added type: enhancement Improvement to existing behavior. area: collections Fields, rows, views, DataViews, relations, rollups, formulas, and row properties. labels May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: collections Fields, rows, views, DataViews, relations, rollups, formulas, and row properties. type: enhancement Improvement to existing behavior.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant