Skip to:
Content
Pages
Categories
Search
Top
Bottom

Adding a second element for posting with an activity.

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

  • gabrielcrowe
    Member

    @gabrielcrowe

    I think this is what i want:

    https://buddypress.org/forums/topic/extending-activity-how-to-store-additional-info

    And i’v implimented a simple plugin:

    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 );

    And it does not crash, or complain, but where does my data go? and how can i access it in my templates?


    gabrielcrowe
    Member

    @gabrielcrowe

    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. :)

    great thanks! how do you get to show a list of all the tracks that have been posted?? not the activity but just the tracks..

    could you explain this a bit more..could it be extended to include attachments to the update?

    thanks


    gabrielcrowe
    Member

    @gabrielcrowe

    Well, it looks like i spoke too soon.

    I cannot get: any $POST’ed information inside here:

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

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

    }

    $_POST[‘trackstr’] was returning an empty string, md5 hashed.

    can anyone here jump in and help? why cant i get posted items inside my bp-custom.php?


    Xevo
    Participant

    @xevo

    Cant you just add activity meta? Haven’t tried this myself, but shouldn’t be that hard.


    gabrielcrowe
    Member

    @gabrielcrowe

    more experimentation leads me to this solution:

    items from the form are passed through global.js

    i found and modified the posted items to include /match my new fields:

    /* Default POST values */

    var object = ”;

    var item_id = j(“#whats-new-post-in”).val();

    var content = j(“textarea#whats-new”).val();

    var artist = j(“input#artist”).val();

    var track = j(“input#track”).val();

    /* Set object for non-profile posts */

    if ( item_id > 0 ) {

    object = j(“#whats-new-post-object”).val();

    }

    j.post( ajaxurl, {

    action: ‘post_update’,

    ‘cookie’: encodeURIComponent(document.cookie),

    ‘_wpnonce_post_update’: j(“input#_wpnonce_post_update”).val(),

    ‘content’: content,

    ‘artist’: artist,

    ‘track’: track,

    ‘object’: object,

    ‘item_id’: item_id

    },

    and it worked just fine. _POSTed items are now available in my bp-custom.


    Boone Gorges
    Keymaster

    @boonebgorges

    @gabrielcrowe Have you dumped the whole $_POST variable to see what it looks like when bp_activity_posted_update fires? Is it totally empty, or are you just failing to populate $_POST[‘trackstr’]?

    My guess is that it’s an AJAX issue. Activity updates are handled near the top of bp-default/_inc/global.js. The reason it’s not getting written to $_POST is because it’s not being submitted as a form at all. I’m not really that great with jQuery, but I think you might have to unbind the bp-default handler for input#aw-whats-new-submit, then reproduce that javascript in your own plugin, with additional code to grab the content of your track box and submit it to your custom function.


    Boone Gorges
    Keymaster

    @boonebgorges

    Ha ha, we were writing at the same time :)

    the summary on this? how do we get it to work?


    gabrielcrowe
    Member

    @gabrielcrowe

    in summary:

    when you post items from a modified post-form.php you’re sending them through some ajax, and functions inside global.js.

    what i had to do was edit the values that were passed into the ajax inside global js.

    i have 3 fields, artist, track and cover.

    j.post( ajaxurl, {

    action: ‘post_update’,

    ‘cookie’: encodeURIComponent(document.cookie),

    ‘_wpnonce_post_update’: j(“input#_wpnonce_post_update”).val(),

    ‘content’: content,

    ‘artist’: artist, <<<

    ‘track’: track, <<<

    ‘cover’: cover, <<<

    ‘object’: object,

    ‘item_id’: item_id

    },

    (arrows added for effect)

    after that, a function in bp-custom.php can pick them up and use them as metas for the post.

    cool, thanks! 2 more questions

    1) how do you get to show a list of all the tracks that have been posted?? not the activity but just the tracks..can this be done?

    2) any idea if i wanted it to pick up when i wrote a ‘#’ in the post form?? like i wrote #artist and it turns the #artist into a link for that artist..? like how the @ mention works…


    gabrielcrowe
    Member

    @gabrielcrowe

    with number 1, id assume you’d have to loop all updates and pull out the meta on the track information.

    with number 2, where would you send the link? to a webservice?

    im not much of a coder so do you know of any example code i could use to pull out the meta on the track information?

    the link to point to a page which has all the updates in which users have used #artist for that particular artist, for example you click on #artist in an update, it takes you to a page which has all the updates that have #artist in them, you click on #ARTIST2 in an update it takes you to a page which has all the updates that have #ARTIST2 in them, n so on..


    gabrielcrowe
    Member

    @gabrielcrowe

    lol, just so you know: this is what i’m working on right now. lol. i’ll let you know IF i can get it working.

    lol greeat…i hope you manage..please do letme know how it turns out..

    thanks

    followed all the steps cant seem to get this working, it comes up blank…any idea why?


    CricketLaChica
    Member

    @cricketlachica

    Thanks a lot for this, works like a charm!


    matom
    Participant

    @matom

    This works fine for me too, thanks – but it works only for personal activity updates and I really need it to work on group updates.

    Is there a different action I need to hook this to to add meta data to group updates?

    This is what I’ve got in my functions.php

    `function add_title_to_activity( $content, $user_id, $activity_id ) {
    bp_activity_update_meta( $activity_id, ‘activity_title’, $_POST );
    }

    add_action( ‘bp_activity_posted_update’, ‘add_title_to_activity’, 10, 3 );`


    matom
    Participant

    @matom

    Found it – it needs to be hooked to bp_groups_posted_update:

    `add_action( ‘bp_groups_posted_update’, ‘add_title_to_group_activity’, 10, 4 );`


    matiou34
    Participant

    @matiou34

    Hi,
    Do you know how to add a text field in the activity stream ?

Viewing 20 replies - 1 through 20 (of 20 total)
  • The topic ‘Adding a second element for posting with an activity.’ is closed to new replies.
Skip to toolbar