Skip to content

Add wp post revision restore, diff, and prune commands#563

Merged
swissspidy merged 19 commits intomainfrom
copilot/add-post-revision-commands
Feb 15, 2026
Merged

Add wp post revision restore, diff, and prune commands#563
swissspidy merged 19 commits intomainfrom
copilot/add-post-revision-commands

Conversation

Copy link
Contributor

Copilot AI commented Jan 12, 2026

Implementation Plan for Post Revision Commands

  • Explore repository structure and understand existing patterns
  • Create Post_Revision_Command.php file with three commands:
    • wp post revision restore <post_id> - Restore a revision with the given ID
    • wp post revision diff <from> <to> - Compare/diff two revisions with CLI-friendly colored output
    • wp post revision prune [<post-ids>...] [--latest=<limit>] [--earliest=<limit>] - Delete old revisions
  • Register the command in entity-command.php
  • Add command to composer.json commands list
  • Create Behat feature tests for all commands
  • Address all code review feedback
  • Fix incomplete test scenario for diff between two revisions
  • Replace HTML diff output with CLI-friendly colored output
  • All code quality checks passing ✓

Latest Changes

Addressed code review feedback from @swissspidy:

  1. Handle null return from wp_restore_post_revision(): Now shows a warning message when revision is identical to current post instead of misleading success message
  2. Extract duplicate logic: Added get_post_or_revision() helper method to reduce code duplication
  3. Use instanceof for type checking: Replaced switch/get_class() with instanceof checks for more robust type checking

Commands

wp post revision restore <revision_id>

Restores a post to the specified revision using WordPress's native wp_restore_post_revision().

wp post revision restore 123
# Success: Restored revision 123.
# Or: Warning: Revision 123 is the same as the current post. No action taken.

wp post revision diff <from> [<to>] [--field=<field>]

Compares revision content using CLI-friendly colored diff output. Auto-detects parent post when <to> is omitted.

# Compare two revisions
wp post revision diff 123 456

# Compare revision with current post
wp post revision diff 123

# Compare specific fields
wp post revision diff 123 456 --field=post_title

wp post revision prune [<post-ids>...] [--latest=<limit>] [--earliest=<limit>]

Deletes old post revisions while keeping a specified number of latest or earliest revisions.

# Delete all but the latest 5 revisions for post 123
wp post revision prune 123 --latest=5

# Delete all but the latest 5 revisions for all posts
wp post revision prune --latest=5 --yes

# Delete all but the earliest 2 revisions for posts 123 and 456
wp post revision prune 123 456 --earliest=2

Features:

  • If <post-ids> is provided, flags apply individually to those posts only
  • If <post-ids> is not provided, flags apply to all posts individually
  • Requires confirmation when processing multiple posts (use --yes to skip)
  • Must specify either --latest or --earliest flag (cannot use both)
  • Provides detailed feedback on number of revisions deleted per post

Diff Output

The diff command displays changes with color coding:

  • Red lines with - prefix = Deleted lines
  • Green lines with + prefix = Added lines
  • Default color with prefix = Unchanged lines
  • Yellow header lines = Revision metadata (title, date, ID)

Example output:

--- Original Post (2024-01-01 12:00:00) - ID 123
+++ Modified Post (2024-01-02 13:00:00) - ID 456

  Line 1
- Line 2
+ Line 2 modified
  Line 3

Supports 15 post fields: post_title, post_content, post_excerpt, post_name, post_status, post_type, post_author, post_date, post_date_gmt, post_modified, post_modified_gmt, post_parent, menu_order, comment_status, ping_status.

Implementation

  • src/Post_Revision_Command.php: Command class with restore, diff, and prune subcommands
  • entity-command.php: Registers post revision namespace
  • composer.json: Adds command entries for autocompletion
  • phpcs.xml.dist: Excludes new command from prefix rules
  • features/post-revision.feature: 12 comprehensive test scenarios covering all commands

Ready for merge.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@github-actions github-actions bot added command:post Related to 'post' command command:post-list Related to 'post list' command command:post-meta Related to 'post meta' command command:post-meta-get Related to 'post meta get' command command:post-meta-update Related to 'post meta update' command labels Jan 12, 2026
Copilot AI and others added 4 commits January 12, 2026 12:50
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
…sed property

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
…ror handling

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Add commands for restoring and diffing post revisions Add wp post revision restore and diff commands Jan 12, 2026
Copilot AI requested a review from swissspidy January 12, 2026 12:59
@codecov
Copy link

codecov bot commented Jan 12, 2026

Codecov Report

❌ Patch coverage is 80.12821% with 31 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/Post_Revision_Command.php 80.12% 31 Missing ⚠️

📢 Thoughts on this report? Let us know!

This comment was marked as resolved.

swissspidy and others added 3 commits January 13, 2026 12:27
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
@swissspidy

This comment was marked as resolved.

@swissspidy swissspidy marked this pull request as ready for review January 16, 2026 21:06
@swissspidy swissspidy requested a review from a team as a code owner January 16, 2026 21:06
@swissspidy swissspidy removed command:post-meta Related to 'post meta' command command:post-list Related to 'post list' command command:post-meta-get Related to 'post meta get' command command:post-meta-update Related to 'post meta update' command labels Jan 21, 2026
@swissspidy swissspidy added this to the 2.9.0 milestone Jan 21, 2026
@swissspidy

This comment was marked as resolved.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

Copilot AI changed the title Add wp post revision restore and diff commands Add wp post revision restore, diff, and prune commands Jan 25, 2026
@swissspidy swissspidy linked an issue Jan 26, 2026 that may be closed by this pull request
Copy link
Member

@thelovekesh thelovekesh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes looks good to me.

@swissspidy

This comment was marked as resolved.

gemini-code-assist[bot]

This comment was marked as resolved.

…e instanceof

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI requested a review from swissspidy February 15, 2026 18:14
@swissspidy swissspidy merged commit 7400871 into main Feb 15, 2026
61 of 62 checks passed
@swissspidy swissspidy deleted the copilot/add-post-revision-commands branch February 15, 2026 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command:post Related to 'post' command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wp post revisions

3 participants