Delete Old Contact Form 7 Messages Stored in Flamingo
Permanently deletes contact form messages saved by the Flamingo add-on once they are older than 180 days, so old enquiries and their personal data are not kept forever.
Opens WPIDE on
Code
// Days to keep stored messages.
$wpide_flamingo_days = 180;
add_action( 'init', function () {
if ( post_type_exists( 'flamingo_inbound' ) && ! wp_next_scheduled( 'wpide_flamingo_retention' ) ) {
wp_schedule_event( time() + HOUR_IN_SECONDS, 'daily', 'wpide_flamingo_retention' );
}
}, 20 );
add_action( 'wpide_flamingo_retention', function () use ( $wpide_flamingo_days ) {
if ( ! post_type_exists( 'flamingo_inbound' ) ) {
return;
}
$ids = get_posts( array(
'post_type' => 'flamingo_inbound',
'post_status' => 'any',
'posts_per_page' => 200,
'fields' => 'ids',
'no_found_rows' => true,
'date_query' => array( array( 'before' => $wpide_flamingo_days . ' days ago' ) ),
) );
foreach ( $ids as $id ) {
wp_delete_post( $id, true );
}
} );
Notes
Requires the Flamingo plugin alongside Contact Form 7; nothing happens if Flamingo is not active.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.