Skip to content

Commit af620a2

Browse files
Copilotswissspidy
andcommitted
Handle null return value from wp_restore_post_revision and improve error handling
Co-authored-by: swissspidy <[email protected]>
1 parent 598c559 commit af620a2

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/Post_Revision_Command.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ public function restore( $args ) {
7070
// Restore the revision
7171
$restored_post_id = wp_restore_post_revision( $revision_id );
7272

73-
if ( false === $restored_post_id ) {
73+
// wp_restore_post_revision() returns post ID on success, false on failure, or null if revision is same as current
74+
if ( ! $restored_post_id ) {
7475
WP_CLI::error( "Failed to restore revision {$revision_id}." );
7576
}
7677

@@ -146,6 +147,8 @@ public function diff( $args, $assoc_args ) {
146147
if ( ! isset( $from_revision->{$field} ) ) {
147148
WP_CLI::error( "Field '{$field}' not found on revision {$from_id}." );
148149
}
150+
151+
// $to_revision is guaranteed to be non-null at this point due to earlier validation
149152
if ( ! isset( $to_revision->{$field} ) ) {
150153
$to_error_id = $to_id ?? $to_revision->ID;
151154
WP_CLI::error( "Field '{$field}' not found on revision/post {$to_error_id}." );

0 commit comments

Comments
 (0)