Regenate wp_bp_activity posts from the original posts of contributors
-
Thanks ! I just use your code to reset / regenerate my blog posts activities in BuddyPress in a single WordPress website (not multisite).
I just execute that like that in a custom page (page-123456.php). Work like a charm.
<?php global $wpdb; ?> <div class="wrap"> <h2><?php _e( 'Import Blog Activity', 'bp-import-blog-activity' ) ?></h2> <form name="bp-iba-options-form" method="post" action=""> <div class="bp-iba-options"> <label for="bp-iba-submit"><?php _e('Press the button below to import blog entries and comments left before BuddyPress was installed into the BuddyPress activity streams. Warning: If you have a lot of blogs and comments on your system, this could take a while.', 'bp-import-blog-activity') ?> </label> <p class="submit"> <input type="submit" name="Submit" value="<?php _e( 'Import' ) ?> »" /> <input type="hidden" name="bp_iba_submit" value="1" /> </p> </form> </div> <?php //if( ! empty( $_POST['bp_iba_submit'] ) && $_POST[ 'bp_iba_submit' ] == '1' ) { if(true) { print "<pre>"; $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1; $query = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => 2000, 'paged' => $paged ) ); if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); //if ( have_posts() ) { //while ( have_posts() ) { //the_post(); //echo "The post is: "; the_title(); echo "<br />"; $filter = array( 'object' => 'blogs', 'secondary_id' => get_the_ID(), 'action' => 'new_blog_post' ); $activities = bp_activity_get( array( 'filter' => $filter ) ); if ( empty($activities->activities) ) { global $post; $post_permalink = get_permalink(); $activity_action = sprintf( __( '%s a écrit a posté : %s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' ); $activity_content = $post->post_content; $post_id = get_the_ID(); $short_content = substr(strip_tags(apply_filters( 'bp_blogs_activity_new_post_content', $activity_content, $post, $post_permalink )), 0, 200).'...'; echo 'user_id' . ' : ' . (int)$post->post_author . '<br>'; echo 'action' . ' : ' . apply_filters( 'bp_blogs_activity_new_post_action', $activity_action, $post, $post_permalink ) . '<br>'; echo 'content' . ' : ' . $short_content . '<br>'; echo 'primary_link' . ' : ' . apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink, $post_id ) . '<br>'; echo 'type' . ' : ' . 'new_blog_post' . '<br>'; echo 'secondary_item_id' . ' : ' . $post_id . '<br>'; echo 'recorded_time' . ' : ' . $post->post_date_gmt . '<br>'; bp_blogs_record_activity( array( 'user_id' => (int)$post->post_author, 'action' => apply_filters( 'bp_blogs_activity_new_post_action', $activity_action, $post, $post_permalink ), 'content' => $short_content, 'primary_link' => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink, $post_id ), 'type' => 'new_blog_post', 'item_id' => $blog['blog_id'], 'secondary_item_id' => $post_id, 'recorded_time' => $post->post_date_gmt )); echo "Importing: \"" . $activity_action . "\"<br />"; } endwhile; endif; // } // end while have_posts //} // end if have_posts wp_reset_query(); echo "<br /><br />"; }
- The topic ‘Regenate wp_bp_activity posts from the original posts of contributors’ is closed to new replies.