Skip to:
Content
Pages
Categories
Search
Top
Bottom

Add custom field to activity feed


  • deadbeat007
    Participant

    @deadbeat007

    I’m hoping to customize my activity feed so that it displays the usual textbox (to input the profile update), a “+” button, and a submit button. When clicked, the “+” button would open a full list of members, so users can tag/mention whichever user they click (so they don’t have to type @mention into their message).

    I figured the easiest way to do this would be to add a custom field to the activity feed form. I could create a popup that would display all members, and then feed the chosen member through after post submission, so it would display alongside the post.

    I tried following the following tutorial, but my post data would not save:
    https://buddypress.org/support/topic/adding-a-second-element-for-posting-with-an-activity/

    Does anyone have any ideas for this? Are there any plugins that might achieve something similar?

    Thanks!

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

  • Henry Wright
    Moderator

    @henrywright

    My first thought is how best to open a selectable list of members. You could use a modal but if the list of members is long (30 or more) then a modal + list might not be the best approach.


    deadbeat007
    Participant

    @deadbeat007

    Good point, Henry — I’ll have to rethink the layout. In the meantime, I was wondering if you could answer one more question for me:

    If a post in the acvitity feed has an @mention, is there any way to pull the username and avatar of the mentioned user?

    Thanks!


    Henry Wright
    Moderator

    @henrywright

    Do you mean grab the username and avatar of @-mentioned users for a) activity items already posted or b) new activity items going forward?


    deadbeat007
    Participant

    @deadbeat007

    B) new activity items going forward

    The premise of my client’s site is basically Twitter, but for quotes. A user can enter a quote that their friend said, then tag their friend (assuming the friend has an account) and attribute the quote to them.

    The quote will then appear in the activity stream, along with the tagged user’s avatar and username.

    I figured BuddyPress would be my best bet for this, since it allows users to add friends and @mention other users, but now I’m a bit lost as to how to manage what my client it looking for.


    Henry Wright
    Moderator

    @henrywright

    Right, I see! I’m thinking you’ll need to use a regular expression to get the mentioned user’s username from the activity item’s text. Then you can do a user lookup using that username. From there you’ll have everything you need to know about the mentioned user.


    deadbeat007
    Participant

    @deadbeat007

    That makes sense, thanks! Do you have any idea how I’d find the username from the activity item’s text? Would it be easiest to search for any text preceded by a “@”?


    Henry Wright
    Moderator

    @henrywright

    Would it be easiest to search for any text preceded by a “@”?

    Yeah that’s a good idea. The regex pattern you’ll need will be something like @[0-9a-Z_-]+. That will find within the activity item’s text all strings that begin with an @ character which is followed by one or more lowercase or uppercase characters, including numbers and the – and _ characters. Please note I haven’t tested.


    Henry Wright
    Moderator

    @henrywright

    Oh, and you’ll need preg_match().

    Ref: http://php.net/manual/en/function.preg-match.php


    Bughy
    Participant

    @bughy

    I would like to use a custom field to make an activity post sticky.. But where can I find the code that displays the activity feed? So I can alter the query a bit.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Add custom field to activity feed’ is closed to new replies.
Skip to toolbar