This repository has been archived by the owner on Oct 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
After switching themes, delete all pm_pattern
posts
#62
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kienstra
commented
Feb 20, 2023
@@ -238,3 +239,27 @@ function redirect_pattern_actions() { | |||
} | |||
} | |||
add_action( 'admin_init', __NAMESPACE__ . '\redirect_pattern_actions' ); | |||
|
|||
function get_pm_post_ids() { |
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 is a separate function so we don't have to have a single query with a 'posts_per_page'
that might not get all of the posts.
We can keep calling this in the while
loop until there aren't any more posts.
kienstra
commented
Feb 20, 2023
|
||
while( ! empty( $post_ids ) ) { | ||
foreach ( $post_ids as $post_id ) { | ||
wp_delete_post( $post_id, true ); |
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.
The 2nd true
argument bypasses putting the post in the trash.
kienstra
commented
Feb 20, 2023
require_once module_dir_path( __FILE__ ) . 'utils.php'; | ||
require_once module_dir_path( __FILE__ ) . 'model.php'; |
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.
Prevents a PHP error from get_pattern_post_type()
not being defined.
johnstonphilip
approved these changes
Feb 21, 2023
Thanks a lot, @johnstonphilip! |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes part of #57 (When theme is changed, delete all pm_pattern posts (these are not needed as we pull from files)
How to test
/wp-admin/admin.php?page=pattern-manager
wp post list --post_type=pm_pattern
wp post list --post_type=pm_pattern
patterns/
directory are still there