Bulk-move bbPress topics
-
could we possibly to have Bulk-move bbPress topics soon?
users post on wrong forum all the time, we really need function
-
You cannot do this at the time. There is a ticket to hopefully add this feature to bulk edit topics into different forums in the future.
https://bbpress.trac.wordpress.org/ticket/1838
This is where it would be in Topics > All Topics in the WordPress backend, just show/change the parent forum with a dropdown like when you edit a single topic right there.
There have been a few tickets in WordPress itself to make it easier without a workaround with javascript lately so hopefully that will help get this type of feature in soon.
yes , like moving several posts from forum A to forum B
Well, I have something that COULD help you. Let me see if I can extract it and put it somewhere on my site. It worked for me, but is pure database access ! So you will have to make a full backup of your site before and maybe review the code to make sure it works on your environment. So no guarantees !
But I’m busy on another project now, so I might need some days/weeks, depending of how fast I go with the current one.
Pascal.
that will be helpful, thanks!
Any contributions to that ticket would be much appreciated.
Any other participation in the bbPress project would be much appreciated also.
For this ticket, I have the logic on paper what is needed and part of the code already in one of my projects. But need to finish some stuff for the association first.
For the participation part, I’m helping in the forum and will stick to that for now. But any bbPress developer can have a look at my code of course to get inspiration 🙂
But we can have a chat about it, no problem.
Pascal.Alright, I am just pointing it out there if you are interested to participate/contribute in other ways.
Helping in the forums definately helps me out, and thanks for that.
Hello,
We have done this… we are still testing it. Be careful use VPS:
<?php
/**
* Now that you have your custom column, it’s bulk/quick edit showtime!
* The filters are ‘bulk_edit_custom_box’ and ‘quick_edit_custom_box’. Both filters
* pass the same 2 arguments: the $column_name (a string) and the $post_type (a string).
*
* Your data’s form fields will obviously vary so customize at will. For this example,
* we’re using an input. Also take note of the css classes on the <fieldset> and <div>.
* There are a few other options like ‘inline-edit-col-left’ and ‘inline-edit-col-center’
* for the fieldset and ‘inline-edit-col’ for the div. I recommend studying the WordPress
* bulk and quick edit HTML to see the best way to layout your custom fields.
*/
add_action( ‘bulk_edit_custom_box’, ‘manage_wp_posts_be_qe_bulk_quick_edit_custom_box’, 10, 2 );
//add_action( ‘quick_edit_custom_box’, ‘manage_wp_posts_be_qe_bulk_quick_edit_custom_box’, 10, 2 );
function manage_wp_posts_be_qe_bulk_quick_edit_custom_box( $column_name, $post_type ) {switch ( $post_type ) {
case ‘topic’:
switch( $column_name ) {
case ‘bbp_topic_forum’:
?><fieldset class=”inline-edit-col-left”>
<div class=”inline-edit-col”>
<label>
<span class=”title”>Deplacer dans le forum</span>
<span class=”input-text-wrap”>
<select name=”deplacer”>
<option value=”Null”></option>
<?php /* recuperation des forums “forum” */
$args = array(
// ‘post_parent__not_in’=> array( 0 ) ,
‘post_type’ => ‘forum’
);
$forums = new WP_Query( $args );
// boucle de test affiche en debug id et titre forum
if ( $forums->have_posts() ) {
while ( $forums->have_posts() ) {
$forums->the_post();
echo ‘<option value=”‘.$forums->post->ID.'”>’.get_the_title() . ‘</option>’ ;
}
}
wp_reset_postdata();?></select>
</span>
</label>
</div>
</fieldset><?php
break;
}
break;
}
}/**
* When you click ‘Quick Edit’, you may have noticed that your form fields are not populated.
* WordPress adds one ‘Quick Edit’ row which moves around for each post so the information cannot
* be pre-populated. It has to be populated with JavaScript on a per-post ‘click Quick Edit’ basis.
*
* WordPress has an inline edit post function that populates all of their default quick edit fields
* so we want to hook into this function, in a sense, to make sure our JavaScript code is run when
* needed. We will ‘copy’ the WP function, ‘overwrite’ the WP function so we’re hooked in, ‘call’
* the original WP function (via our copy) so WordPress is not left hanging, and then run our code.
*
* Remember where we wrapped our column data in a <div> in Step 2? This is where it comes in handy,
* allowing our Javascript to retrieve the data by the <div>’s element ID to populate our form field.
* There are other methods to retrieve your data that involve AJAX but this route is the simplest.
*
* Don’t forget to enqueue your script and make sure it’s dependent on WordPress’s ‘inline-edit-post’ file.
* Since we’ll be using the jQuery library, we need to make sure ‘jquery’ is loaded as well.
*
* I have provided several scenarios for where you’ve placed this code. Simply uncomment the scenario
* you’re using. For all scenarios, make sure your javascript file is in the same folder as your code.
*/
add_action( ‘admin_print_scripts-edit.php’, ‘manage_wp_posts_be_qe_enqueue_admin_scripts’ );
function manage_wp_posts_be_qe_enqueue_admin_scripts() {// if code is in theme functions.php file
wp_enqueue_script( ‘manage-wp-posts-using-bulk-quick-edit’, trailingslashit( get_bloginfo( ‘stylesheet_directory’ ) ) . ‘js/bulk_quick_edit.js’, array( ‘jquery’, ‘inline-edit-post’ ), ”, true );// if using code as plugin
//wp_enqueue_script( ‘manage-wp-posts-using-bulk-quick-edit’, trailingslashit( plugin_dir_url( __FILE__ ) ) . ‘js/bulk_quick_edit.js’, array( ‘jquery’, ‘inline-edit-post’ ), ”, true );}
add_action( ‘save_post’, ‘save_deplacer’);
function save_deplacer() {
global $wpdb;if( $_GET[‘post_type’]=’topic’ && $_GET[‘bulk_edit’]=’Mettre Ă jour’){
$post_ids= $_GET[‘post’];
$forum_id = $_GET[‘deplacer’];
foreach($post_ids as $post_id){$wpdb->query(“UPDATE $wpdb->posts SET post_parent = $forum_id WHERE ID = $post_id “);
}
}
}
/*echo ‘'; print_r($post_type); echo '
‘;
die();Array
(
[s] =>
[post_status] => all
[post_type] => topic
[_wpnonce] => dcfdf56a2d
[_wp_http_referer] => /public/wptest/wp-admin/edit.php?post_type=topic&paged=1
[action] => edit
[m] => 0
[bbp_forum_id] =>
[paged] => 1
[mode] => excerpt
[_status] => -1
[tax_input] => Array
(
[topic-tag] =>
)[Deplacer] => 39
[bulk_edit] => Mettre Ă jour
[post_view] => excerpt
[screen] => edit-topic
[post] => Array
(
[0] => 43
[1] => 41
)[action2] => -1
)*//**
* Step 3: display an admin notice on the Posts page after deplacer
*/
add_action(‘admin_notices’, ‘custom_bulk_admin_notices’);
function custom_bulk_admin_notices() {
global $post_type, $pagenow ;if( $_GET[‘post_type’]=’topic’ && $_GET[‘bulk_edit’]=’Mettre Ă jour’){
$messages = array();
$messages[] = bbp_admin_repair_forum_meta();
$messages[] = bbp_admin_repair_topic_meta();
$messages[] = bbp_admin_repair_freshness();
$messages[] = bbp_admin_repair_reply_menu_order();
$messages[] = bbp_admin_repair_forum_topic_count();
$messages[] = bbp_admin_repair_forum_reply_count();
$messages[] = bbp_admin_repair_topic_reply_count();
$messages[] = bbp_admin_repair_topic_voice_count();
$messages[] = bbp_admin_repair_user_topic_count();
$messages[] = bbp_admin_repair_user_reply_count();//if($pagenow == ‘edit.php’ && $post_type == ‘topic’ && isset($_GET[‘deplacer’])) {
$messageori = sprintf( _n( ‘Topic dĂ©placĂ©.’, ‘%s topics dĂ©placĂ©s.’, $_REQUEST[‘deplacer’] ), number_format_i18n( $_REQUEST[‘deplacer’] ) );
foreach ($messages as $message){
echo'<div class=\”updated\”><p>’.$message[1].'</p></div>’;
}
echo “<div class=\”updated\”><p>{$messageori}</p></div>”;
}
}?>
Very first version of my plugin uploaded in the WP queue today. Will report here when you can start testing.
You ask, you get ! Here you go : https://wordpress.org/plugins/bbp-move-topics/
Please check the sticky topics on the support tab for upcoming things.
Try it and PLEASE let me know how it goes (if bad: support tab, if good: review).
For all suggestions or issues about the plugin, make sure to use the support tab there and NOT this global thread anymore.Enjoy the moves,
Pascal.Hi,
Here is the code that we use with the child theme. As we run a large forum, we must modify some setting of the server but we use a VPS.
<?php add_action( 'bulk_edit_custom_box', 'manage_wp_posts_be_qe_bulk_quick_edit_custom_box', 10, 2 ); function manage_wp_posts_be_qe_bulk_quick_edit_custom_box( $column_name, $post_type ) { switch ( $post_type ) { case 'topic': switch( $column_name ) { case 'bbp_topic_forum': ?><fieldset class="inline-edit-col-left"> <div class="inline-edit-col"> <label> <span class="title">Deplacer dans le forum</span> <span class="input-text-wrap"> <select name="deplacer"> <option value="Null"></option> <?php /* recuperation des forums "forum" */ $args = array( 'post_parent__not_in'=> array( 0 ) , 'post_type' => 'forum' ); $forums = new WP_Query( $args ); // boucle forum if ( $forums->have_posts() ) { while ( $forums->have_posts() ) { $forums->the_post(); echo '<option value="'.$forums->post->ID.'">'.get_the_title() . '</option>' ; } } wp_reset_postdata();?> </select> </span> </label> </div> </fieldset><?php break; } break; } } /* lance le javascript */ add_action( 'admin_print_scripts-edit.php', 'manage_wp_posts_be_qe_enqueue_admin_scripts' ); function manage_wp_posts_be_qe_enqueue_admin_scripts() { wp_enqueue_script( 'manage-wp-posts-using-bulk-quick-edit', trailingslashit( get_bloginfo( 'stylesheet_directory' ) ) . 'js/bulk_quick_edit.js', array( 'jquery', 'inline-edit-post' ), '', true ); } /* enregistre modif forum et repare */ add_action( 'save_post', 'save_deplacer'); function save_deplacer() { global $wpdb; if( $_GET['post_type']='topic' && $_GET['bulk_edit']='Mettre à jour'){ $post_ids= $_GET['post']; $forum_id = $_GET['deplacer']; foreach($post_ids as $post_id){ $wpdb->query("UPDATE wp_posts SET post_parent = $forum_id WHERE ID = $post_id "); } $messages = array(); $messages[] = bbp_admin_repair_forum_meta(); // $messages[] = bbp_admin_repair_topic_meta(); $messages[] = bbp_admin_repair_freshness(); // $messages[] = bbp_admin_repair_reply_menu_order(); $messages[] = bbp_admin_repair_forum_topic_count(); $messages[] = bbp_admin_repair_forum_reply_count(); // $messages[] = bbp_admin_repair_topic_reply_count(); // $messages[] = bbp_admin_repair_topic_voice_count(); // $messages[] = bbp_admin_repair_user_topic_count(); // $messages[] = bbp_admin_repair_user_reply_count(); $messageori = sprintf( _n( 'Topic déplacé.', '%s topics déplacés.', $_REQUEST['deplacer'] ), number_format_i18n( $_REQUEST['deplacer'] ) ); foreach ($messages as $message){ echo'<div class=\"updated\"><p>'.$message[1].'</p></div>'; } echo "<div class=\"updated\"><p>{$messageori}</p></div>"; } } ?>
Do you think this is a right way? Is there a way to improve it?
I thank you in advance
Regards
Mei Ling
Thanks for sharing!!
This is exactly like what I said earlier. I will need to check this out and see if it needs more improvements in the code, and create a patch for bbPress if in the ticket.
Just note that you will have the same issue with the freshness like in my plugin as long as the repair fresness function is not patched.
Pascal.Just in case anyone needs to alter the forum of topics manually with PHP:
1. Find the Forum ID you’re moving topics to.
2. Create a function to search for your required topics and set the ‘post_parent’ as the forum ID. (sample below)
3. Set the topic’s post meta fields ‘bbp_topic_forum’, ‘_bbp_topic_forum’ and ‘_bbp_forum_id’ as the Forum ID.
4. Repair the forums (tools->forums)After these steps you should see your topics in the correct forum!
Place in functions.php file of your child theme and modify to your needs, then call the function:
** Disclaimer! I’m not responsible for breaking your site! backup your install before using this code to change your topics! **function mwc_change_forum_topic_ties() { // 18 was my target forum ID. get yours. $forumid = '18'; $args = array( 'post_type' => 'topic', 'post_status' => 'publish', 'posts_per_page' => -1, ); /* uncomment this to filter your topics by something $oldForumID = '10'; //change this to target a specific forum $args['meta_query'] = array( 'meta_key' => 'bbp_topic_forum', 'meta_value' => $oldForumID, 'compare' => '=' ); */ $query = new WP_Query( $args ); if($query->have_posts()): while($query->have_posts()): $query->the_post(); $theid = get_the_ID(); $theargs = array( 'ID' => $theid, 'post_parent' => $forumid ); wp_update_post($theargs); update_post_meta($theid, 'bbp_topic_forum', $forumid); update_post_meta($theid, '_bbp_topic_forum', $forumid); update_post_meta($theid, '_bbp_forum_id', $forumid); update_post_meta($theid, '_bbp_topic_id', $theid); endwhile; endif; }
- You must be logged in to reply to this topic.