Home Forums Plugin Support WP User Frontend Pro Post to Buddypress Actvities

This topic is: not resolved

This topic contains 24 replies, has 5 voices, and was last updated by  Aaron 4 years, 5 months ago.

Viewing 15 posts - 1 through 15 (of 25 total)
  • Author
    Posts
  • #2982

    ggsalas
    Participant
    Post count: 108

    Hi, I like to know if can use one form to publish an BP activity instead a post.

    Thsnks

    #2987

    Tareq Hasan
    Keymaster
    Post count: 2831

    Sorry, it can't be done. Only thing WPUF can do is creating post or custom post type.

    #4788

    quokka
    Participant
    Post count: 10

    Hi Tareq,

    Thanks for the great plugin!
    I used it to create a front end post form to submit to main blog in Buddypress.
    Also I created a custom post type ‘imagegalleries' where users can post photo's to with WPUF.
    Amazingly easy with WPUF!

    One concern..
    I would like the activity of posting to my custom post type and blog to be recorded in the BP activity stream..

    I have been looking on how other plugins do it.
    For example the BP Portfolio plugin logs all activity to the stream..
    http://wordpress.org/plugins/buddypress-portfolio/
    [php]/**
    * Record an activity item
    */
    function bp_portfolio_record_activity( $args = ” ) {
    global $bp;

    if ( !function_exists( ‘bp_activity_add' ) )
    return false;

    $defaults = array(
    ‘id' => false,
    ‘user_id' => $bp->loggedin_user->id,
    ‘action' => ”,
    ‘content' => ”,
    ‘primary_link' => ”,
    ‘component' => $bp->portfolio->id,
    ‘type' => false,
    ‘item_id' => false,
    ‘secondary_item_id' => false,
    ‘recorded_time' => gmdate( "Y-m-d H:i:s" ),
    ‘hide_sitewide' => false
    );

    $r = wp_parse_args( $args, $defaults );
    extract( $r );

    return bp_activity_add( array( ‘id' => $id, ‘user_id' => $user_id, ‘action' => $action, ‘content' => $content, ‘primary_link' => $primary_link, ‘component' => $component, ‘type' => $type, ‘item_id' => $item_id, ‘secondary_item_id' => $secondary_item_id, ‘recorded_time' => $recorded_time, ‘hide_sitewide' => $hide_sitewide ) );
    }
    <pre><code>

    bp-portfolio-activity.php has a function o update the stream and i gets called on every post creation or update.
    </code></pre>
    // Records an activity
    if($result = $portfolio->save()) {

    /* Now record the activity item */
    $user_link = bp_core_get_userlink( $bp->loggedin_user->id );

    $project = new BP_Portfolio_Item( array( ‘id' => $result ) );
    $project->get();

    $title = $project->query->post->post_title;
    $user_portfolio_link = ‘<a href="'. bp_core_get_user_domain($bp->loggedin_user->id) . BP_PORTFOLIO_SLUG . ‘">portfolio</a>';

    if($id) {
    // Edit an existing item
    bp_portfolio_record_activity( array(
    ‘type' => ‘edit_project',
    ‘action' => apply_filters( ‘bp_edit_portfolio_activity_action', sprintf( __( ‘%s edited the <strong>%s</strong> project in his %s', ‘bp-portfolio' ), $user_link, $title, $user_portfolio_link ), $user_link, $title, $user_portfolio_link ),
    ‘item_id' => $bp->loggedin_user->id,
    ) );
    }
    else {
    // New item, so new activity
    $description = $project->query->post->post_content;
    $url = get_post_meta($result, ‘bp_portfolio_url', true);

    $attachment = wp_get_attachment_image_src($project->query->post->post_parent, ‘portfolio-thumb');
    if($attachment != 0)
    $thumbnail = apply_filters( ‘bp_portfolio_get_item_thumbnail', $attachment[0]);
    else
    $thumbnail = apply_filters( ‘bp_portfolio_get_item_thumbnail', BP_PORTFOLIO_PLUGIN_URL . ‘/templates/' . BP_PORTFOLIO_TEMPLATE . ‘/img/default.png');

    $activity_content = sprintf(__( ‘<div class="item-project"><div class="item-project-pictures"><img width="250px" height="170px" src="%s"></div><div class="item-project-content"><div class="item-project-title">%s</div><div class="item-project-url"><a href="%s">%s</a></div><div class="item-project-desc">%s</div></div></div></div>', ‘bp-portfolio'), $thumbnail, $title, $url, $url, $description);

    bp_portfolio_record_activity( array(
    ‘type' => ‘new_project',
    ‘action' => apply_filters( ‘bp_new_portfolio_activity_action', sprintf( __( ‘%s created a new project in his %s', ‘bp-portfolio' ), $user_link, $user_portfolio_link ), $user_link, $user_portfolio_link ),
    ‘content' => $activity_content,
    ‘item_id' => $bp->loggedin_user->id,
    ) );
    }

    return true;
    }[/php]

    Any chance you could build this support into WPUF?
    I'm willing to sponsor the development, maybe ggsalas is interested too?

    Thanks!
    Bas

    #4792

    quokka
    Participant
    Post count: 10

    Looking at WPUF documentation and seems to me like the action hooks wpuf_add_post_after_insert ans wpuf_edit_post_after_update could be used to call a function likke the bp_portfolio_record_activity above that writes to the activity stream, or in't it that easy?

    Thanks,
    Bas

    #4795

    Tareq Hasan
    Keymaster
    Post count: 2831

    Hey Bas, yes you are right. Using those hooks you add the activities easily.

    #4796

    quokka
    Participant
    Post count: 10

    Hi Tareq,

    Thanks…i'm aready fooling around..
    Can you tell me what I'm doing wrong please?
    I didn't play with action hooks before and while it looks pretty simple, I even can't get this working:

    <?php
    /*
    Plugin Name: Do action after insert or update
    Plugin URI: http://www.basdebie.com
    Description: Testing the action hooks of WPUF
    Version: 1.0
    Author: Bas Debie
    Author URI: http://www.basdebie.com
    License: GPL2
    */
    
    function bd_trigger_wpuf_update_insert( $post_id ) {
        //update_post_meta( $post_id, 'artist', $_POST['song_artist'] );
    	$to = "my_email_addres@domain.com";
    	$subject = "Test mail from plugin";
    	$message = "Hello! This is a test mail from plugin";
    	$from = "my_email_addres@domain.com";
    	$headers = "From:" . $from;
    	mail($to,$subject,$message,$headers);
    }
    add_action( 'wpuf_add_post_after_insert', 'bd_trigger_wpuf_update_insert' );
    add_action( 'wpuf_add_post_after_update', 'bd_trigger_wpuf_update_insert' );
    
    ?>
    

    Thanks!
    Bas

    #4797

    quokka
    Participant
    Post count: 10

    I activated this simple plugin and when I add or update a post with the WPUF forntend form, nothing seems to happen..

    Thanks!

    #4799

    Tareq Hasan
    Keymaster
    Post count: 2831

    Your code is fine and it should work. May be some problem with the email delivery?

    #4801

    quokka
    Participant
    Post count: 10

    ;-D

    You are right, seems like php mail() function not working on that domain hosting account. Tried on another domain / WP install and working fine!

    Thanks Tareq,
    If I manage to get this working I'll post it here for other Buddypress users..
    Bye…
    Bas

    #4805

    quokka
    Participant
    Post count: 10

    Hi Tareq (and anybody else that maybe interested)…

    I managed to get this little plugin of mine working.

    When I create a new post (of custom post type ‘photoalbum') with WP User Frontend Pro this plugin also writes the activity to the Buddypress Activity Stream.

    To use this with your own custom post type just search/replace for ‘photoalbum' and replace with ‘your_custom_post_type_name'

    Grab the code and save it as a WordPress plugin and you should be fine..

    Thanks Tareq for pointing me in the right direction, and for making those handy action hooks available in WP User Frontend Pro ๐Ÿ˜€

    Take care!
    Bas

    The plugin code:

    
    <?php
    /*
    Plugin Name: Photoalbum CPT 2 Buddypress Activity Stream
    Plugin URI: http://www.basdebie.com
    Description: This plugin hooks into WP User Frontend and posts to the Buddypress Activity Stream on new photoalbum submission
    Version: 1.0
    Author: Bas Debie
    Author URI: http://www.basdebie.com
    License: GPL2
    */
     
     
     /**
     * Record an activity item
     * This code is taken from Nicolas Crocfer's BuddyPress Portfolio Plugin
     */
    function bd_custom_bp_record_activity( $args = '' ) {
    	if ( !function_exists( 'bp_activity_add' ) )
    		return false;
    
    	$defaults = array(
    		'id' => false,
    		'user_id' => '',
    		'action' => '',
    		'content' => '',
    		'primary_link' => '',
    		'component' => 'photoalbum',
    		'type' => false,
    		'item_id' => false,
    		'secondary_item_id' => false,
    		'recorded_time' => gmdate( "Y-m-d H:i:s" ),
    		'hide_sitewide' => false
    	);
    
    	$r = wp_parse_args( $args, $defaults );
    	extract( $r );
    	return bp_activity_add( array( 'id' => $id, 'user_id' => $user_id, 'action' => $action, 'content' => $content, 'primary_link' => $primary_link, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide ) );
    }
    
    /**
     * After post photoalbum update the Buddypress Activity Stream
     */
    function bd_after_photoalbum_insert( $post_id ) {
    	
    	global $bp;
    	if( get_post_type( $post_id ) == "photoalbum" ) {
    	bd_custom_bp_record_activity( array(
    				'user_id' => $bp->loggedin_user->id,
    				'action' => sprintf(__('%s added the Photoalbum \''.get_the_title($post_id).'\' at %s','bd-photoalbum'), "<a href='".$bp->loggedin_user->domain."/'>".$bp->loggedin_user->fullname."</a>", get_permalink( $post_id ) ),
    				'primary_link' => get_permalink( $post_id ),
    				'type' => 'new_photoalbum',
    				'item_id' => $bp->loggedin_user->id,
    			));
    	}
    
    }
    add_action( 'wpuf_add_post_after_insert', 'bd_after_photoalbum_insert' );
    
    ?>
    
    #4806

    Mahi
    Member
    Post count: 1555

    Hello @quokka,

    Thats great. Would you mind to email this as tutorial to support@wedevs.com with your name , email address and site (as ref) ? If you can include some screenshot images that would be great.

    We will post it on our Documentation as tutorial with your ref.

    Cheers.

    #4807

    quokka
    Participant
    Post count: 10

    Hi Mahi,

    Sure no problem..I will include the custom post type code from my functions-custom.php as well together with some screenshots..

    Can take a day or two because I'm very busy playing with you cool WPUF plugin ;-D

    Take care and keep up the great work at Wedevs.com!
    Bas

    #5502

    ggsalas
    Participant
    Post count: 108

    what I need is to insert custom-fields in activity posts and i can't. This is the code that doesn't work:

    [php]add_filter( ‘bp_blogs_activity_new_post_content', ‘record_post_activity_content', 1, 3 );
    function record_post_activity_content($activity_content, $post,
    $post_permalink ){
    if( $post-_post_type == ‘post' ) {
    global $post;
    $activity_content = get_post_meta($post->ID, "txt_link", true);
    }
    return $activity_content;
    }[/php]

    #5504

    Tareq Hasan
    Keymaster
    Post count: 2831

    Make sure your filter is actually running and you are getting the correct post id. I am not that much experienced in buddypress.

    #5507

    ggsalas
    Participant
    Post count: 108

    I found something, when i set to false:

    return get_post_meta($post->ID, 'txt_link', false);

    I get “array” text in activity content

Viewing 15 posts - 1 through 15 (of 25 total)

The topic ‘Post to Buddypress Actvities’ is closed to new replies.