Skip to content

Instantly share code, notes, and snippets.

@foliovision
Created May 24, 2016 14:50
Show Gist options
  • Save foliovision/3aa64abf1bc0378e34bf3376019b3461 to your computer and use it in GitHub Desktop.
Save foliovision/3aa64abf1bc0378e34bf3376019b3461 to your computer and use it in GitHub Desktop.
bbPress 1 to bbPress 2 cleanup tool
<?php
/*
Please read the bbPress 1 conversion article on foliovision.com before using
*/
include('wp-load.php');
global $wpdb;
$aPosts = $wpdb->get_results( "SELECT * FROM $wpdb->posts AS p JOIN $wpdb->postmeta AS m ON p.ID = m.post_id WHERE post_type IN ('forum','topic','reply') AND ( meta_key = '_bbp_old_topic_id' ) LIMIT 10000 " );
// Hint: take this from step 2.
$aDeleted = array(1,2,3,4,...);
foreach( $aPosts AS $objPost ) {
$action = false;
if( in_array($objPost->meta_value,$aDeleted) ) {
$action = 'delete';
$wpdb->query( "UPDATE $wpdb->posts SET post_status = 'trash' WHERE ID = '{$objPost->ID}'" );
}
if( $action ) {
echo $objPost->ID.' '.$objPost->post_title.' '.$objPost->meta_value.' '.$objPost->post_status." will be ".$action."\n";
}
}
echo "=====\n\n\n";
// Hint: take this from step 1.
$aModerated = array(1,2,3,4,...);
$aPosts = $wpdb->get_results( "SELECT * FROM $wpdb->posts AS p JOIN $wpdb->postmeta AS m ON p.ID = m.post_id WHERE post_type IN ('forum','topic','reply') AND ( meta_key = '_bbp_post_id' ) ORDER BY meta_value LIMIT 10000 " );
foreach( $aPosts AS $objPost ) {
$action = false;
if( in_array($objPost->meta_value,$aModerated) ) {
$action = 'moderated';
$wpdb->query( "UPDATE $wpdb->posts SET post_status = 'pending' WHERE ID = '{$objPost->ID}'" );
}
if( $action ) {
echo $objPost->ID.' '.$objPost->post_title.' '.$objPost->meta_value.' '.$objPost->post_status." will be ".$action."\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment