how to bulk add students to coursepress

Hey WPMU,

We are doing B to B sales of courses and there does not appear to be an easy way to bulk add Students to a course.

I have found a plugin to import users using a CSV. After the users are imported I want to add them all to a course.

I have done some research and it seems like they are assigned to a course via the the User meta table. Could you provide an SQL Quarry to add all users to a course.

This would be a great feature to your product.

Thank you so much in advance. :slight_smile:

  • Sajid
    • DEV MAN’s Sidekick

    Hi @RedJacketWest

    Hope you are doing good today :slight_smile:

    I am afraid this is not yet possible out of the box. Sorry! We have already received feature request that you can chime in support it, if you would like to see in future versions of plugin.

    https://premium.wpmudev.org/forums/topic/ability-to-add-students-in-bulk-to-courses

    For SQL query, how come you are importing users in WordPress ? Using a plugin to import from CSV or they are already registered ?

    If you can provide more details then I can try to help you find a workaround or flag SLS (second line support) for their feedback on this matter.

    Take care and have a nice day :slight_smile:

    Cheers, Sajid

  • Black Fox
    • The Incredible Code Injector

    Hey Sajid,

    An option that we want to offer our partners is a private learning platform.

    This allows a company to manage and review their own team as an admin. We are importing users, assigning them as students (need help with this), and setting a manager as an admin.

    With the current set up, I would need to add all students one by one. However, If you could provide an SQL quarry to mark all users as a student in a course then we could save hours of work.

    All the best,

  • Sajid
    • DEV MAN’s Sidekick

    Hi @RedJacketWest

    Hope you are doing good today :slight_smile:

    CoursePress save students as meta data in wp_users_meta table. There is no simple query to add that information. Because it have to save other related information like enrolment date etc…

    Instead I would suggest you to use following class to add a student.

    $student = new Student( $user_id );
    $student->enroll_in_course( $course_id );

    You can use this code in loop that is responsible to import users into WordPress. Also you must pass the valid user ID and course ID to make it work.

    Hope that helps :slight_smile:

    Cheers, Sajid

  • Black Fox
    • The Incredible Code Injector

    Thanks so much for the help. Im working on fleshing the code out more. But I will past what I have below in case it could help your team or any one else. I tested it and it works. All the best, @RedJacketWest

    <?php

    /**

    * Plugin Name: Add all users as Students to Coursepress.

    * Description: This is a quick and dirty way of adding all useres as Students to a Coursepress Class. ***Set course ID in php script***

    * Author: RJW

    */

    /** Step 2 Hook your admin_menu function. */

    add_action( ‘admin_menu’, ‘my_plugin_menu’ );

    /** Step 1. create admin_menu function */

    function my_plugin_menu() {

    add_options_page( ‘My Plugin Options’, ‘My Plugin’, ‘manage_options’, ‘my-unique-identifier’, ‘my_plugin_options’ );

    }

    /** Step 3 Do your work. */

    function my_plugin_options() {

    if ( !current_user_can( ‘manage_options’ ) ) {

    wp_die( __( ‘You do not have sufficient permissions to access this page.’ ) );

    }

    ?>

    <?php

    // The Array that holds and passes all user ids to the Coursepress Student Class

    $importedUsers = array();

    // The course I want to add Students to

    $course_id = 205;

    // array or arguments I am passing to the Database class

    $args = array( ‘fields’ => ‘all’, );

    // The Database Query

    $user_query = new WP_User_Query( $args );

    // User Loop

    if ( ! empty( $user_query->results ) ) {

    foreach ( $user_query->results as $user ) {

    //Prints name

    echo ‘<p>’ . $user->display_name . ‘</p>’;

    //Prints User ID

    echo ‘<p>’ . $user->id . ‘</p>’;

    //Adds User ID to array

    $importedUsers[] = $user->id;

    }

    } else {

    echo ‘No users found.’;

    }

    //Prints array for fun.

    print_r ($importedUsers);

    //Checks if array is empty

    if ( ! empty($importedUsers )) {

    //loops through array and adds students to class

    foreach($importedUsers as &$newEnroll){

    $student = new Student( $newEnroll );

    $student->enroll_in_course( $course_id );

    }

    } else {

    echo ‘No users added to course.’;

    }

    }

    ?>

  • Sajid
    • DEV MAN’s Sidekick

    Hi @RedJacketWest

    Hope you are doing good today :slight_smile:

    This is awesome! Thanks for sharing it with the community. I am sure it will be helpful for many other people looking for same option. Sending some points your way :slight_smile:

    Take care and have a nice day :slight_smile:

    Cheers, Sajid

  • Christian
    • WPMU DEV Initiate

    For sure! Always excited to help. Email => ccampbell@sapphirebd.com

    I demo it in the WordPress section of my resume site. https://christiancampbell.us/

    If you are a course press admin, you might also be interested in a reporting dashboard I’m building. Just started building on it yesterday but its coming along.

    https://lh3.googleusercontent.com/-EtGeVP0REDE/WDvG-KpHCII/AAAAAAAAAg0/oen1_l4b7ZErGq2izZcpSybKmPb7hYfWwCL0B/h323/2016-11-27.png

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.