Skip to:
Content
Pages
Categories
Search
Top
Bottom

Search Results for 'bp_activity_entry_meta'

Viewing 20 results - 1 through 20 (of 20 total)
  • Author
    Search Results
  • #333980
    gishw
    Participant

    I have created a solution for this and this works. but like count only changes when pages are refresh. any solution for that?
    // CODE TO GET LIKES COUNT

    ## create a table wp_likes

    function custom_activity_content_below( $activity_id ) {
    // echo bp_activity_id();

    global $wpdb;

    // Query to count the number of favorites for a specific activity
    $favorite_count = $wpdb->get_var( $wpdb->prepare(

    SELECT COUNT(*)
    FROM {$wpdb->prefix}likes
    WHERE activity_id = %d
    “,
    bp_get_activity_id()
    ) );

    echo ‘<div class=”like_count” style=”margin-top: 10px; color: black;”>’.$favorite_count .’ Likes</div>’;
    }

    add_action( ‘bp_activity_entry_meta’, ‘custom_activity_content_below’,10,1 );

    function get_activity_favorite_count( $activity_id ) {
    global $wpdb;

    // Query to count the number of favorites for a specific activity
    $favorite_count = $wpdb->get_var( $wpdb->prepare(

    SELECT COUNT(*)
    FROM {$wpdb->prefix}bp_activity_user_favorite
    WHERE activity_id = %d
    “,
    $activity_id
    ) );

    return $favorite_count;
    }

    function save_activity_like_to_table($activity_id) {

    global $wpdb;

    // Get current user ID
    $user_id = get_current_user_id();

    // Table name
    $table_name = $wpdb->prefix . ‘likes’;

    // Insert data into the custom table
    $wpdb->insert(
    $table_name,
    array(
    ‘activity_id’ => $activity_id,
    ‘user_id’ => $user_id,
    ‘created_at’ => current_time( ‘mysql’ ),
    ),
    array(
    ‘%d’,
    ‘%d’,
    ‘%s’,
    )
    );
    }

    add_action( ‘bp_activity_add_user_favorite’, ‘save_activity_like_to_table’, 10, 1 );

    function delete_activity_like_from_table($activity_id) {
    global $wpdb;

    // Get current user ID
    $user_id = get_current_user_id();

    // Table name
    $table_name = $wpdb->prefix . ‘likes’;

    // Delete data from the custom table
    $wpdb->delete(
    $table_name,
    array(
    ‘activity_id’ => $activity_id,
    ‘user_id’ => $user_id,
    ),
    array(
    ‘%d’,
    ‘%d’,
    )
    );
    }

    add_action( ‘bp_activity_remove_user_favorite’, ‘delete_activity_like_from_table’, 10, 1 );

    #262749
    squadup
    Participant

    Excuse me if this request is in the wrong place:

    I have added a working custom date field to my activity page by editing the post-form.php and the the bp-custom.php. This is in my bp-custom.php:

    
    // CUSTOM DATE FIELD
    function add_date_to_activity( $content, $user_id, $activity_id ) {
    bp_activity_update_meta( $activity_id,'thedate', $_POST['thedate'] );
    }
    add_action( 'bp_activity_posted_update', 'add_date_to_activity', 10, 3 );
    function my_datemeta() {
    $my_datemeta = bp_activity_get_meta( bp_get_activity_id(),'thedate' );
    if (is_user_logged_in()) : {
    echo "<span class='datefont'>" . $my_datemeta . "</span></br>";
    }
    endif;
    }
    add_action( 'bp_activity_entry_meta','my_datemeta' );
    

    Now I am trying to sort the posted activities by this date field instead of the standard sort by activity-id’s. Is there any way to override the standard sort function?

    Thanks in advance, i’d be happy to share more information if necessary

    tommyhares
    Participant

    Hello, I am trying to edit my theme to enclose the Delete button and Mark as Spam button into a custom drop-down box. How can I add these buttons into another area? Also, how do I remove these buttons from the do_action( ‘bp_activity_entry_meta’ ); ?> action? Thanks for any help!

    bikerwp000
    Participant
    <?php
    /**
     * Plugin Name:       BP Loop Filters
     * Plugin URI:        https://codex.buddypress.org/add-custom-filters-to-loops-and-enjoy-them-within-your-plugin
     * Description:       Plugin example to illustrate loop filters
     * Version:           1.0
     * Author:            imath
     * Author URI:        http://imathi.eu
     * License:           GPL-2.0+
     * License URI:       http://www.gnu.org/licenses/gpl-2.0.txt
     */
    
    // Exit if accessed directly
    if ( !defined( 'ABSPATH' ) ) exit;
    
    class BP_Loop_Filters {
    
    	/**
    	 * Constructor
    	 */
    	public function __construct() {
    		$this->setup_actions();
    		$this->setup_filters();
    	}
    
    	/**
    	 * Actions
    	 *
    	 * @uses bp_is_active()
    	 * @uses is_multisite()
    	 */
    	private function setup_actions() {
    		/**
    		 * Adds the random order to the select boxes of the Members, Groups and Blogs directory pages
    		 */
    		// Members component is core, so it will be available
    		add_action( 'bp_members_directory_order_options', array( $this, 'random_order' ) );
    
    		// You need to check Groups component is available
    		if ( bp_is_active( 'groups' ) ) {
    			add_action( 'bp_groups_directory_order_options',  array( $this, 'random_order' ) );
    		}
    
    		// You need to check WordPress config and that Blogs Component is available
    		if ( is_multisite() && bp_is_active( 'blogs' ) ) {
    			add_action( 'bp_blogs_directory_order_options',   array( $this, 'random_order' ) );
    		}
    
    		/**
    		 * Registers the Activity actions so that they are available in the Activity Administration Screen
    		 */
    		// You need to check Activity component is available
    		if ( bp_is_active( 'activity' ) ) {
    
    			add_action( 'bp_register_activity_actions', array( $this, 'register_activity_actions' ) );
    
    			// Adds a new filter into the select boxes of the Activity directory page,
    			// of group and member single items activity screens
    			add_action( 'bp_activity_filter_options',        array( $this, 'display_activity_actions' ) );
    			add_action( 'bp_member_activity_filter_options', array( $this, 'display_activity_actions' ) );
    
    			// You need to check Groups component is available
    			if ( bp_is_active( 'groups' ) ) {
    				add_action( 'bp_group_activity_filter_options', array( $this, 'display_activity_actions' ) );
    			}
    
    	        // You're going to output the favorite count after action buttons
    			add_action( 'bp_activity_entry_meta', array( $this, 'display_favorite_count' ) );
    		}
    
    	}
    
    	/**
    	 * Displays a new option in the Members/Groups & Blogs directories
    	 *
    	 * @return string html output
    	 */
    	public function random_order() {
    		?>
    		<option value="random"><?php _e( 'Random', 'buddypress' ); ?></option>
    		<?php
    	}
    
    	/**
    	 * Registering the Activity actions for your component
    	 *
    	 * The registered actions will also be available in Administration
    	 * screens
    	 *
    	 * @uses bp_activity_set_action()
    	 * @uses is_admin()
    	 */
    	public function register_activity_actions() {
    		/* arguments are :
    		- 'component_id', 'component_action_type' to use in {$wpdb->prefix}bp_activity database
    		- and 'caption' to display in the select boxes */
    		bp_activity_set_action( 'bp_plugin', 'bpplugin_action', __( 'BP Plugin Action' ) );
    
    		/* Activity Administration screen does not use bp_ajax_querystring
    		Moreover This action type is reordering instead of filtering so you will only
    		use it on front end */
    		if ( ! is_admin() ) {
    			bp_activity_set_action( 'bp_plugin', 'activity_mostfavs', __( 'Most Favorited' ) );
    		}
    	}
    
    	/**
    	 * Building an array to loop in from our display function
    	 *
    	 * Using bp_activity_get_types() will list all registered activity actions
    	 * but you need to get the ones for your plugin, and this particular function
    	 * directly returns an array of key => value. As you need to filter activity
    	 * with your component id, the global buddypress()->activity->actions will be
    	 * more helpful.
    	 *
    	 * @uses buddypress()
    	 * @return array the list of your plugin actions.
    	 */
    	private function list_actions() {
    
    		$bp_activity_actions = buddypress()->activity->actions;
    
    		$bp_plugin_actions = array();
    
    		if ( !empty( $bp_activity_actions->bp_plugin ) ) {
    			$bp_plugin_actions = array_values( (array) $bp_activity_actions->bp_plugin );
    		}
    
    		return $bp_plugin_actions;
    	}
    
    	/**
    	 * Displays new actions into the Activity select boxes
    	 * to filter activities
    	 * - Activity Directory
    	 * - Single Group and Member activity screens
    	 *
    	 * @return string html output
    	 */
    	public function display_activity_actions() {
    		$bp_plugin_actions = $this->list_actions();
    
    		if ( empty( $bp_plugin_actions ) ) {
    			return;
    		}
    
    		foreach ( $bp_plugin_actions as $type ):?>
    			<option value="<?php echo esc_attr( $type['key'] );?>"><?php echo esc_attr( $type['value'] ); ?></option>
    		<?php endforeach;
    	}
    
    	/**
    	 * Displays a mention to inform about the number of time the activity
    	 * was favorited.
    	 *
    	 * @global BP_Activity_Template $activities_template
    	 * @return string html output
    	 */
    	public function display_favorite_count() {
    		global $activities_template;
    
    		// BuddyPress < 2.0 or filtering bp_use_legacy_activity_query
    		if ( ! empty( $activities_template->activity->favorite_count ) ) {
    			$fav_count = $activities_template->activity->favorite_count;
    		} else {
    			// This meta should already have been cached by BuddyPress :)
    			$fav_count = (int) bp_activity_get_meta( bp_get_activity_id(), 'favorite_count' );
    		}
    
    		if ( ! empty( $fav_count ) ): ?>
    			<a name="favorite-<?php bp_activity_id();?>" class="button bp-primary-action">Favorited <span><?php printf( _n( 'once', '%s times', $fav_count ), $fav_count );?></span></a>
    		<?php endif;
    	}
    
    	/**
    	 * Filters
    	 */
    	private function setup_filters() {
    		add_filter( 'bp_ajax_querystring',              array( $this, 'activity_querystring_filter' ), 12, 2 );
    		add_filter( 'bp_activity_get_user_join_filter', array( $this, 'order_by_most_favorited' ),     10, 6 );
    		add_filter( 'bp_activity_paged_activities_sql', array( $this, 'order_by_most_favorited'),      10, 2 );
    
    		// Maybe Fool Heartbeat Activities!
    		add_filter( 'bp_before_activity_latest_args_parse_args', array( $this, 'maybe_fool_heartbeat' ), 10, 1 );
    	}
    
    	/**
    	 * Builds an Activity Meta Query to retrieve the favorited activities
    	 *
    	 * @param  string $query_string the front end arguments for the Activity loop
    	 * @param  string $object       the Component object
    	 * @uses   wp_parse_args()
    	 * @uses   bp_displayed_user_id()
    	 * @return array()|string $query_string new arguments or same if not needed
    	 */
    	public function activity_querystring_filter( $query_string = '', $object = '' ) {
    		if ( $object != 'activity' ) {
    			return $query_string;
    		}
    
    		// You can easily manipulate the query string
    		// by transforming it into an array and merging
    		// arguments with these default ones
    		$args = wp_parse_args( $query_string, array(
    			'action'  => false,
    			'type'    => false,
    			'user_id' => false,
    			'page'    => 1
    		) );
    
    		/* most favorited */
    		if ( $args['action'] == 'activity_mostfavs' ) {
    			unset( $args['action'], $args['type'] );
    
    			// on user's profile, shows the most favorited activities for displayed user
    			if( bp_is_user() ) {
    				$args['user_id'] = bp_displayed_user_id();
    			}
    
    			// An activity meta query :)
    			$args['meta_query'] = array(
    				array(
    					/* this is the meta_key you want to filter on */
    					'key'     => 'favorite_count',
    					/* You need to get all values that are >= to 1 */
    					'value'   => 1,
    					'type'    => 'numeric',
    					'compare' => '>='
    				),
    			);
    
    			$query_string = empty( $args ) ? $query_string : $args;
            }
    
            return apply_filters( 'bp_plugin_activity_querystring_filter', $query_string, $object );
    	}
    
    	/**
    	 * Ninja Warrior trick to reorder the Activity Loop
    	 * regarding the activities favorite count
    	 *
    	 * @param  string $sql        the sql query that will be run
    	 * @param  string $select_sql the select part of the query
    	 * @param  string $from_sql   the from part of the query
    	 * @param  string $where_sql  the where part of the query
    	 * @param  string $sort       the sort order (leaving it to DESC will be helpful!)
    	 * @param  string $pag_sql    the offset part of the query
    	 * @return string $sql        the current or edited query
    	 */
    	public function order_by_most_favorited( $sql = '', $select_sql = '', $from_sql = '', $where_sql = '', $sort = '', $pag_sql = '' ) {
    		if ( apply_filters( 'bp_use_legacy_activity_query', false ) ) {
    			preg_match( '/\'favorite_count\' AND CAST\((.*) AS/', $where_sql, $match );
    
    			if ( ! empty( $match[1] ) ) {
    				$new_order_by = 'ORDER BY '. $match[1] .' + 0';
    				$new_select_sql = $select_sql . ', '. $match[1] .' AS favorite_count';
    
    				$sql = str_replace(
    					array( $select_sql, 'ORDER BY a.date_recorded' ),
    					array( $new_select_sql, $new_order_by ),
    					$sql
    				);
    			}
    
    		// $select_sql is carrying the requested argument since BuddyPress 2.0.0
    		} else {
    			$r = $select_sql;
    
    			if ( empty( $r['meta_query'] ) || ! is_array( $r['meta_query'] ) ) {
    				return $sql;
    			} else {
    				$meta_query_keys = wp_list_pluck( $r['meta_query'], 'key' );
    
    				if ( ! in_array( 'favorite_count', $meta_query_keys ) ) {
    					return $sql;
    				}
    
    				preg_match( '/\'favorite_count\' AND CAST\((.*) AS/', $sql, $match );
    
    				if ( ! empty( $match[1] ) ) {
    					$sql = str_replace( 'ORDER BY a.date_recorded', 'ORDER BY '. $match[1] .' + 0', $sql );
    				}
    			}
    		}
    
    		return $sql;
    	}
    
    	/**
    	 * Cannot pass the favorite data for now so just fool heartbeat activities
    	 */
    	public function maybe_fool_heartbeat( $r = array() ) {
    		if ( empty( $r['meta_query'] ) ) {
    			return $r;
    		}
    
    		$meta_query_keys = wp_list_pluck( $r['meta_query'], 'key' );
    
    		if ( ! in_array( 'favorite_count', $meta_query_keys ) ) {
    			return $r;
    		} else {
    			$r['since'] = '3000-12-31 00:00:00';
    		}
    
    		return $r;
    	}
    }
    
    // 1, 2, 3 go !
    function bp_loop_filters() {
    	return new BP_Loop_Filters();
    }
    
    add_action( 'bp_include', 'bp_loop_filters' );
    
    
    danbp
    Participant

    Hi!

    Yes, bp_activity_entry_meta is the correct hook.

    If you prefer to use JS, see an example here.

    #243701
    danbp
    Participant

    You didn’t explain what you want to do. What should Momentum and Milestone do ? Where are they living ? Are this activty types or CPT, something from a plugin ?

    As is, your second snippet do nothing from within bp-custom. Function name is missing and eventually filter or action name also.

    Insert your buttons by using the meta action filter which is avaible in entry.php

    function bfchris() {
    echo 'Button test >';
    ?>
    <a href="<?php bp_activity_unfavorite_link(); ?>" class="button unfav bp-secondary-action" title="<?php esc_attr_e( 'Is Milestone?', 'buddypress' ); ?>"><?php _e( 'Is Milestone?', 'buddypress' ); ?></a>
    <a href="<?php bp_activity_unfavorite_link(); ?>" class="button unfav bp-secondary-action" title="<?php esc_attr_e( ' Is Momentum Point?', 'buddypress' ); ?>"><?php _e( 'Is Momentum Point?', 'buddypress' ); ?></a>
    <?php
    }
    add_action( 'bp_activity_entry_meta' , 'bfchris' );

    Read from here for global information:

    Posting Activity from Plugins

    Here for an example:
    https://buddypress.org/support/topic/cant-seem-to-get-bp-2-2s-post-types-activities-working/

    And here for what you have to do for your specific activities

    Add custom filters to loops and enjoy them within your plugin

    puffyjoe
    Participant

    This is what I have so far. It doesn’t update the meta table correctly, only putting in the meta name not the values, which are blank

    
    function add_location()
    {
        echo '<div class="form" style="margin-top: 20px;">';    
        echo '<label style="font-weight: bold;font-size:2.1">loc? </label>&nbsp;&nbsp;<input value="" style="width: 200px; margin-right: 20px;" placeholder="" id="location" name="location" ><br><br>';
        echo '<label style="font-weight: bold;font-size:2.1">rating?</label>&nbsp;&nbsp;<select style="width: 140px;" id="rating" name="rating" >';
        echo '<option value="5">Amazing!</option><option value="4">Excellent</option><option value="3">Great</option><option value="2">So - So</option><option value="1">Sucks!</option>';
        echo '</select>';
        echo '</div>';
    }
    add_action( 'bp_activity_post_form_options', 'add_location', 10, 3);
    
    function add_rating_to_activity( $content, $user_id, $activity_id ) 
    {
    	bp_activity_update_meta( $activity_id, 'location', $_POST['location'] );
    	bp_activity_update_meta( $activity_id, 'rating', $_POST['rating'] );
    }
    add_action( 'bp_activity_posted_update', 'add_rating_to_activity', 10, 3 );
    
    function add_data_to_activity_item() 
    {
    
    	$location = bp_activity_get_meta( bp_get_activity_id(), 'location' );
    	$rating   = bp_activity_get_meta( bp_get_activity_id(), 'rating' );
    
    	echo '<br><br><span><b>I am at:&nbsp;</b>' . $location . '</span>';
    	echo '<br><span><b>Rating:</b>&nbsp;' . $rating . '</span><br>';
    
    //  ‘
    
    }
    add_action( 'bp_activity_entry_meta', 'add_data_to_activity_item',10,3 );
    

    I remember something about having to set the ids for the posted values in global.js? seems like I shouldnt have to put code into core files right? I tried modifying it for location to no avail…

    /* Default POST values */
    		var object = '';
    		var item_id = jq("#whats-new-post-in").val();
    		var content = jq("textarea#whats-new").val();
    		var ch_location = jq("input#location").val();
    
    		/* Set object for non-profile posts */
    		if ( item_id > 0 ) {
    			object = jq("#whats-new-post-object").val();
    		}
    
    		jq.post( ajaxurl, {
    			action: 'post_update',
    			'cookie': bp_get_cookies(),
    			'_wpnonce_post_update': jq("input#_wpnonce_post_update").val(),
    			'content': content,
    			'location':ch_location,
    			'object': object,
    			'item_id': item_id,
    			'_bp_as_nonce': jq('#_bp_as_nonce').val() || ''
    		},
    
    #236789
    danbp
    Participant

    I guess you have to fetch the activity type and the content first.
    You probably can find some snippets which will guide you by using a forum search.
    https://buddypress.org/support/search/bp_activity_entry_meta/

    #234564
    danbp
    Participant

    hi @mahdiar,

    of course there is a way ! 😉

    Add this to bp-custom.php, and tell us if it is what you needed

    
    function bpfr_fav_count() {
    	
    	// bail if activity component is not used
    	if ( !bp_is_active( 'activity' ) ) {
    		return false;
    	}
    
    	// action
    	$my_fav_count = bp_activity_get_meta( bp_get_activity_id(), 'favorite_count' );
    
    	// formating action result
    	if ( ! empty( $my_fav_count ) ) {
    		$text = sprintf( _n( 'Favorited by %d user.', 'Favorited by %d users.', $my_fav_count, 'text_domain' ), bp_core_number_format( $my_fav_count ) );	
    	}
    	
    	// output
    	echo $text;
    }
    add_action( 'bp_activity_entry_meta', 'bpfr_fav_count' );
    milenushka
    Participant

    Wow, @shanebp, thank you so much! That worked perfectly!

    Perhaps you can help me with something else, i’ve been struggling for some time?

    I would like to add the featured image to these activity updates (whether it’s a regular blog post or the custom post – such as projects).

    I found this code before- this one is for posts. It works, but there is something in it that makes all the excerpts in the activity – short and unclickable.
    Also some custom post types do not show the attached image.

    function icondeposit_bp_activity_entry_meta() {
     
        if ( bp_get_activity_object_name() == 'blogs' && bp_get_activity_type() == 'new_blog_post' ) {?>
            <?php
            global $wpdb, $post, $bp;
            $theimg = wp_get_attachment_image_src(  get_post_thumbnail_id( bp_get_activity_secondary_item_id() ) );
            ?>
            <img src="<?php echo $theimg[0]; ?>" >
     
        <?php }
     
    }
    add_action('bp_activity_excerpt_append_text', 'icondeposit_bp_activity_entry_meta');

    And another thing I was researching and could find any reference to :
    How can I add the group description to the activity update?
    I think if it shows up in the activity- it should at least carry some information that will make members want to click and join the group.

    Thank you for your help!

    #175247
    Matt McFarland
    Participant

    Here’s MY entry.php file

    please don’t mind the bootstrap integration :p

    <?php
    
    /**
     * BuddyPress - Activity Stream (Single Item)
     *
     * This template is used by activity-loop.php and AJAX functions to show
     * each activity.
     *
     * @package BuddyPress
     * @subpackage bp-legacy
     */
    global $wpdb, $post, $bp;
    ?>
    
    <?php do_action( 'bp_before_activity_entry' ); ?>
    <?php echo $bp->current_item; ?>
    <li class="panel <?php bp_activity_css_class(); ?>" style="padding-top:0;" id="activity-<?php bp_activity_id(); ?>">
    	<div class="panel-heading" style="padding-top:0;">
    		<span class="activity-avatar">
    			<a href="<?php bp_activity_user_link(); ?>">
    				<?php bp_activity_avatar(); ?>
    			</a>
    		</span>
    			<?php bp_activity_action(); ?>
    	</div>
    	<div class="panel-body activity-content">
    		<?php if ( bp_activity_has_content() ) : ?>
    
    			<div class="activity-inner" >
    				<?php bp_activity_content_body();
    				
    				$blogpost_id = bp_get_activity_secondary_item_id();
    				if ($blogpost_id) :
    					if (has_post_thumbnail( $blogpost_id ) )	:
    						$theimg = wp_get_attachment_image_src( get_post_thumbnail_id( $blogpost_id ) ); ?>
    						<a href="<?php echo get_post_permalink($blogpost_id); ?>"> <img style="thumbnail" style="width:100%;" src="<?php echo $theimg[0]; ?>"></a>
    					<?php endif; ?>
    				<?php endif; ?>
    			</div>
    
    		<?php endif; ?>
    
    		<?php do_action( 'bp_activity_entry_content' ); ?>
    
    		<div class="activity-meta">
    			<?php if ( bp_get_activity_type() == 'activity_comment' ) : ?>
    
    				<a href="<?php bp_activity_thread_permalink(); ?>" type="button" class="button button-xs view" title="<?php _e( 'View Conversation', 'buddypress' ); ?>"><?php _e( 'All Comments', 'buddypress' ); ?></a>
    
    			<?php endif; ?>
    			<?php if ( is_user_logged_in() ) : ?>
    				<?php if ( bp_activity_can_comment() ) : ?>
    					<a href="<?php bp_activity_comment_link(); ?>" type="button" class="button button-xs acomment-reply"  id="acomment-comment-<?php bp_activity_id(); ?>"><i class="fa fa-comment"></i><?php printf( __( 'Comment <span>%s</span>', 'buddypress' ), bp_activity_get_comment_count() ); ?></a>
    				<?php endif; ?>
    				
    				<?php if ( bp_activity_can_favorite() ) : ?>
    
    					<?php if ( !bp_get_activity_is_favorite() ) : ?>
    
    						<a href="<?php bp_activity_favorite_link(); ?>" type="button" class="button button-xs fav"  title="<?php esc_attr_e( 'Mark as Favorite', 'buddypress' ); ?>"><i class="fa fa-thumbs-up"></i><?php _e( 'Favorite', 'buddypress' ); ?></a>
    
    					<?php else : ?>
    
    						<a href="<?php bp_activity_unfavorite_link(); ?>" class="button button-xs unfav bp-secondary-action"  title="<?php esc_attr_e( 'Remove Favorite', 'buddypress' ); ?>"><i class="fa fa-remove"></i><?php _e( 'UnFavorite', 'buddypress' ); ?></a>
    
    					<?php endif; ?>
    
    				<?php endif; ?>
    				
    				<?php if ( bp_activity_user_can_delete() ) {
    					echo '<a href="'.bp_get_activity_comment_delete_link().'" type="button" class="button button-xs item-button bp-secondary-action delete-activity confirm" rel="nofollow"><i class="fa fa-trash-o"></i>Remove</a>';
    					
    					} ?>
    				<?php do_action( 'bp_activity_entry_meta' ); ?>
    				
    			<?php endif; ?>
    		</div>
    
    	</div>
    
    	<?php do_action( 'bp_before_activity_entry_comments' ); ?>
    
    	<?php if ( ( is_user_logged_in() && bp_activity_can_comment() ) || bp_activity_get_comment_count() ) : ?>
    
    		<div class="activity-comments">
    
    			<?php bp_activity_comments(); ?>
    
    			<?php if ( is_user_logged_in() ) : ?>
    
    				<form action="<?php bp_activity_comment_form_action(); ?>" method="post" id="ac-form-<?php bp_activity_id(); ?>" class="ac-form"<?php bp_activity_comment_form_nojs_display(); ?>>
    					<div class="ac-reply-avatar"><?php bp_loggedin_user_avatar( 'width=' . BP_AVATAR_THUMB_WIDTH . '&height=' . BP_AVATAR_THUMB_HEIGHT ); ?></div>
    					<div class="ac-reply-content">
    						<div class="ac-textarea">
    							<textarea id="ac-input-<?php bp_activity_id(); ?>" class="ac-input" name="ac_input_<?php bp_activity_id(); ?>"></textarea>
    						</div>
    						<input type="submit" name="ac_form_submit" value="<?php _e( 'Post', 'buddypress' ); ?>" /> &nbsp; <a href="#" class="ac-reply-cancel"><?php _e( 'Cancel', 'buddypress' ); ?></a>
    						<input type="hidden" name="comment_form_id" value="<?php bp_activity_id(); ?>" />
    					</div>
    
    					<?php do_action( 'bp_activity_entry_comments' ); ?>
    
    					<?php wp_nonce_field( 'new_activity_comment', '_wpnonce_new_activity_comment' ); ?>
    
    				</form>
    
    			<?php endif; ?>
    
    		</div>
    
    	<?php endif; ?>
    
    	<?php do_action( 'bp_after_activity_entry_comments' ); ?>
    
    </li>
    
    <?php do_action( 'bp_after_activity_entry' ); ?>
    

    Fits with my theme, might not yours (my thumbnails are larger than default and I’m using a masonry layout) see it at http://www.hvac-hacks.com/activity

    #175246
    Matt McFarland
    Participant

    Yes this is very easy to do.

    Adding the featured image of a wordpress post into a buddypress activity stream can be done by doing one of the following. I’d like to add that I had trouble finding out how to do this at first and it took a lot of searching. The first copypasta I have for you was actually found on these very forums. However, due to so many people asking this question (and not getting answers) it is buried and very difficult to find. So without further ado please enjoy…

    You can either edit the activity page activity/entry.php or just copy paste the following function into your functions.php file.

    
    function icondeposit_bp_activity_entry_meta() {
     
        if ( bp_get_activity_object_name() == 'blogs' && bp_get_activity_type() == 'new_blog_post' ) {?>
            <?php
            global $wpdb, $post, $bp;
            $theimg = wp_get_attachment_image_src(  get_post_thumbnail_id( bp_get_activity_secondary_item_id() ) );
            ?>
            <img src="<?php echo $theimg[0]; ?>" >
     
        <?php }
     
    }
    add_action('bp_activity_excerpt_append_text', 'icondeposit_bp_activity_entry_meta');
    

    If you want further customization, I recommend editing activity/entry.php

    #174167
    tse11
    Participant

    So I answered my own question by just experimenting. I figure I go ahead and let everyone who is interested in this know how I got everything working. I used the following code and placed it in my bp-custom.php

    function my_favorite_count() {
    
    $my_fav_count = bp_activity_get_meta( bp_get_activity_id(), 'favorite_count' );
    
    if ($my_fav_count >= 1) : {
    
    if (is_user_logged_in()) : { echo '<span class="fav-count">('.$my_fav_count.')</span>';
    
    }
    
    endif;
    
    }
    
    endif;
    
    }
    
    add_action( 'bp_activity_entry_meta', 'my_favorite_count' );

    I added a span class in this code as you can see, and that is how I managed to display the count directly next to favorites button (or link).

    I added this to my css:

    .fav-count {
    margin-left: -15px !important;
    }

    You may have to play with it to get the margin just right, hope this helps someone.

    #134181
    @ChrisClayton
    Participant

    It will do_(any)_action you tell it to do ;)

    `function cc_awesome_activity_meta_shortcodes() {
    echo do_shortcode(‘SexyButton’);
    }

    add_action(‘bp_activity_entry_meta’, ‘cc_awesome_activity_meta_shortcodes’);
    `

    Or, activity/entry.php

    José M. Villar
    Participant

    I have the following code in my bp-custom.php file
    `function my_bp_activity_entry_meta() {

    if ( bp_get_activity_object_name() == ‘blogs’ && bp_get_activity_type() == ‘new_blog_post’ ) {?>
    <a class="view-post" href="”>Ver nuevo post
    <?php }

    if ( bp_get_activity_object_name() == ‘blogs’ && bp_get_activity_type() == ‘new_blog_comment’ ) {?>
    <a class="view-post" href="”>Ver comentario
    <?php }

    if ( bp_get_activity_object_name() == ‘activity’ && bp_get_activity_type() == ‘activity_update’ ) {?>
    <a class="view-post" href="”>Ver actualizacion
    <?php }

    if ( bp_get_activity_object_name() == ‘groups’ && bp_get_activity_type() == ‘new_forum_topic’ ) {?>
    <a class="view-thread" href="”>Ver hilo en el foro
    <?php }

    if ( bp_get_activity_object_name() == ‘groups’ && bp_get_activity_type() == ‘new_forum_post’ ) {?>
    <a class="view-post" href="”>Ver respuesta en el foro
    <?php }

    }
    add_action(‘bp_activity_entry_meta’, ‘my_bp_activity_entry_meta’);`

    Trim what you don’t need. Mine is translated to spanish also

    #93407
    Nick
    Participant

    Latest attempts:

    If I type in:
    `function my_equipmeta() {
    $my_equipmeta = ‘joe’;
    //if (is_user_logged_in()) : {
    echo ‘(‘ . $my_equipmeta . ‘)‘;
    //}
    //endif;
    }
    add_action( ‘bp_activity_entry_meta’, ‘my_equipmeta’ );`

    I can see the name ‘joe’ in the activity. That’s a good start

    If I input `$my_equipmeta = the_meta();`

    I see some custom field info but not all of the info displayed for each post is the meta stored with that post. IE some custom fields are showing up in posts that do not have that info stored. In other words it doesn’t appear to be working the way I need it to.

    Lastly:
    If I input:
    `$my_equipmeta = get_post_meta($post->ID, ‘Make’, true);`

    I receive nothing in return.

    I will keep tinkering but if anyone sees an error feel free to let me know. Thanks.

    #85291

    In reply to: Google Buzz button

    r-a-y
    Keymaster

    Instead of modifying a template file, you can also hook into the following action:
    bp_activity_entry_meta.

    function my_gbuzz() {
    echo ‘whatever’;
    }
    add_action( ‘bp_activity_entry_meta’, ‘my_gbuzz’ );

    #71963
    gabrielcrowe
    Member

    oh lordy, i think i sorted it, and for those interested, here is the deal:

    – in post-form.php, i have another input field with the ID: ‘trackstr’

    – create a plugin in wp-content/plugins: ‘bp-custom.php’

    – customise the below function to your custom capture needs:

    function add_trackmeta_to_activity( $content, $user_id, $activity_id ) {

    bp_activity_update_meta( $activity_id, ‘trackmd5’, md5($_POST[‘trackstr’]) );

    }

    add_action( ‘bp_activity_posted_update’, ‘add_trackmeta_to_activity’, 10, 3 );

    function my_trackmeta() {

    $my_trackmeta = bp_activity_get_meta( bp_get_activity_id(), ‘trackmd5’ );

    //if (is_user_logged_in()) : {

    echo ‘<span class=\’trackmeta-md5\’>(‘ . $my_trackmeta . ‘)</span>’;

    //}

    //endif;

    }

    add_action( ‘bp_activity_entry_meta’, ‘my_trackmeta’ );

    … additional metadata is captured and stored with your posts.

    sorry for not searching and readin up on this before i jumped in and gave it a go chaps and chapettes, but here is how i solved my own problem anyhow. :)

    #65486
    ousep
    Participant

    @snark: Try this, for pluralization…

    function my_favorite_count() {
    $my_fav_count = bp_activity_get_meta( bp_get_activity_id(), 'favorite_count' );
    if ($my_fav_count >= 1) : {
    if (is_user_logged_in()) : {
    echo '<span>(' . $my_fav_count . ')</span> favorite';
    if ($my_fav_count > 1) :
    {echo 's';} //this turns favorite into favorites :)
    endif;
    }
    endif;
    }
    endif;
    }
    add_action( 'bp_activity_entry_meta', 'my_favorite_count' );

    I’ve been sidetracked by a couple of other things that needed my attention, so I haven’t been able to make it do what I’d really like it to do, ie: show the number within the favorite link, like it shows in the reply link:

    [Reply (12)] [Favorite (23)].

    For consistency.

    And the other issue of updating the number on clicking the link.

    And, showing the users who’ve favourited the activity.

    About the other issue, I’ve been trying to find the source of those links, too… Not much luck with that, yet.

    #65001
    ousep
    Participant

    @snark: I’ve modified the function to this:

    function my_favorite_count() {
    $my_fav_count = bp_activity_get_meta( bp_get_activity_id(), 'favorite_count' );
    if ($my_fav_count >= 1) : {
    if (is_user_logged_in()) : {
    echo '<span>(' . $my_fav_count . ')</span>';
    }
    endif;
    }
    endif;
    }
    add_action( 'bp_activity_entry_meta', 'my_favorite_count' );

    Apart from shortening my function name, this shows the count only if the visitor is logged in.

    This code goes into bp-custom.php, and it outputs the count next to the Favorite or Remove Favorite button.

Viewing 20 results - 1 through 20 (of 20 total)
Skip to toolbar