Coursepress Pro Send email to all students who have not "Completed" Course

Would like to be able to email to all students who have not "Completed" a Course

When looking at Course > Students

Send an email to enrolled students section
There is a Dropdown that has:
"All students",
"All students with submissions"
"All students with submissions - Course Name"
(Not sure what the Second two choices do)

Would like to have addition choices...
"All students who are NOT Certified"
"All students who are Certified"

Is this possible? Would assist in sending reminders to Students who have not finished course and sending notifications to students who have completed of next or upcoming course.

  • James Morris

    Hello HawaiiDude,

    I hope you are well today.

    I've looked this over and it appears this would require a bit of custom coding. There's no option for this out of the box and I wasn't able to quickly find a function you could add to functions.php to achieve this. However, I've pinged our SLS Team (code experts) in order to get their valuable feedback on this issue.

    Please keep in mind that the SLS Team deals with more advanced topics which can take a bit more time to dig into. Thank you for your patience while our team sorts through this issue.

    Best regards,

    James Morris

  • Mahlamusa

    Hello HawaiiDude,

    I hope you are doing great today. Thank you for the question.

    I have looked at the code of CoursePress Pro and unfortunately there is no way to achieve this without modifying the plugin itself. But, I was able to try and figure out what needs to be changed to achieve this and I prepared the following which should be a solid foundation to get you started.

    1. Modify the file plugins/coursepress/2.0/include/coursepress/view/admin/course/class-student.php

    On line 113 add the following code:

    $send_options = array_merge( $send_options, array(
    	'all_certified' => __( 'All Certified', 'cp' ),
    	'all_not_certified' => __( 'All Not Certified', 'cp' )
    ));

    Then on line number 485 of the file: plugins/coursepress/2.0/admin/controller/class-course.php

    and on line 1663 of the file: plugins/coursepress//2.0/include/coursepress/view/admin/course/class-edit.php

    Add the following code in both files on the lines mentioned:

    if ( 'all_certified' == $send_to || 'all_not_certified' == $send_to ) {
    	$certificates = CoursePress_Data_Certificate::get_certificated_students_by_course_id( $course_id );
    
    	if ( is_multisite() ) {
    		$course_meta_key = $wpdb->prefix . 'enrolled_course_date_' . $course_id;
    	} else {
    		$course_meta_key = 'enrolled_course_date_' . $course_id;
    	}
    
    	// Could use the Course Model methods here, but lets try stick to one query
    	$query_args = array(
    		'meta_query' => array( array( 'key' => $course_meta_key, 'compare' => 'EXISTS',),),
    		'number' => -1
    	);
    	if ( ! empty( $certificates ) ) {
    		if ( 'all_certified' == $send_to )
    			$query_args['include'] = $certificates;
    		else
    			$query_args['exclude'] = $certificates;
    	}
    
    	$users = new WP_User_Query( $query_args );
    	foreach ( $users->get_results() as $student ) {
    		if ( in_array( $student->ID, $certificates ) )
    			$filtered_students = $student;
    	}
    }

    After doing those changes, save or upload your changes and check out the students page. Alternatively, download, extract and upload the attached zip file which is a modified copy of the latest version of Course Press Pro. It should look like this on the drop down:

    Test and modify the code as needed. I haven't done any tests and I am not sure if those are the only changes required so please test and let us know the results, we will always be happy to help if necessary.

    Unfortunately, this is not an official fix so if you modify the plugin you will have to apply the changes with each update you make. I suggest that you make a feature request in our Features and Feedback Forums so that our developers can consider adding this in future versions of the plugin if it gets many votes from other users.

    Please let us know if you need any further help with regards to this.

    Have a nice day.
    Mahlamusa

  • Mahlamusa

    Hello HawaiiDude,

    Sorry the modified plugin could not be attached due to size limit on the support forum. Please find the attached file which contains only the modified files in their respective folders. You may be able to upload them at once depending on your FTP client, or you can upload them one by one according to the locations mentioned above.

    I hope this helps.

    Have a nice day.
    Mahlamusa

  • Mahlamusa

    Hello HawaiiDude,

    I hope you are doing great today. Thank you for your feedback.

    I have doublechecked the code and found the reason why it always returned "No Users Found" is the way I constructed the query parameters for getting the students. The query was incomplete, there were more parameters to include in the search query. So I have changed the code a little to get the students using the built in Course Press functions.

    So, on line number 485 of the file:
    plugins/coursepress/2.0/admin/controller/class-course.php

    and on line 1663 of the file:
    plugins/coursepress//2.0/include/coursepress/view/admin/course/class-edit.php

    replace all the code if the if condition that looks like this:

    if ( 'all_certified' == $send_to || 'all_not_certified' == $send_to ) {
              //all the previous code
    }

    Replace all that if block with the following:

    if ( 'all_certified' == $send_to || 'all_not_certified' == $send_to ) {
    	//$students = CoursePress_Data_Course::get_students( $course_id, -1, 0 );
    	$all_students_ids = CoursePress_Data_Course::get_student_ids( $course_id );
    	$all_certified_students = CoursePress_Data_Course::get_certified_student_ids( $course_id );
    	$all_not_certified = array_diff( (array) $all_students_ids, (array) $all_certified_students );
    
    	error_log("All Students: \n" .print_r( $all_students_ids, true));
    	error_log("Certified Students: \n" .print_r( $all_certified_students, true));
    	error_log("Not Certified Students: \n" .print_r( $all_not_certified, true));
    
    	if ( 'all_certified' == $send_to )
    		$include = (array) $all_certified_students;
    	else if ( 'all_not_certified' == $send_to )
    		$include = (array) $all_not_certified;
    	else
    		$include = (array) $all_students_ids;
    
    	$filtered_students = get_users( array('include' => $include ) );
    }

    You may also download the attached modified files and replace the corresponding files in the plugin. Once you have done that you should be able to send to the desired groups of students. Please remember that a Certified student is not the same a student who completed a course, a certified student has actually received a certificate of completion.

    Certified students are marked as follows in the students list:

    And students not certified are shown as follows:

    Question tho, on the dropdown what are the other choices in the sections... does it only send to those students who have completed those in order?

    In the drop down, if you choose "All with submissions of - <MODULE_NAME>", it will send the email to all students who have submitted their answers for the questions of that particular module. So with the custom editions, once you have assessed the students they will be certified and then you will be able to send to Certified students of the particular course.

    I hope that clarifies everything. Please let us know if you need any further assistance with anything relating to this, we will always be happy to assist in any way possible.

    Have a nice day.
    Mahlamusa