I would like to do the following:

Registered users in my wordpress application can receive messages. They can choose to receive messages in the following ways:

  • The WordPress application (Inbox system)
  • SMS message
  • Email

I would like to use the Front End PM plugin to send messages in portal. For the sms messages I would use the Twilio plugin.

So when they sent a message (functionality by Front end PM plugin) I would like to call another function in the Twilio plugin to send an SMS.

What’s the proper way to do this? I don’t think editing the function in the Front End PM plugin is the correct way to do this? How should it be done?

4 Answers
4

Levi Dulstein has a lot of righ, but in my opinion Front-end-pm uses two hooks to send messages:

  • fep_save_message (from back-end)
  • fep_action_message_after_send (from front-end)

Before sending a email few things are checked, like publishig or sending status (includes/class-fep-emails.php):

function save_send_email( $postid, $post ) {
    if ( ! $post instanceof WP_Post ) {
        $post = get_post( $postid );
    }
    if ( 'publish' != $post->post_status ){
        return;
    }       
    if ( get_post_meta( $postid, '_fep_email_sent', true ) ){
        return;
    }
    $this->send_email( $postid, $post );
}

So, for test try add something like this to your plugin or theme:

function send_sms( $postid, $post ) {
    if ( ! $post instanceof WP_Post ) {
        $post = get_post( $postid );
    }
    if ( 'publish' != $post->post_status ){
        return;
    }       
    if ( get_post_meta( $postid, '_fep_email_sent', true ) ){
        return;
    }
    // use Twilio plugin function twl_send_sms
    if( function_exists('twl_send_sms') ) {

        $participants = fep_get_participants( $postid );
        // check if recipients exists, for each get the phone number, 
        // send message and mark sms as sent (or save sms send time)
        $args = array( 
            'message' => $post->post_title, // or $post->post_content
        ); 
        foreach ($participants as $participant) {
            // get usermeta with phone number for $participant ID 
            $args['number_to'] = '098765'; 
            twl_send_sms( $args );
        }
    }
}
add_action( 'fep_save_message', 'send_sms', 99, 2 ); //sending from back-end
add_action( 'fep_action_message_after_send , 'send_sms', 99, 2 ); //front-end

Sorry for my english. I hope you understand what I want to say.

Leave a Reply

Your email address will not be published. Required fields are marked *