Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01At3V6SjwbMe6eMzVGW3Hs7
30 lines
848 B
PHP
30 lines
848 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace LIT\MCP\Integrations\WordPress;
|
|
|
|
/**
|
|
* Restore point before a change (spec §2 principle 7): WordPress stores the
|
|
* current state as a revision (only if it differs from the newest one) and the
|
|
* newest revision ID is returned as revision_id of the ToolResult.
|
|
* Note: revisions cover title, content and excerpt; meta and terms are not revisioned.
|
|
*/
|
|
final class RevisionPoint
|
|
{
|
|
public static function capture(int $postId): ?int
|
|
{
|
|
wp_save_post_revision($postId);
|
|
|
|
return self::latest($postId);
|
|
}
|
|
|
|
public static function latest(int $postId): ?int
|
|
{
|
|
$revisions = wp_get_post_revisions($postId, ['posts_per_page' => 1]);
|
|
$newest = is_array($revisions) ? reset($revisions) : false;
|
|
|
|
return is_object($newest) ? (int) $newest->ID : null;
|
|
}
|
|
}
|