Search Results for 'fep_action_message_after_send'

Home Forums Search Search Results for 'fep_action_message_after_send'

Viewing 8 results - 31 through 38 (of 38 total)
  • Author
    Search Results
  • #9579
    Alex Brearley
    Participant

    Thanks Shamin for your response. How many arguments are sent from the fep_action_message_after_send action? To use fep_get_message_with_replies function, what global do I need define or what file do I need to include?

    #8361
    Shamim Hasan
    Keymaster

    when message is sent fep_action_message_after_send is fired. first argument is message id of newly created message.

    If you want to show only one message then you have to custom code for that. You can use fep_get_message_with_replies() function to retrieve any message and show them anywhere.

    #6427
    Shamim Hasan
    Keymaster

    You can add remove_action( 'fep_action_message_after_send', array( Fep_Emails::init(), 'save_send_email'), 20, 2 ); just before using fep_send_message()

    #6307
    Shamim Hasan
    Keymaster

    Your attachment will not be sent with email in your approach.
    From my code add_action ('fep_action_message_after_send', 'fep_open_emr_upload_attachments', 10, 3 ); and bellow everything move to above function action_putmessage( $args ) {. That means attachment hook have to be added first.

    Let me know.

    #6301
    Craig Tucker
    Participant

    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?

    #6189
    Shamim Hasan
    Keymaster

    Please use following (Untested).
    let me know

    
    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,
    		'open_emr_args' => $args, //pass to get in attachment function
    	);
    	$override = array(
    		'post_author' => $sender,
    	);
    	$message_id = fep_send_message( $message, $override );
    }
    
    add_action ('fep_action_message_after_send', 'fep_open_emr_upload_attachments', 10, 3 );
    
    function fep_open_emr_upload_attachments( $message_id, $message, $inserted_message ){
    	if ( ! fep_get_option( 'allow_attachment', 1 ) || ! $message_id || empty( $message['open_emr_args']) )
    	return false;
    	
    	$args = $message['open_emr_args'];
    	
    	$name = isset( $args['filename'] ) ? $args['filename'] : '';
    	
    	if( ! $name )
    	return false;
    	
    	$size_limit = (int) wp_convert_hr_to_bytes(fep_get_option('attachment_size','4MB'));
    	$fields = (int) fep_get_option('attachment_no', 4);
    	
    	if( class_exists( 'Fep_Attachment' ) ){
    		add_filter('upload_dir', array(Fep_Attachment::init(), 'upload_dir'));
    	}
    	
    	$mime = isset( $args['mimetype'] ) ? $args['mimetype'] : '';
    	$content = isset( $args['contents'] ) ? base64_decode($args['contents']) : '';
    	
    	if( !$mime || !in_array( $mime, get_allowed_mime_types() ) )
    	return false;
    	
    	$size = strlen( $content );
    	if( $size > $size_limit )
    	return false;
    	
    	$att = wp_upload_bits( $name, null, $content );
    	
    	if( ! isset( $att['file'] ) || ! isset( $att['url'] ) || ! isset( $att['type'] ) )
    	return false;
    	
    	$attachment = array(
    		'guid'           => $att['url'], 
    		'post_mime_type' => $att['type'],
    		'post_title'     => preg_replace( '/\.[^.]+$/', '', basename( $att['url'] ) ),
    		'post_content'   => '',
    		'post_author'	=> $inserted_message->post_author,
    		'post_status'    => 'inherit'
    	);
    	
    	// Insert the attachment.
    	wp_insert_attachment( $attachment, $att['file'], $message_id );
    	
    	if( class_exists( 'Fep_Attachment' ) ){
    		remove_filter('upload_dir', array(Fep_Attachment::init(), 'upload_dir'));
    	}
    }
    
    #6147
    Shamim Hasan
    Keymaster

    You can see Fep_Attachment class. upload attachment is hooked to fep_action_message_after_send action. But if $_FILES[‘fep_upload’] not exists then no attachment will be uploaded. In that case you can see FEP_Email_Pipe class and see how it is done there.

    #1732
    Shamim Hasan
    Keymaster

    This feature was there in initial versions of this plugin. But for user feedback this feature was removed many days ago. So this feature may not be included.
    you can use fep_action_message_after_send action hook to send email to sender if you need that badly.

Viewing 8 results - 31 through 38 (of 38 total)