Skip to:
Content
Pages
Categories
Search
Top
Bottom

Which function should I call to send private message?

  • Avatar of Mack
    Mack
    Participant

    @nebril

    Hi, I need to write a script to send private messages on buddypress site. It would take user id, title and message text and then call buddypress function to send.

    The problem is, I can’t find this function on codex docs, not even in svn. Maybe I’m not a good searcher :P

    Can anybody tell me which function I should use, or at least, where should I search for it? (besides google ;)).

    Cheers,
    Maciej

Viewing 8 replies - 1 through 8 (of 8 total)
  • Avatar of Boone Gorges
    Boone Gorges
    Keymaster

    @boonebgorges

    Check out messages_new_message() in buddypress/bp-messages.php.

    Avatar of Mack
    Mack
    Participant

    @nebril

    Thanks for quick respond :). I try to call this function, but it doesn’t seem to be working. Nothing is inserted into the bp_messages tables in wordpress db. BTW, how to open my inbox? I can’t find it even here on buddypress.org, and on the site I am working on it’s also invisible. Should I install some new plugin or what?

    Cheers,
    Maciej

    Avatar of r-a-y
    r-a-y
    Moderator

    @r-a-y

    Did you pass parameters into the messages_new_message() function?

    All the parameters can be found in the /plugins/buddypress/bp-messages.php file like Boone stated.

    Private messages are disabled on this website at the moment due to spam. However, on a regular install, simply navigate to the “My Account” menu in the BuddyPress admin bar (located at the top) and navigate to “Messages”.

    Avatar of Mack
    Mack
    Participant

    @nebril

    The function I wrote is as following -
    function send_msg($user_id, $title, $message){
    $args = “recipients=$user_id&sender_id’=11&subject’=$title&content’=$message”;

    messages_new_message( $args );
    }

    I pass only recipients id, sender id, subject and content, due to call to wp_parse_args in messages_new_message, which fills message parameters which aren’t sent with default values, I believe. But it doesn’t affect database at all, no new messages are inserted.

    About inbox, the installation I am working on is quite tweaked, so I don’t know what has been enabled and what disabled :P. But if pm’s are disabled, is there an easy way to enable them? Also if pm’s are disabled, will message_new_message function do anything at all?

    Cheers
    Maciej

    Avatar of r-a-y
    r-a-y
    Moderator

    @r-a-y

    I can see potential problems with that $args variable you have setup.
    Try setting up the arguments as an array.

    $args = array( 'recipients' => $user_id, 'sender_id' => 11, 'subject' => $title, 'content' => $message );

    If PMs are disabled, the code will not run. In fact, most likely you’ll get an undefined function error.

    Avatar of Mack
    Mack
    Participant

    @nebril

    At first I tried to send arguments the way you suggested in last post, but it didn’t work, so I tried to do it in url-style. None of these worked so far.

    Can you tell me how to enable PMs?

    Thanks for replies!

    Cheers,
    Maciej

    Avatar of r-a-y
    r-a-y
    Moderator

    @r-a-y

    Just looking over the parameters again, it appears that the “recipients” parameter should be an array.
    So try changing that.

    PMs and other BP components can be enabled/disabled from the “BuddyPress > Component Setup” page in the WP admin dashboard.

    Avatar of Mack
    Mack
    Participant

    @nebril

    Thanks a lot, my function now works. Maybe I made sth wrong with these parameters. Messages now appear in database, the problem is that PMs are enabled in buddypress settings. I guess I will have to implement inbox myself, as it would be faster :P

    Thanks for your responds again :).

    Cheers,
    Maciej

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

You must be logged in to reply to this topic.