Skip to:

Re: Extending Activity: How to Store Additional Info?

Boone Gorges


The WordPress Codex has detailed instructions on extending the software without modifying core files: In short: wherever you see do_action or apply_filters in the BP/WP core files, a hook is being created. You can then write custom functions in a plugin file that modifies WP’s behavior without modifying the core code by hooking into those actions or filters.

Short example: If you want to add a piece of metadata to an activity item, you might try something like this (in a file called bp-custom.php in wp-content/plugins):

function add_genre_to_activity( $content, $user_id, $activity_id ) {
if ( strpos( $content, 'rock' ) )
bp_activity_update_meta( $activity_id, 'genre', 'rock' );
add_action( 'bp_activity_posted_update', 'add_genre_to_activity', 10, 3 );

which will add the meta value ‘rock’ (key ‘genre’) whenever an activity item contains the word ‘rock’. Of course, this is probably not how you want to determine the genre, but this shows you how to add the metadata without touching core code.

Skip to toolbar