• Resolved captainmack90

    (@captainmack90)


    Hi,

    I’m using the 3.3.1 beta:

    Have anybody tried to send a message programmatically based on e.g. user id? Let’s say I have a function that executes in functions.php, how do I send a message through Front End PM to that user (I guess from a system account?). Does a hook/filter exist for this purpose?

    Again, thanks for such an awesome plugin Shamim Hasan.

    – Chris

    https://www.ads-software.com/plugins/front-end-pm/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Shamim Hasan

    (@shamim51)

    use fep_send_message()

    Thread Starter captainmack90

    (@captainmack90)

    How do you use it? As far as I could read from the code, I needed to do the following:

    //Send private message to guest.
      $message['message_to_id'] = $guest_id;
      $message['message_title'] = $current_user->user_firstname . __('  confirmed you', 'text-domain');
      $message['message_content'] = __('You have been confirmed as a guest on ','text-domain') . get_post_meta($event_id, '_job_title', true);
      fep_send_message($message);

    Are there more requirements than the three fields? When sending messages from the system.

    Plugin Author Shamim Hasan

    (@shamim51)

    If you do not set post_author then sender will be current user

    Thread Starter captainmack90

    (@captainmack90)

    How would that look? I’ve looked through the code and came up with the following, which does not work:

    //Send private message to guest.
      $message['message_to_id'] = $guest_id;
      $message['post_author'] = 1; //TODO: Change to System user ID
      $message['message_title'] = $full_name . __(' have confirmed you', 'text-domain');
      $message['message_content'] = __('You have been confirmed') . '"' . get_post_meta($event_id, '_job_title', true) . '"';
    
      fep_send_message($message);

    How can you set the post_author? So the “from user” is not the current user?

    Btw. the latest commit fixed the unread message count problem!
    Thanks!

    Plugin Author Shamim Hasan

    (@shamim51)

    second argument support $override as array. Supply any value which you want to override.
    try following way

    //Send private message to guest.
      $message['message_to_id'] = $guest_id;
      //$message['post_author'] = 1; //TODO: Change to System user ID
      $message['message_title'] = $full_name . __(' have confirmed you', 'text-domain');
      $message['message_content'] = __('You have been confirmed') . '"' . get_post_meta($event_id, '_job_title', true) . '"';
    
    	$override = array (
    		'post_author' => $author_id
    		);
      fep_send_message($message, $override );

    Also let me know if you found issue about nicename with dashes.

    Thread Starter captainmack90

    (@captainmack90)

    Thank you Shamim! That worked straight away.
    There was no problem regarding dashes, I found that someone had switched on some caching, preventing me from seeing any arriving messages.

    Everything working perfectly as of now – great plugin!

    hi
    i tried frontend pm i want to know is it possible,
    my requirement is
    i want a system i which user can only send message to admin (TO column is hidden, it by default is set to admin)
    second a user and admin see all previous conversation between them in one place

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How do you send a message programmatically?’ is closed to new replies.