Files
WP-LIT-MCP/src/Integrations/WordPress/RevisionPoint.php
T

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;
}
}