Skip to:
Content
Pages
Categories
Search
Top
Bottom

Extending Activity: How to Store Additional Info?


  • huntermaster
    Participant

    @huntermaster

    First off, BP is quite impressive, nice work. I’m a PHP programmer getting ready to hack the BP core but I was hoping for some input. I would like to add an additional field to the /activity/ screen. This concerns the Buddpress plugin at wp-content/buddypress.

    First I add a new dropdown genre to the html form in ../themes/theme/activity/post-form.php

    Option 1:

    1. add a new field genre to the database.bp_activity table
    2. bp-themes/bp-default/_inc/global.js add the data to the ajax post
    3. bp-themes/bp-default/_inc/ajax.php add the data to the parameter array in bp_dtheme_post_update()
    4. bp-activity.php add the data to the parameter array in bp_activity_post_update()
    5. bp-activity/bp-activity-classes.php add the data to the sql string in save()

    Option 2:

    Could I do something like…

    bp_activity_update_meta( $activity_id, 'genre', $_POST['genre'] );

Viewing 3 replies - 1 through 3 (of 3 total)

  • Boone Gorges
    Keymaster

    @boonebgorges

    Definitely do Option 2. Use that kind of line inside of a function that will then be hooked something like this:

    add_action( 'bp_activity_add', 'my_custom_activity_meta_stuff', 10, 1 )

    If you then want to allow filtering by genre, you’ll have to add an option to the dropdown at this action: bp_activity_filter_options

    I can’t tell just by glancing at the code – will additional filters then be handled automatically by bp-default’s ajax.php and global.js?


    huntermaster
    Participant

    @huntermaster

    Where do I place that add_action hook outside of core files? The ajax posts to /wp-load.php and gets captured in bp-core.php.bp_core_add_ajax_hook() which runs do_action(‘wp_ajax_post_update’). I can’t seem to “get my hooks in”, so to speak. I suppose I can hack one of the core files.

    As far as filters go, I have no idea what’s going on there yet, but my main focus is to modify my theme’s archive.php file to display all BP activity for the current genre (category). So I need to somehow read back thru the meta data.


    Boone Gorges
    Keymaster

    @boonebgorges

    The WordPress Codex has detailed instructions on extending the software without modifying core files: https://codex.wordpress.org/Plugin_API. 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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Extending Activity: How to Store Additional Info?’ is closed to new replies.
Skip to toolbar