Skip to:
Content
Pages
Categories
Search
Top
Bottom

function to send a private message

  • Is there a function that can be used to send a private message?

    Currently on my site when an image is denied an email is sent out to the user telling them, however this can often end up in the users spam folder, and the user can’t respond directly to the person denying the image.

    What I would like to do instead is when an image is denied, automatically send a private message from the moderator to the contributor, does anyone know of a function (I tried looking through the plugin source, but couldn’t really find anything useful) or can help me do this?

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

  • shanebp
    Moderator

    @shanebp

    The function is messages_new_message()

    > when an image is denied an email is sent out to the user

    So you have a function or some code that does that, yes?
    Then you could use parts of the below in that code or call it as a function

    `

    function bp_send_image_denied_message() {
    global $bp;

    //check_admin_referer(message_check”); // adjust if needed

    $sender_id = $bp->loggedin_user->id; // moderator id ?
    $recip_id = $bp->displayed_user->id; // denied image user id ?

    if ( $thread_id = messages_new_message( array(‘sender_id’ => $sender_id, ‘subject’ => ‘Image Denied, ‘content’ => ‘why it was denied], ‘recipients’ => $recip_id ) ) ) {
    bp_core_add_message( __( ‘Image Denied Message was sent.’, ‘buddypress’ ) );
    bp_core_redirect( $bp->displayed_user->domain ); // adjust as needed
    } else {
    bp_core_add_message( __( ‘There was an error sending that Private Message.’, ‘buddypress’ ), ‘error’ );
    }

    }
    add_action( ‘wp’, ‘bp_send_image_denied_message’, 3 );
    `

    Thanks so much for that, it’s used within a plugin so I used:
    `
    function bp_send_image_denied_message($sender_id, $recip_id, $subject, $message) {
    global $bp;
    if ( $thread_id = messages_new_message( array(‘sender_id’ => $sender_id, ‘subject’ => $subject, ‘content’ => $message, ‘recipients’ => $recip_id ) ) ) {
    bp_core_add_message( __( ‘Image Denied Message was sent.’, ‘buddypress’ ) );
    } else {
    bp_core_add_message( __( ‘There was an error sending that Private Message.’, ‘buddypress’ ), ‘error’ );
    }

    } `
    and pass the required bits, the only thing it’s not doing is adding a notification item, is there an easy way to add that?

    Again, thanks a lot, I would have spent ages trying to figure that out.

    Ignore that, I had a look at the messages_new_message function and realised it should be sending a notification so I guessed the issue was I was testing using the same id for uploader and denyer, i changed to another uploader and it worked perfectly :)

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘function to send a private message’ is closed to new replies.
Skip to toolbar