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
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b991d35
After switching themes, delete all pm_pattern posts
kienstra 2715663
Add PHP DocBlocks summaries
kienstra d20337b
Extract 'pm_pattern' into a function
kienstra 81f1563
Add a return type to get_pattern_post_type()
kienstra 10bb02c
Call the new util function in pattern-data-handlers.php
kienstra d96d1ff
Fix a PHP error
kienstra bc87840
Prevent confusion between names
kienstra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
namespace PatternManager\PatternPostType; | ||
|
||
use WP_Post; | ||
use WP_Query; | ||
use function PatternManager\PatternDataHandlers\get_pattern_by_name; | ||
use function PatternManager\PatternDataHandlers\get_theme_patterns; | ||
use function PatternManager\PatternDataHandlers\delete_pattern; | ||
|
@@ -238,3 +239,27 @@ function redirect_pattern_actions() { | |
} | ||
} | ||
add_action( 'admin_init', __NAMESPACE__ . '\redirect_pattern_actions' ); | ||
|
||
function get_pm_post_ids() { | ||
return ( new WP_Query( | ||
[ | ||
'post_type' => 'pm_pattern', | ||
'post_status' => 'any', | ||
'fields' => 'ids', | ||
'posts_per_page' => 10, | ||
] | ||
) )->posts; | ||
} | ||
|
||
function delete_pattern_posts() { | ||
$post_ids = get_pm_post_ids(); | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. The 2nd |
||
} | ||
|
||
$post_ids = get_pm_post_ids(); | ||
} | ||
} | ||
add_action( 'after_switch_theme', __NAMESPACE__ . '\delete_pattern_posts' ); |
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.
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.