Home › Forums › Front End PM PRO › Insert Message from another application › Reply To: Insert Message from another application
No that was not it. I could not get the fep_action_message_after_send hook
to work in this location. It would not trigger after several different approaches. My work around has been this:
`
function action_putmessage( $args ) {
global $out, $admin_user_login;
if( ! function_exists( ‘fep_send_message’ ) )
return false;
$sender = fep_get_userdata( $admin_user_login, ‘ID’, ‘login’ );
if (!$sender) {
$out[‘errmsg’] = “No such sender ‘$admin_user_login'”;
return false;
}
$recipient = fep_get_userdata( $args[‘user’], ‘ID’, ‘login’ );
if (!$recipient) {
$out[‘errmsg’] = “No such recipient ‘{$args[‘user’]}'”;
return false;
}
$message = array(
‘message_title’ => $args[‘title’],
‘message_content’ => $args[‘message’],
‘message_to_id’ => $recipient,
);
$override = array(
‘post_author’ => $sender,
);
$message_id = fep_send_message( $message, $override );
$upload_dir = wp_upload_dir();
$upload_dir = $upload_dir[‘basedir’];
$subdir = ”;
if ( get_option( ‘uploads_use_yearmonth_folders’ ) ) {
$time = current_time( ‘mysql’ );
$y = substr( $time, 0, 4 );
$m = substr( $time, 5, 2 );
$subdir = “/$y/$m”;
}
$upsub = ‘/front-end-pm’ . $subdir;
$filename = $args[‘filename’];
$newfilename = wp_unique_filename( $upload_dir, $filename );
$pathtofile = $upload_dir . $upsub . ‘/’ . $newfilename;
$content = isset( $args[‘contents’] ) ? base64_decode($args[‘contents’]) : ”;
$size_limit = (int) wp_convert_hr_to_bytes(fep_get_option(‘attachment_size’,’4MB’));
$size = strlen( $content );
if( $size > $size_limit )
return false;
$mime = isset( $args[‘mimetype’] ) ? $args[‘mimetype’] : ”;
if( !$mime || !in_array( $mime, get_allowed_mime_types() ) )
return false;
file_put_contents($pathtofile, $content);
$attachment = array(
‘guid’ => $pathtofile,
‘post_mime_type’ => $args[‘mimetype’],
‘post_title’ => preg_replace(‘/\.[^.]+$/’, ”, basename($pathtofile)),
‘post_content’ => ”,
‘post_author’ => $sender,
‘post_status’ => ‘inherit’,
);
$attach_id = wp_insert_attachment( $attachment, $pathtofile, $message_id );
}
I think it includes all the necessary checks. Can you see anything wrong with working this way? Everything works as it is. Do you have any concerns?