Sylvain Filoni
asked 5 years ago

Hi Everybody !

I was proud i could handle it until now for almost everything but i get a tiny last issue :
When recording a new Question | Comment or Response in the Buddypress activity, it doesn’t print the right phrases, but record as it was a blog post, and a comment post …  Is it because i’m using BP 2.0 ? Or maybe i missed something ?

Thanks for your help !
 

Sylvain Filoni
replied 5 years ago

Maybe we cannot have at the same time a new_blog_post record with a specific message for questions “user asked a new question”,
and a new_blog_post record with the message ” user posted a new blog post ” ?

Sylvain Filoni
replied 5 years ago

no one on this case ? 🙁

2 Answers
BigHug
answered 5 years ago

HI Sylvain,
We are using buddypress on our homepage designwall.com too. So we made a custom function to record activity for buddypress thourght two action hooks dwqa_add_question and draft_to_publish, You can use this code below as a reference :

function nex_record_question_activity( $post_id ) {
$post = get_post($post_id);
if(($post->post_status != 'publish') && ($post->post_status != 'private'))
return;

$user_id = get_current_user_id();
$post_permalink = get_permalink( $post_id );
$post_title = get_the_title( $post_id );
$activity_action = sprintf( __( '%s asked a new question: %s', 'nex' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );
$content = $post->post_content;
$hide_sitewide = ($post->post_status == 'private') ? true : false;

if( function_exists('bp_activity_add') ) {
bp_activity_add( array(
'action' => $activity_action,
'content' => $content,
'primary_link' => $post_permalink,
'user_id' => $user_id,
'item_id' => $post_id,
'recorded_time' => $post->post_date_gmt,
'hide_sitewide' => $hide_sitewide
) );
}

if(function_exists('mycred_add')) {
if($post->post_status == 'private') {
mycred_add( 'new_question', $user_id, '-20', '%plural% for Ask a Question', $post_id, array( 'ref_type' => 'post' ) );
} else {
mycred_add( 'new_question', $user_id, '-10', '%plural% for Ask a Question', $post_id, array( 'ref_type' => 'post' ) );
}
}
}
add_action( 'dwqa_add_question', 'nex_record_question_activity');
add_action( 'draft_to_publish', 'nex_record_question_activity' );

Regards

Sylvain Filoni
answered 5 years ago

hi thanks for your reply !
but i still don’t see the exit … this is what i have for the recording of a question:  

function adn_record_question_activity( $post_id ) { $post = get_post($post_id);

if(($post->post_status != ‘publish’) && ($post->post_status != ‘private’)) return; $user_id = get_current_user_id(); $post_permalink = get_permalink( $post_id ); $post_title = get_the_title( $post_id ); $activity_action = sprintf( __( ‘%s asked: %s’,’buddypress’ ), bp_core_get_userlink( $user_id ), ‘<a href=”‘ . $post_permalink . ‘”>’ . $post->post_title . ‘</a>’ ); $content = $post->post_content; $hide_sitewide = ($post->post_status == ‘private’) ? true : false; bp_blogs_record_activity( array( ‘user_id’ => $user_id, ‘action’ => $activity_action, ‘content’ => $content, ‘primary_link’ => $post_permalink, ‘type’ => ‘new_blog_post’, ‘item_id’ => 0, ‘secondary_item_id’ => $post_id, ‘recorded_time’ => $post->post_date_gmt, ‘hide_sitewide’ => $hide_sitewide, )); } add_action( ‘dwqa_add_question’, ‘adn_record_question_activity’);  

The sprintf do not seems to take care of the ”  sprintf( __( ‘%s asked: %s’,’buddypress’ )  ” That’s why in the activity stream it’s recorded as a simple “article”.  I suppose i forgot something my eyes cannot see, or i’m afraid it’s a piece of knowledge i do not earn yet …    Your lights shall be very appreciated on this !   Regards 

BigHug
replied 5 years ago

Did you include two lines of code that will hook into insert post action :
add_action( ‘dwqa_add_question’, ‘nex_record_question_activity’);
add_action( ‘draft_to_publish’, ‘nex_record_question_activity’ );

Powered by DW Question & Answer Pro