I want to grab data from CoursePress using PHP

1. People (coaches)

Wordpress username - UniqueID
Name - Firstname, Lastname
GroupID (wordpress roles)

2. People roles - Roles in wordpress
UniqueID of the role
Name of the role

3. CoursepressCourse:
CoursepressCourse UniqueID,
CoursepressCourse Name
List of registered students by ID

1. People: are registered in a GravityForm, their user was created at registration, so the unique wordpress username is also in the form.
I wish to select all the items from the form from a .php code and populate $persons = array

2. People roles I wish to query all the roles and populate $group = array

3. CoursepressCourse: I wish to select all the CoursePress Courses with the registered users and populate $exams = array

Here you can see an example of the file and also the .php file with the values

header ('Content-type: application/json; charset=utf-8');
$type=isset($_GET['type']) ? $_GET['type'] : 0;
//echo$type;

if ($type=='groups'){
$group = array(
['id'=>1, 'name'=>'1. group']
);
$result = $group;
}
if ($type=='persons'){
$persons = array(
['id'=>wpuser1, 'name'=>'1. coach', 'mksz_code'=>'12345', 'group_id' => 1],
['id'=>wpuser2, 'name'=>'2. coach', 'mksz_code'=>'23456', 'group_id' => 1],
['id'=>wpuser3, 'name'=>'3. coach', 'mksz_code'=>'34567', 'group_id' => 1]
);
$result = $persons;
}
if ($type=='exams'){
$exams = array(
['id'=>coursepresscourseid1, 'name'=>'CoursePress Course Name 1 - coursepresscourseid1', 'persons'=>array(wpuser1,wpuser2,wpuser3)],
['id'=>coursepresscourseid2, 'name'=>'CoursePress Course Name 2 - coursepresscourseid2', 'persons'=>array(wpuser1,wpuser3)],
);
$result = $exams;
}

echo json_encode($result);
//print_r($result);echo"";

?>
  • Kasia Swiderska

    Hello Bela,

    I have pinged for feedback our developers - please note that we can help with part of getting data from the CoursePress, but Gravity forms is third party plugin and we might not be able to provide code for it. If that Gravity Form registers users in some custom way and keeps accounts in separate place it would be better if you contact Gravity Form developer if they can provide help with that.
    If that form registers WordPress users like regular registration and just adds some additional data, then it should be good :slight_smile: - but I would like you to confirm that.

    I will let you know when developers will give feedback to this.

    EDIT: I noticed that you are not using latest version of the plugin - I would suggest updating it to latest one.

    kind regards,
    Kasia

  • Bela

    Dear Kasia,

    Thanks for the quick reply! I did not get notification, so I just recognized your reply now.
    Update. We have a project and 1500 users using the site, plugin at the moment, I stopped automatic update as I do not wish to risk any malfunction. After we close this period I will do the update. Would you still recommend to update?

    GravityForm. It registers users also. username, password is given. Unfortunately I have not recognized that given GravityForm parameters can added as value to Wordpress parameters or even possible to create new user parameters. So now I need to select the information from different sources. In the future I wil lmakes sure whatever data added by a GravityForm it will be added as a Wordpress user related value.

    I contact GravityForm developers. However I believed that this situation is super common by GravityForm users.

    Waiting for the CoursePress related information.

    Thank you very much!
    Bela Grundmann
    http://belagrundmann.com

  • Panos

    Hi Bela ,

    As the requests are not very clear, I can try give some hints and hopefully they could help you in your project :slight_smile:

    1. People (coaches)

    All instructors in coursepress:

    $role_name = CoursePress_Data_Capabilities::get_role_instructor_name();
    
    	$args = array(
    		'number' => -1,
    		'meta_key' => $role_name,
    		'meta_value' => 'instructor',
    		'fields' => 'all_with_meta',
    	);
    
    	$instructors_search = new WP_User_Query( $args );
    	$instructors = $instructors_search->get_results();

    OR
    Iinstructors for a given course/course id:

    $course_id = 456;
    $instructors = array_filter( CoursePress_Data_Course::get_instructors( $course_id ) );

    2. People roles - Roles in wordpress

    All available roles in wordpress:
    $roles = get_editable_roles();
    	foreach ( $roles as $role_key => $role ) {
    		$role_name = $role['name'];
    	}

    Roles of specific user id:

    $user = new WP_User( $user_id );
    $user_roles = $user->roles;
    3. CoursepressCourse

    All courses for specific student:

    $student_courses = CoursePress_Data_Student::get_enrolled_courses_ids( $student_id );

    Hope this helps!
    Cheers!

  • Panos

    Hi Bela,

    1. You can get all courses in the following way:

    $post_args = array(
    	'post_type' => CoursePress_Data_Course::get_post_type_name(),
    	'post_status' => 'publish',
    	'posts_per_page' => -1,
    
    );
    $courses_q = new WP_Query( $post_args );
    $courses = $courses_q->posts;
    
    foreach ( $courses as $course ){
    	$course_id = $course->ID;
    	$course_name = $course->post_title;
    }

    2. Get students of a course:

    $course_id = 785;
    $students = CoursePress_Data_Course::get_students( $course_id );
    
    foreach ( $students as $student ){
    	$student_id = $student->ID;
    	$student_name = $student->data->display_name;
    }

    3. GravityForms related. You could read their docs, perhaps this part could help:
    https://docs.gravityforms.com/using-the-gravity-forms-gform-validation-hook/
    as it mentions how to loop through fields.

    Hope this helps!
    Cheers!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.