Custom-fields in Budypress Activity-content

This topic contains 12 reply and 2 voices, and was last updated by ggsalas 10 years, 9 months ago
Viewing 12 Posts - 1 through 12 (of 12 total)
Author Posts
July 9, 2013 at 9:38 pm 5791
ggsalas Hi @Tareq, For insert custom-fields in activity content I must need use this filter:
add_filter( 'bp_blogs_activity_new_post_content', 'record_post_activity_content',10,3);
function record_post_activity_content($activity_content, $post, $post_permalink ){
       $meta = get_post_meta($post->ID, 'txt_link', true).'this yes';
        return $activity_content . $meta;
}
This function I tested with wordpress, but with WPUF not work. Aparently is because the plugin not trigger "save_post" Wordpress action. Thanks
July 9, 2013 at 10:04 pm 5796
Tareq Hasan Tareq Hasan

So how and when are you inserting the activity in buddypress?

July 9, 2013 at 10:42 pm 5802
ggsalas ggsalas

I have created a WPUF form to add a new post. This form contains one or more custom-fields.

For each post creates an activity in wich I need show the custom-fields of the post.

July 9, 2013 at 11:52 pm 5810
Tareq Hasan Tareq Hasan

Instead of applying a filter, you could directly publish an activity to buddypress using this trick. Wouldn’t be that easier?

July 10, 2013 at 12:02 am 5814
ggsalas ggsalas

I think this is an unnecessary complex trick. Buddypress can record posts to activity. My only need is add custom-fields to activity.

Do you know how to trigger “save_post” WordPress action for each new post with WPUF?

July 10, 2013 at 12:06 am 5815
Tareq Hasan Tareq Hasan

You could fire the save_post hook by your own may be, don’t know if that’ll work.

[php]
function wpufe_bp_activity( $post_id ) {
do_action( ‘save_post’, $post_id );
}

add_action( ‘wpuf_add_post_after_insert’, ‘wpufe_bp_activity’ );
[/php]

July 10, 2013 at 1:55 am 5824
ggsalas ggsalas

I have tested and not work. Another problem is that wordpress give me this error” Warning: Missing argument 2 for bp_blogs_record_post() in /nfs/c08/h04/mnt/140927/domains/redminka.com/html/wp-content/plugins/buddypress/bp-blogs/bp-blogs-functions.php on line 214 “

July 10, 2013 at 10:02 pm 5842
Tareq Hasan Tareq Hasan

Then I suggest insert an activity manually. save_post only fires in wp-admin area. Implementing that hook in WPUF will create much trouble, thats why there are hooks given by WPUF.

July 11, 2013 at 7:36 am 5862
ggsalas ggsalas

Hi @Tareq,
I’m not sure to understand how to implement WPF-hooks. I need automatically update the buddypress activity for each blog post. Please tell me if exist any chance to do this with WPUF, even with some private customization or if there is no way to do this.

I’m very grateful for all your help.

July 12, 2013 at 1:34 am 5889
Tareq Hasan Tareq Hasan

Finally I gave a try to see what are you doing wrong. Turns out, bp_blogs_activity_new_post_content filter actually runs, but before any custom fields added to that post. So you can’t get any custom field because no custom fields are there yet. So all you’ve to do is to update the activity with your desired content.

Here’s how:
[php]
function wpufe_modify_bp_activity( $post_id ) {
global $wpdb, $user_ID;

//get the last inserted activity
$activity = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}bp_activity WHERE secondary_item_id = $post_id AND user_id = $user_ID");

// if activity found, update the activity with custom field
if ( $activity ) {
$content = $activity->content . ‘… Custom Field: ‘ . get_post_meta( $post_id, ‘custom_field’, true );

$wpdb->update(
$wpdb->prefix . ‘bp_activity’,
array( ‘content’ => $content ),
array( ‘id’ => $activity->id )
);
}
}

add_action( ‘wpuf_add_post_after_insert’, ‘wpufe_modify_bp_activity’ );
[/php]

July 12, 2013 at 1:53 am 5895
ggsalas ggsalas

@Tareq

This works great!!!!!!!!

I hope that you can update the plugin for that works perfect “out the box” with buddypress.

Now I gonna update the solution in a buddypress and wpmu forums.

Thanks!

July 12, 2013 at 1:56 am 5896
Tareq Hasan Tareq Hasan

Adding the solution to the plugin core is a bad idea. Everyone doesn’t run buddypress, so it’s waste of 2 SQL query.

July 12, 2013 at 2:07 am 5897
ggsalas ggsalas

Maybe an option that can unselect?

Or maybe a item in the WPUF manual.

I’m glad that find a solution. WPUF is a fantastic plugin, I don’t find any so complete

Viewing 12 Posts - 1 through 12 (of 12 total)