Skip to:
Content
Pages
Categories
Search
Top
Bottom

bp_activity_add issue….


  • josetraslabarra
    Participant

    @josetraslabarra

    Quizás quisiste decir: Hola buenas tengo un problema intentando crear un simple record activity usando la funcion bp_activity_Add

    Hi, I have a problem trying to create a simple record_activity using the bp_activity_Add function

    function bp_example_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->example->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 ) );
    }
    

    and add this in functions.php

    
    bp_example_record_activity( array( 'type' => 'new_highfive', 'action' => 'Andy high-fived John', 'user_id' => $bp->loggedin_user->id, 'item_id' => $bp->displayed_user->id ) );?>

    It wouldn’t be enough for me to add an item to my feed every time I reload (I’m testing in functions.php because I don’t know exactly where to put the function to run). But he does nothing here either

    thanxs

Viewing 1 replies (of 1 total)
  • Hi!

    1. Instead of using global $bp I advise you to use $bp = buddypress()
    2. Instead of using $bp->loggedin_user->id I advise you to use bp_loggedin_user_id()
    3. You don’t need to extract you can directly use the array
    4. I advise you to use the activity component because it’s unsure $bp->example->id isset
    5. Make sure to set some content for your test

    Hope it will help.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.
Skip to toolbar