-
Notifications
You must be signed in to change notification settings - Fork 5
Fix renaming bug where there were 2 patterns #61
Conversation
@@ -110,8 +109,8 @@ function save_metadata_to_pattern_file( $override, $post_id, $meta_key, $meta_va | |||
] | |||
); | |||
|
|||
if ( $previous_value && $previous_value !== $meta_value ) { | |||
delete_pattern( $meta_value ); | |||
if ( $pattern_name !== $meta_value ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$pattern_name
is a more reliable previous pattern name. Every time we're in the editor, there will be a pm_pattern
post with a ->post_title
(the pattern name).
@@ -173,16 +172,13 @@ function redirect_pattern_actions() { | |||
} | |||
|
|||
if ( 'edit-pattern' === filter_input( INPUT_GET, 'action' ) ) { | |||
// Prevent the hook from overwriting the file when this post is created. | |||
remove_action( 'rest_after_insert_pm_pattern', __NAMESPACE__ . '\save_pattern_to_file' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated, but removes a hack I added that's not needed anymore, thanks to Phil's rest_insert_
hook.
if ( $previous_value && $previous_value !== $meta_value ) { | ||
delete_pattern( $meta_value ); | ||
if ( $pattern_name !== $meta_value ) { | ||
delete_pattern( $pattern_name ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the bug (which I created).
$meta_value
was the new pattern name, where it should have deleted the old name.
Thanks a lot, @johnstonphilip! |
Before
Renaming (changing the title) of a pattern resulted in 2 patterns. One pattern with the new name, and a pattern with the old name.
After
This deletes the pattern with the old name.
Fixes part of #57 (Renaming a pattern creates a new copy)
How to test
patterns/
directory only has a pattern with the new name, not the old name: