CoursePress Pro. Manually makes students certified

I want to change many users to be certified. During the chat we try to solve some issues. Now I want to make some users certified. This will require editing sql database. How do I do this?

  • Panos
    • SLS

    Hey Jonathan ,

    You could try following instructions :

    1st. Create a mu-plugin and add the following snippet :

    <?php
    add_action( 'admin_init', function(){

    $students = array( 9, 10, 11, 12 );
    $courses = array( 777, 785, 1213 );

    foreach( $students as $student_id ){
    foreach( $courses as $course_id ){

    $is_enrolled = CoursePress_Data_Course::student_enrolled( $student_id, $course_id );

    if( ! $is_enrolled ) {
    CoursePress_Data_Course::enroll_student( $student_id, $course_id );
    }

    $meta_key = sprintf( '_course_%d_completed', $course_id );
    update_user_meta( $student_id, $meta_key, true );

    $data = get_user_option( 'course_' . $course_id . '_progress', $student_id );

    if( empty( $data ) ){
    $data = array();
    }

    $data[ 'completion' ][ 'completed' ] = true;

    update_user_option( $student_id, 'course_' . $course_id . '_progress', $data );
    CoursePress_Data_Certificate::generate_certificate( $student_id, $course_id );

    }
    }

    }, 10 );

    In above snippet you need to set the student ids in the $students array and the course ids in the $courses array.

    2. Refresh a page in admin

    3. Comment out the snippet code or delete the mu-plugin file.

    For each of the courses it should have enrolled and certified the specified users.

    Please test this first in a staging or local site before applying in your live site.

    In case you are not familiar with mu-plugins you can check it out here: https://premium.wpmudev.org/manuals/wpmu-manual-2/using-mu-plugins/ . It’s simply a php file in your wp-content/mu-plugins folder (if that folder doesn’t exist you can simply create it). Mu-plugins don’t need activation.

    Hope this helps!

    Cheers!

  • Panos
    • SLS

    Hey Jonathan ,

    I just remembered that you have server side authentication. I hard coded to use a different external file and the certificates were created. I have restored now though.

    I believe I haven’t explained this issue very well :slight_smile:

    It is not related to the snippet in the mu-plugin, it is related to the authentication required to access files, which tcpdf can’t provide when the certificate is created.

    I have modified the mu-plugin so it will not be executed if the url doesn’t contain

    &cp_autocertify=yes

    so you can visit the admin. In order to verify the issue you can go to your course setup and scroll to Step 7 – Course Completion. Click on the preview button where you will get this error message.

    Then try removing this authentication option form your host options and try the preview again. It should work this time.

    Hope I didn’t confuse you more :slight_smile:

    Cheers!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.