-
-
Save promotion/82ba346d8e27c5074f4fd67b2c91be1a to your computer and use it in GitHub Desktop.
Delete Contact Form 7 Flamingo submissions - Easily delete a large number of Flamingo (Contact Form 7) messages. https://www.damiencarbery.com/2020/03/delete-contact-form-7-flamingo-submissions/
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
<?php $time_start = microtime(true); ?> | |
<!DOCTYPE html> | |
<html lang="en-US"> | |
<head> | |
<meta charset="UTF-8" /> | |
<title>Delete Flamingo messages and contacts</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1" /> | |
</head> | |
<body> | |
<h1>Delete Flamingo messages and contacts</h1> | |
<?php | |
define('WP_USE_THEMES', false); | |
require( dirname( __FILE__ ) . '/wp-blog-header.php' ); | |
$args = array('post_type'=> array( 'flamingo_inbound', 'flamingo_contact', 'flamingo_outbound' ), | |
'fields' => 'ids', | |
'post_status' => array( 'publish', 'trash' ), | |
'posts_per_page' => 200, | |
'no_found_rows' => true, | |
'update_post_term_cache' => false, | |
'update_post_meta_cache' => false); | |
$flamingo_msgs = new WP_Query($args); | |
$msgs_ids = array(); | |
// No need for a loop because we only requested the 'id' field! | |
$msgs_ids = $flamingo_msgs->posts; | |
wp_reset_postdata(); | |
// Display the product IDs | |
echo '<ul>'; | |
foreach ( $msgs_ids as $msg_id ) { | |
if ( null == wp_delete_post( $msg_id, true ) ) { | |
echo "<li>Error deleting item ID: $msg_id </li>"; | |
} | |
else { | |
echo "<li>$msg_id deleted</li>"; | |
} | |
} | |
echo '</ul>'; | |
// Display some stats - for fun. | |
echo '<p>Memory usage: ', intval(memory_get_usage() / (1024 * 1024)), "MB\n"; | |
echo '<br />Peak memory usage: ', intval(memory_get_peak_usage() / (1024 * 1024)), "MB</p>\n"; | |
$time_end = microtime(true); | |
$time = $time_end - $time_start; | |
echo "<p>Process Time: {$time} seconds.</p>"; | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment