Coursepress custom fields in certificates

Hello,

I have 2 questions acout Coursepress Pro functionality.
1. How can I add additional fields for students (birthday and profession)? Students must enter these data during registration.
2. How can I add this information to final certificate (e.g. Student Name, birthday, Profession?)

  • Dimitris

    Hello there Michail,

    hope you're doing good today and thanks for reaching us! :slight_smile:

    1. How can I add additional fields for students (birthday and profession)? Students must enter these data during registration.

    There's no way provided by CoursePress itself, you can disable the login/register forms it provides though with next setting
    https://monosnap.com/file/gOSBMRv1mUiI5sLLRMCmCLFzMwEYSX
    and then install and activate the famous BuddyPress plugin, which can be used to insert additional profile fields.

    2. How can I add this information to final certificate (e.g. Student Name, birthday, Profession?)

    Certificates are using only a predefined set of macros, so there's no support of additional fields there.
    Please let me know, if you're going to use the above BuddyPress approach, so I could then ping our Second Level Support team to let us know if it's possible to add extended BuddyPress profile fields in CoursePress certificates.

    Warm regards,
    Dimitris

  • Dimitris

    Hello there Michail,

    appreciate your kind words here! :slight_smile:

    I've already created a request towards our Second Level Support team, on how to add additional profile fields in CoursePress certificates.
    I can't promise that this will be doable, at least in a timely manner or if it's going to be considered custom development, so a developer of yours should implement it. For the later, or in case you urgently need this, you can always advise our jobs board page, Jobs & Pros (no WPMUDEV staff included there).
    Reference: https://premium.wpmudev.org/docs/getting-started/getting-support/#chapter-1 ("WPMU DEV Support vs. Custom Development")

    Warm regards,
    Dimitris

    • Dimitris

      That's something similar that should be made, it includes BuddyPress variables though, instead of CoursePress ones (like grades).
      Our developers will keep us posted on this as soon as possible!
      Please keep in mind that their response times are wider than ours here in support forums, as they're working from older to newer request.
      Your patience on this is highly appreciated!

      Take care,
      Dimitris

      • Michail

        Hello,

        I successfully installed Buddypress - it has options to make extra fields (birthday, profession in my case).
        All I need - is to output these fields in Coursepress certificate.
        On "single wordpress pages" I use "xprofile_get_field_data" function and it gives output, for example:

        $profession_field = xprofile_get_field_data( '2', '3', $multi_format = 'comma' );

        Gives me profession of user with ID=3.
        As I see from database tables, Coursepress variable $student_id it the same as Buddypress User ID.

        When I try to implement the same string in code provided below, I get empty data. Example:
        The question is - why output is empty and if there are any additional includes I should use?

        Code I used for my custom "plugin" look like:

        <?php
        /**
        * Plugin Name: BuddyPress user Data on Certificate
        * Description: Add BuddyPress user data on certificate_tokens
        */

        add_filter( 'coursepress_certificate_fields', 'percentage_fields_on_certificate' );
        add_filter( 'coursepress_basic_certificate_html', 'modify_basic_certificate_html', 10, 3 );
        add_filter( 'coursepress_basic_certificate_vars', 'percentage_to_certificate_vars', 10, 1 );

        function percentage_fields_on_certificate($fields, $student, $course){
        $course_grade = 0;
        if ( class_exists ( 'CoursePress_Data_Student' ) ) {
        $course_grade = CoursePress_Data_Student::average_course_responses( $student_id, $course_id );
        }
        elseif ( class_exists( 'Student' ) ) {
        $student = new Student( $student_id );
        if ( $student->is_course_complete( $student_id, $course_id ) ) {
        $course_grade = get_avarage_response_grade( $course_id );
        }
        }

        return array_merge( $fields, array( 'assessment_percentage' => $course_grade ) );
        }

        function modify_basic_certificate_html( $html, $course_id, $student_id ) {
        $profession_field = xprofile_get_field_data( '2', '3', $multi_format = 'comma' );
        return $html . '<div id="Profession"> Profession - '. $profession_field . ' </div>';
        }

        function percentage_to_certificate_vars( $certificate_tokens ) {
        return array_merge( $certificate_tokens, array( 'assessment_percentage'=>'' ) );
        }

        ?>

  • Ari

    Hey Michail

    === You had two questions: ===

    1. How can I add additional fields for students? Students must enter these data during registration.
    2. How can I add this information to final certificate (e.g. Student Name, birthday, Profession?)

    === About the first one ===

    You already did it with BuddyPress, but if you need to show the fields in the student registration form with our CoursePress, it would require a lot of custom coding and this is I'm afraid out of scope of support that we can provide, you can see more here: https://premium.wpmudev.org/manuals/using-wpmu-dev/support-vs-custom-development/

    If you need to customize this then you can post a job in our job board where you can hire a developer to assist further: https://premium.wpmudev.org/wordpress-development/

    === And the second one ===

    I made a mu-plugin for you, here's the link: https://gist.github.com/wpmudev-sls/6b4bc9ddcdb6a45262a23e92e32c66bc
    It will enable you custom variables for certificate to use them where you want. To activate it please follow the steps bellow:

    1: Inside the wp-content folder, create mu-plugins folder if this folder is not exist.
    2: Download the gist file, unzip it and upload the cp-certificate-with-bdp-fields.php file inside the mu-plugins folder.
    3: Now you have to add field_id & var_name paired. like below image:

    That means you can use "FIELD_1" variable in the certificate to get the BuddyPress field data which have ID of "12".

    So you can use "FIELD_1" & "FIELD_2" variable in the certificate like below image:

    Now to get the BuddyPress field ID, inspect the field, you will the name property have some value like: field_13, here the 13 is the field ID, like below image:

    === What is mu-plugins? ===

    mu-plugins also called "must use plugins" is auto-activated plugin, that's mean by adding that file inside the "mu-plugins" the code is automatically start functioning without any activation from dashboard.
    If you need to more about mu-plugins, here's the link: https://codex.wordpress.org/Must_Use_Plugins
    In future if you need to deactivate it, just remove this file.

    Please have a look is that work for you, and let me know if you have any trouble!

    Have a great day!

    Cheers,
    Ari

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.