• Hello dear developers. I thought that it would be very useful for the student lists plugin to show those students who are not enrolled in the course. It is optional for others, but for small universities it is important – so you can calculate truant students. This is a useful functionality.

    <?php
    //total in progress      
    $finishedCount = 0;
    $inProgressCount = 0;
    $nonEnrolledStudents = [];
    
    foreach ($students as $student) {
        $student = learn_press_get_user($student->ID);
        $course_data = $student->get_course_data($course->get_id());
    
        if (!$course_data) {
            $nonEnrolledStudents[] = $student->user_email;
        } else {
            $course_results = $course_data->get_results(false);
            $result = $course_results['result'];
    
            if ($result == 100) {
                $finishedCount++;
            } else {
                $inProgressCount++;
            }
        }
    }
    
    echo "Finished: " . number_format(($finishedCount / count($students)) * 100, 2) . "%<br>";
    echo "In Progress: " . number_format(($inProgressCount / count($students)) * 100, 2) . "%<br>";
    
    $nonEnrolledSubscribers = [];
    
    // Get all subscribers who are not enrolled in the course
    $args = array(
        'role' => 'subscriber',
        'meta_key' => 'lp_enrolled_courses',
        'meta_compare' => 'NOT EXISTS'
    );
    $subscribers = get_users($args);
    
    foreach ($subscribers as $subscriber) {
        $nonEnrolledSubscribers[] = $subscriber->user_email;
    }
    
    echo "<table border='1' id='subscriberTable'>";
    echo "<tr><th>Email</th></tr>";
    
    foreach ($nonEnrolledSubscribers as $subscriberEmail) {
        echo "<tr><td>" . $subscriberEmail . "</td></tr>";
    }
    
    echo "</table>";
    echo "<button onclick='exportToExcel()'>Export to Excel</button>";
    
    echo "<script>
        function exportToExcel() {
            const table = document.getElementById('subscriberTable');
            let html = table.outerHTML;
            const url = 'data:application/vnd.ms-excel,' + encodeURIComponent(html);
            const a = document.createElement('a');
            a.href = url;
            a.download = 'subscribers.xls';
            a.click();
        }
    </script>";
    //total in progress finish
    ?>

    I found a taemplate plugin that is responsible for displaying the list of students who came and after the ul tag I insert my code, but it just shows the list of all subscribers, but I would like it to be those subscribers or in general all users except admins, who did not come / did not sign up for the course. It would also be useful to display an overall picture of the course – who is in progress and who has finished, so that you don’t have to count manually. My code doesn’t work, apparently I’m getting the values wrong. I am not strong in code for writing plugins. If you have a chance, please tell me what I’m doing wrong. Thank you in advance for any advice!

The topic ‘Student lists plugin’ is closed to new replies.