Below two code, i can create buddypress activity for Book CPT (1st code) with title (2nd code) … Member A publish new “best horror book last 10 years” ( with Title)
I have 2 question: 1st: When anyone comment this activity : It shows Member B comment a “Book” i could not success the display post title instead of “Book (CPT)” . i need to dispaly Member B comment “best horror book last 10 years”
2nd question If 1st can possible ‘bp_activity_new_comment’ => __( ‘%1$s commented BOOK‘, ‘custom-textdomain’ ), is possible Member B comment on the “best horror book last 10 years” by Member A (with post author name or avatar) … mİLLİON Thanks
// creating the dropdown filter on activity and members page
function customize_page_tracking_args() {
// Check if the Activity component is active before using it.
if ( ! bp_is_active( ‘activity’ ) ) {
return;
}
bp_activity_set_post_type_tracking_args( ‘book’, array(
‘component_id’ => ‘activity’, // unique ID
‘action_id’ => ‘new_book’, // new_$post_type where new_ is mandatory
‘comment_action_id’ => ‘new_mot_comment’,
‘bp_activity_comments_admin_filter’ => __( ‘Comments about book’, ‘custom-textdomain’ ), // label for the Admin dropdown filter
‘bp_activity_comments_front_filter’ => __( ‘Book Comments’, ‘custom-textdomain’ ), // label for the Front dropdown filter
‘bp_activity_new_comment’ => __( ‘%1$s commented BOOK‘, ‘custom-textdomain’ ),
‘bp_activity_admin_filter’ => __( ‘Published a new BOOK’, ‘text-domain’ ),
‘bp_activity_front_filter’ => __( ‘bOOK’, ‘text-domain’ ),
‘contexts’ => array( ‘activity’, ‘member’ ), // swa & member activity page
‘activity_comment’ => true,
‘bp_activity_new_post’ => __( ‘%1$s publish a new bOOK‘, ‘text-domain’ ),
‘position’ => 100,
) );
}
add_action( ‘init’, ‘customize_page_tracking_args’, 999 );
code2 FOR DISPLAY NEW BOOK PUBLISHED WITH TITLE
function monkey1980_include_post_type_title( $action, $activity ) {
if ( empty( $activity->id ) ) {
return $action;
}
// We have a title save it in activity meta to avoid switching blogs too much
if ( ! empty( $post_type_title ) ) {
bp_activity_update_meta( $activity->id, ‘post_title’, $post_type_title );
}
ineedyou
@ineedyou
6 years, 6 months ago
Hi,
Below two code, i can create buddypress activity for Book CPT (1st code) with title (2nd code) … Member A publish new “best horror book last 10 years” ( with Title)
I have 2 question:
1st: When anyone comment this activity : It shows Member B comment a “Book” i could not success the display post title instead of “Book (CPT)” . i need to dispaly Member B comment “best horror book last 10 years”
2nd question If 1st can possible ‘bp_activity_new_comment’ => __( ‘%1$s commented BOOK‘, ‘custom-textdomain’ ), is possible Member B comment on the “best horror book last 10 years” by Member A (with post author name or avatar) … mİLLİON Thanks
cODE1
// allow tracking of our CPT
add_post_type_support( ‘book’, ‘buddypress-activity’ );
// creating the dropdown filter on activity and members page
function customize_page_tracking_args() {
// Check if the Activity component is active before using it.
if ( ! bp_is_active( ‘activity’ ) ) {
return;
}
bp_activity_set_post_type_tracking_args( ‘book’, array(
‘component_id’ => ‘activity’, // unique ID
‘action_id’ => ‘new_book’, // new_$post_type where new_ is mandatory
‘comment_action_id’ => ‘new_mot_comment’,
‘bp_activity_comments_admin_filter’ => __( ‘Comments about book’, ‘custom-textdomain’ ), // label for the Admin dropdown filter
‘bp_activity_comments_front_filter’ => __( ‘Book Comments’, ‘custom-textdomain’ ), // label for the Front dropdown filter
‘bp_activity_new_comment’ => __( ‘%1$s commented BOOK‘, ‘custom-textdomain’ ),
‘bp_activity_admin_filter’ => __( ‘Published a new BOOK’, ‘text-domain’ ),
‘bp_activity_front_filter’ => __( ‘bOOK’, ‘text-domain’ ),
‘contexts’ => array( ‘activity’, ‘member’ ), // swa & member activity page
‘activity_comment’ => true,
‘bp_activity_new_post’ => __( ‘%1$s publish a new bOOK‘, ‘text-domain’ ),
‘position’ => 100,
) );
}
add_action( ‘init’, ‘customize_page_tracking_args’, 999 );
code2 FOR DISPLAY NEW BOOK PUBLISHED WITH TITLE
function monkey1980_include_post_type_title( $action, $activity ) {
if ( empty( $activity->id ) ) {
return $action;
}
if ( ‘new_book’ != $activity->type ) {
return $action;
}
preg_match_all( ‘/<a.*?>([^>]*)<\/a>/’, $activity->action, $matches );
if ( empty( $matches[1][1] ) || ‘Book’ != $matches[1][1] ) {
return $action;
}
$post_type_title = bp_activity_get_meta( $activity->id, ‘post_title’ );
if ( empty( $post_type_title ) ) {
switch_to_blog( $activity->item_id );
$post_type_title = get_post_field( ‘post_title’, $activity->secondary_item_id );
// We have a title save it in activity meta to avoid switching blogs too much
if ( ! empty( $post_type_title ) ) {
bp_activity_update_meta( $activity->id, ‘post_title’, $post_type_title );
}
restore_current_blog();
}
return str_replace( $matches[1][1], esc_html( $post_type_title ), $activity->action );
}
add_filter( ‘bp_activity_custom_post_type_post_action’, ‘monkey1980_include_post_type_title’, 10, 2 );