File tree Expand file tree Collapse file tree 1 file changed +32
-9
lines changed
Expand file tree Collapse file tree 1 file changed +32
-9
lines changed Original file line number Diff line number Diff line change 11<?php
22
3- use WP_CLI \Fetchers \Post as PostFetcher ;
43use WP_CLI \Utils ;
54
65/**
1918 */
2019class Post_Revision_Command {
2120
22- private $ fetcher ;
23-
24- public function __construct () {
25- $ this ->fetcher = new PostFetcher ();
26- }
21+ /**
22+ * Valid post fields that can be compared.
23+ *
24+ * @var array<string>
25+ */
26+ private $ valid_fields = [
27+ 'post_title ' ,
28+ 'post_content ' ,
29+ 'post_excerpt ' ,
30+ 'post_name ' ,
31+ 'post_status ' ,
32+ 'post_type ' ,
33+ 'post_author ' ,
34+ 'post_date ' ,
35+ 'post_date_gmt ' ,
36+ 'post_modified ' ,
37+ 'post_modified_gmt ' ,
38+ 'post_parent ' ,
39+ 'menu_order ' ,
40+ 'comment_status ' ,
41+ 'ping_status ' ,
42+ ];
2743
2844 /**
2945 * Restores a post revision.
@@ -122,11 +138,18 @@ public function diff( $args, $assoc_args ) {
122138 }
123139
124140 // Validate field
125- if ( ! property_exists ( $ from_revision , $ field ) || ! property_exists ( $ to_revision , $ field ) ) {
126- WP_CLI ::error ( "Invalid field ' {$ field }'. " );
141+ if ( ! in_array ( $ field , $ this ->valid_fields , true ) ) {
142+ WP_CLI ::error ( "Invalid field ' {$ field }'. Valid fields: " . implode ( ', ' , $ this ->valid_fields ) );
143+ }
144+
145+ // Get the field values - use isset to check if field exists on the object
146+ if ( ! isset ( $ from_revision ->{$ field } ) ) {
147+ WP_CLI ::error ( "Field ' {$ field }' not found on revision {$ from_id }. " );
148+ }
149+ if ( ! isset ( $ to_revision ->{$ field } ) ) {
150+ WP_CLI ::error ( "Field ' {$ field }' not found on revision/post {$ to_id }. " );
127151 }
128152
129- // Get the field values
130153 $ left_string = $ from_revision ->{$ field };
131154 $ right_string = $ to_revision ->{$ field };
132155
You can’t perform that action at this time.
0 commit comments