Sending a message (or applying any other action) to (part of) a search result

BP Profile Search Sending a message (or applying any other action) to (part of) a search result

  • Author
    Post
  • #8653 Reply
    Mathias C
    Guest

    Hello.

    I’m working on a website having a lot of users, and we need a functionality to apply an action to a list of members resulting of a search – in our case, send a message.

    The functionality should provide something like this :
    1. one searches among members and BP Profile search returns a paginated list of members
    2. a checkbox is displayed next to each member, plus a checkbox allowing to select all members returned by the search
    3. one may select one or more checkboxes, and apply an action to the selected members, for ex. send a message
    (multiple selection across pages is not needed, at least at first)

    Is there any way to achieve this using existing code ?
    Otherwise, as it seems to open interesting perspectives for different usages, would you consider working on it as an extension of BP Profile Search ? We never know 🙂

    Thank you,
    Greetings,

    Mathias – Tela Botanica

    #8654 Reply
    andrea
    Plugin Author

    Hi Mathias,

    The feature you suggest is very interesting, but I think it’s unrelated to BP Profile Search. You can implement it as a directory feature, i.e. in the Members directory:

    1. a checkbox is displayed next to each member, plus a checkbox allowing to select all members in the directory page
    2. one may select one or more checkboxes, and apply an action to the selected members, for ex. send a message

    Then you can select that directory in the Form Action (Results Directory) drop-down of your search form, and the feature will work as expected with the search results.

    #8660 Reply
    Mathias C
    Guest

    Hi Andrea,

    Thank you for your answer.
    Now that you say it, yes it’s quite independent from the search feature.
    We’ll be working on it and send you feedback !

    Greetings,
    Mathias

    #8725 Reply
    Mathias C
    Guest

    Hi Andrea,

    I’m going on with the development of a “members actions” plugin, and of course would like to make it compatible with BP Profile Search. And now I’m facing an situation I don’t understand…

    To be sure to apply an action to all the search results (i.e. bypass the pagination limitations), I’d like to perform the search exactly like BP Profile Search does, and get all the corresponding user IDs, outside of the loop.

    I tried calling bps_search() : the criteria match and a subset of the users is returned, but it includes users whose account is not activated yet, and users whose account data is broken too. Whereas in the members directory loop, those unwanted extra members are not shown.

    What did I miss ? Which functions or filters should I use / apply to restrict the results and obtain the same list of users (preferably users IDs) as in the members directory ?

    Thanks a lot for any advice,
    Greetings from France

    Mathias

    #8728 Reply
    andrea
    Plugin Author

    Hi Mathias,

    My suggestion is to develop your Members Actions plugin for the standard Members directory, without being concerned about searching.

    Your plugin should put a checkbox on each member in the standard Members directory, then perform some action on the checked members (no search is involved so far).

    When you have this plugin ready, it will be automatically compatible with BP Profile Search, without further coding.

    You will be able to activate both plugins, make a profile search as usual, tick the members you want (in the standard Members directory, that now contains your search results instead), and perform the action on them.

    If you wish to see all the search results at once, you could remove the Members directory pagination, e.g. setting a page length of 100000.

    What do you think of this suggestion?

    #8729 Reply
    Mathias C
    Guest

    Hello Andrea,

    You’re right, apologies if my explanations weren’t clear enough.
    I did what you suggest and yes it works, thanks for this strategy !

    Now I’m trying to go further. If a profile search returns, say 427 results and the pagination is limited to 20 items per page, then one cannot tick more than those 20 items at a time. I’m therefore trying to add a mechanism that allows to check “apply this action to all search results (427)” (like in Gmail spam box for example).

    This leads me to propagate the BP Profile Search parameters through the action form I added, so that I can perform the search again when needed, and theoretically obtain the 427 users IDs.

    And now I’m facing the problem mentioned above : bps_search() returns more than the 427 users ID I’m looking for, because it returns all matching users even if their account is not activated, or is missing data. In other words, I have more results with bps_search() than on the members directory screen. I’m looking for a potential BP function that would filter those results the same way as in the members loop.

    Thank you again for any advice,
    All the best

    Mathias

    #8732 Reply
    andrea
    Plugin Author

    Hi Mathias,

    As you correctly noticed, the results from bps_search() must be filtered to exclude the users with ‘bad’ user status, and that’s what BP_User_Query (the Members directory) normally does.

    If you wish to replicate that yourself, you have to remove the user IDs in:

    SELECT ID FROM wp_users WHERE user_status != 0

    #8734 Reply
    Mathias C
    Guest

    Thank you very much Andrea, you save me a lot of time. I’ll try this !

    Mathias

    #8754 Reply
    Mathias C
    Guest

    Hi Andrea,

    Just for information, the plugin I wrote thanks to your precious advices :
    https://github.com/telabotanica/bp-members-directory-actions

    Have a nice day,
    Mathias

    #8759 Reply
    andrea
    Plugin Author

    Great! and thank you for sharing your work.

    #8776 Reply
    Geir
    Guest

    Mathias, I tried your plugin and it works except for when I try to send a message to all search results there is no recipients and I get an error message when I try to send the message. I did a little debugging and it seems like bps_search() is returning an empty array, what could be causing this?

    #8778 Reply
    andrea
    Plugin Author

    Hello Geir,

    I’m not sure if Mathias is still monitoring this topic, perhaps you could open an issue on https://github.com/telabotanica/bp-members-directory-actions

    #8784 Reply
    Mathias C
    Guest

    Hi Geir, Andrea,

    Yes I’m still watching this topic 🙂

    Geir, glad you like this plugin. As Andrea suggested, could you file a bug on https://github.com/telabotanica/bp-members-directory-actions/issues with as many details as possible ?
    If I can reproduce your configuration and the bug, it should be possible to solve it.

    Thank you for reporting, all the best,
    Mathias

    #8785 Reply
    andrea
    Plugin Author

    Thank you Mathias!

Reply to: Sending a message (or applying any other action) to (part of) a search result
My Information