Home Forums Plugin Support WP User Frontend Pro Custom-fields in Budypress Activity-content

This topic is: resolved

This topic contains 12 replies, has 2 voices, and was last updated by  ggsalas 1 year, 3 months ago.

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #5791
    ggsalas
    Post count: 108

    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

    #5796
    Key Master
    Tareq
    Post count: 2796

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

    #5802
    ggsalas
    Post count: 108

    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.

    #5810
    Key Master
    Tareq
    Post count: 2796

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

    #5814
    ggsalas
    Post count: 108

    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?

    #5815
    Key Master
    Tareq
    Post count: 2796

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

    function wpufe_bp_activity( $post_id ) {
        do_action( 'save_post', $post_id );
    }
    
    add_action( 'wpuf_add_post_after_insert', 'wpufe_bp_activity' );
    
    #5824
    ggsalas
    Post count: 108

    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 “

    #5842
    Key Master
    Tareq
    Post count: 2796

    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.

    #5862
    ggsalas
    Post count: 108

    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.

    #5889
    Key Master
    Tareq
    Post count: 2796

    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:

    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' );
    
    #5895
    ggsalas
    Post count: 108

    @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!

    #5896
    Key Master
    Tareq
    Post count: 2796

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

    #5897
    ggsalas
    Post count: 108

    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 13 posts - 1 through 13 (of 13 total)

You must be logged in to reply to this topic.