Send email when student add new discussion

Hello, I want to add the wp_mail( ) function to send a notification email when user add a newdiscussion and send a notification to the student when somebody response a discussion, so what are the files that I need to modify?

  • Milan

    Hello @lea4,

    I hope you are having a good day and thanks for asking us. :slight_smile:

    To send mail when student adds new question for course you'll need to modify /wp-content/plugins/coursepress/includes/templates/page-add-new-discussion.php file. Please add your mail code just before this line ( line no. 23 )

    wp_redirect( trailingslashit( get_permalink( $course_id ) ) . $coursepress->get_discussion_slug() );
    exit;

    To notify when someone comments on discussion please use this bit of code in your theme's functions.php file or better in its child theme's functions.php file.

    add_action('wp_insert_comment','comment_inserted',99,2);
    function comment_inserted($comment_id, $comment_object) {
     	if( get_post_type( $comment_object->comment_post_ID ) == 'discussions' ){
     		wp_mail( ... );
     	}
    }

    There is also one nice plugin for code snippets like above once. You can leverage that too if you want. :slight_smile:
    https://wordpress.org/plugins/code-snippets/

    Dear member I want to make a note here that editing core files of plugin is not advisable as your changes will be lost during plugin update. So I suggest you to take backup of your edited files before you hit update process. You can use our Snapshot Pro plugin to take full backup of your site including its plugin files.

    Cheers,
    Milan

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.