BuddyDev

Search

[Resolved] Mediapress Actions/Filters

  • Participant
    Level: Master
    Posts: 152
    NikB on #20713

    Hi there

    I realise it’s something you’re planning to add in the future but I urgently need to be able to email users when someone comments on their single media page (or in the lightbox) so decided to see if I can write my own plug-in for this.

    I’m getting there but I can’t work out what action/filter I need to hook into to trigger the email eg. example from the WordPress Codex –

    add_action( ‘wp_insert_comment’,’codex15766_comment_inserted’, 99, 2 );

    … obviously I need to replace wp_insert_comment with some other action/filter from Mediapress (or even Buddypress). Do you have any hints/suggestions as what that might be?

    (I did try looking at how/when notifications were triggered since I assume emails could follow the same path but unfortunately that didn’t seem very obvious either.)

    With many thanks in advance.
    Nikki

  • Keymaster
    (BuddyDev Team)
    Posts: 21837
    Brajesh Singh on #20716

    Hi Nikki,
    Thank you for asking.

    Currently, the commenting is not handled in the best way in MediaPress.

    Here is how we approach it.

    1. Any comment in the activity stream is handled by Your theme as normal BuddyPress Activity comment. To check if it was a MediaPress upload, check for the parent activity(top level’s) type.

    2. Commenting on a single gallery, single media page and in the lightbox is handled by MediaPress. A reply on some’s comment is a BuddyPress Activity comment while a complete new comment is stored as activity update(for user/group depending on media component).

    In other words, when someone writes a comment on a media(in lightbox,single page) or a gallery(on single page), It can be stored as an activity update or an activity comment. If the comment is a reply to someone else’s comment on the media, it is stored as activity comment.
    If it is a brand new comment directly on the media/gallery, It is stored as an activity update.

    I am not sure if the above makes much sense to you as the current implementation lacks simplicity for commenting.

    It is on our list for next major release.

    Regards
    Brajesh

  • Participant
    Level: Master
    Posts: 152
    NikB on #20723

    Hi Brajesh

    Thank you as always for your prompt reply and actually yes that does all make sense as I’d noticed that a brand new comment on single media was shown as media update and I couldn’t quite work out why but at least I understand some of the logic behind that now.

    Assuming that’s the (main) action I want to target, what action/filter should I be hooking into to send my email?

    As you say, comments in the activity stream aren’t a problem as those are already handled, including emails (and could be refined if necessary).

    Of course, I realise your new release will probably make my efforts redundant but the site is already live and members need this feature urgently… plus I’ve set myself the challenge now and really want to see if I can make it work 😉

    With many thanks again.
    Nikki

  • Participant
    Level: Master
    Posts: 152
    NikB on #20757

    Hi again Brajesh

    Just wondering if you’ve had any thoughts on this and/or whether I made myself clear.

    I’ve now almost completed a plug-in which works with WP ULike to send out email notifications when someone likes various activities (including media) and I really want to add the same feature when someone comments on a single media page or in the lightbox.

    So for example, for WP Ulike it works as follows –

    add_action( ‘wp_ulike_after_process’, array( $this, ‘notify_likes’ ), 10, 4 );

    All(?) I need to do now is figure out which action to use instead of wp_ulike_after_process in order to trigger emails for Mediapress comments too.

    I’ll keep looking but if you have any thoughts, I’d be very grateful… and of course, if you’re interested, very happy to share my code once it’s complete 😉

    Warm regards
    Nikki

  • Keymaster
    (BuddyDev Team)
    Posts: 21837
    Brajesh Singh on #20773

    Hi Nikki,
    Sorry for the delayed reply.

    The activity type to look for is

    mpp_media_upload

    and you should hook to

    
    bp_activity_after_save
    
    

    This action gives you access to activity object.

    Please do note that make sure to test against the $activity->user_id and logged in user id. You do not want to notify the user on their own upload etc.

    Another thing to consider your attached function will succeed on:-
    – Any gallery activity(new media added to gallery and posted in activity stream)
    – New media uploaded from activity stream
    – New post on a media in light box
    – New post on a gallery on single gallery page
    – New post on a media on single media page

    For replies, the correct approach is to check for the parent activity(top level)’s type and see if it is mpp_media_upload

    Like I have said earlier, In my quest to maximize the usage of inbuilt BP features, I believe using activity for comment was a mistake and I will be correcting it in the next major milestone and re-implement the whole commenting.

    Regards
    Brajesh

  • Participant
    Level: Master
    Posts: 152
    NikB on #20775

    Thank you so much Brajesh. That’s really helpful and I do agree it’s not an easy task working around all the possible options available in BP.

    To keep things simple for the end users (and myself!), I restrict how/where they can can comment and/or like so for example, they can only comment on media on the single media page or in the lightbox which seems more logical to me personally and also avoids some of the scenarios that you’ve mentioned above but obviously if you’re working on a more generic plug-in you may have to cater for end-users who find that too restrictive 😉

    Good luck and will look forward to seeing the results of your efforts in due course… even if I may have to revise my own solutions when the next release comes out!

    Warm regards
    Nikki

  • Keymaster
    (BuddyDev Team)
    Posts: 21837
    Brajesh Singh on #20785

    Hi Nikki,
    Thank you for the patience with me on this.

    I will make sure to let you know(via PM) when I do add the future commenting strategy.

    Good to know that you have the commenting enabled in more organized way.

    Bets regards
    Brajesh

  • Participant
    Level: Master
    Posts: 152
    NikB on #20831

    Hi Brajesh

    Unfortunately hooking to bp_activity_after_save is triggering twice and therefore I am getting duplicate emails sent out.

    Not very helpfully, I can’t post my code right now but if you have any suggestions as to what might be happening or a work around, I would be hugely grateful.

    Note: I’ve tested the entire code with a different hook (ie. wp_ulike_after_process) which I know only works once and it all works fine so I don’t think it’s the code itself that’s the issue, perhaps just the wrong hook…

    Warm regards
    Nikki

  • Participant
    Level: Master
    Posts: 152
    NikB on #20866

    Just to say I’ve fixed this by adding if ( did_action( 'bp_activity_after_save' ) === 1 ) though still no idea why it was saving twice 😉

    Either way… no further assistance required on this for now.

  • Keymaster
    (BuddyDev Team)
    Posts: 21837
    Brajesh Singh on #20870

    Hi Nikki,
    Thank you.
    I am glad you resolved it.

    I hope that more sanity will prevail in our future updates.

    Regards
    Brajesh

You must be logged in to reply to this topic.

This topic is: resolved