0

i'm using plugin " Front End PM " Now i'm trying to transfer some of the plugin action to send a front-end message when the user post is published. this is the original code for sending a msg when users registered

add_action( 'user_register', 'fep_cus_user_register_send_messaage', 10, 1 );

function fep_cus_user_register_send_messaage( $user_id ){
        if ( $user_id < 1 )
                return;
        if ( ! function_exists( 'fep_send_message' ) )
                return;

        // Prepare message data
        $message = array(
             'message_title' => 'Welcome ' . fep_get_userdata( $user_id, 'display_name', 'id' ), //change with message title
             'message_content' => 'CONTENT', //change with message content
             'message_to_id' => $user_id
        );

        $override = array(
             'post_author' => 1, //change with message sender id
        );

        // Send message
       fep_send_message( $message, $override );      
}

And this is all actions of the plugin

fep_admin_settings_field_output_’ . $field[‘type’]
fep_get_announcement_column_content
fep_display_before_announcementbox
fep_display_after_announcement
fep_get_announcement_column_content
fep_display_before_announcementbox
fep_display_after_announcement
fep_save_message
fep_save_announcement
fep_message_table_column_content
fep_message_table_column_content
fep_switch_{$switch
fep_posted_action_{$action
fep_header_note
fep_menu_button
fep_display_before_content
fep_footer_note
fep_display_before_messagebox
fep_display_after_parent_message
fep_display_after_reply_message
fep_action_message_after_send
fep_template_redirect

And i found this code for sending an email to users when their posts is published

add_action( 'publish_post', 'send_notification' );
function send_notification( $post_id ) {    
        $post     = get_post($post_id);
        $post_url = get_permalink( $post_id );
        $post_title = get_the_title( $post_id ); 
        $author   = get_userdata($post->post_author);
        $subject  = 'Post publish notification';
        $message  = "Hello,";
        $message .= "<a href='". $post_url. "'>'".$post_title."'</a>\n\n";
        wp_mail($author->user_email, $subject, $message );  
}

I'm a wordpress noob, I tried more times to make it success but i can't, and i hope someone can help me,Thanks!

  • Your code looks good what error are you getting? This would be a comment but I can't yet comment. – Orlando P. Apr 30 '18 at 20:37
  • Hello Orlando P, Thanks for answer, I need to use the same registered message code above to make it work when the users posts is published. – Adham Mohamed Apr 30 '18 at 20:45
  • That should be working what error are you getting? – Orlando P. Apr 30 '18 at 20:46
  • Hey bro, there is nothing wrong with all the codes above! i need to transfer the first code to make it work with published posts when the user post is published, did you get it now? note: the last code that i found for sending an email to users, So how can i do the first one work like the last one but in the front-end!! – Adham Mohamed Apr 30 '18 at 20:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.