dozent_instructor_attach_course( null $course = null, null $user = null )
Add an instructor to a course
Description
This function add any instructor or user to a course as instructor
Example usage:
dozent_instructor_attach_course( $course_id, $instructor_id );
See also
Parameters
- $course
-
(null) (Optional)
Default value: null
- $user
-
(null) (Optional)
Default value: null
Return
(bool|int) Return row ID or false on error
Source
File: includes/user-functions.php
function dozent_instructor_attach_course( $course = null, $user = null ) { global $wpdb; $course = get_post( $course ); $user = dozent_get_the_user( $user ); if ( ! dozent_instructor_is_attached_to_course( $course, $user ) ) { $data = apply_filters( 'dozent_instructor_attach_course_data', [ 'course_id' => $course->ID, 'instructor_id' => $user->ID, 'added_at' => current_time( 'mysql' ), ] ); /** * Action hook before attach an instructor to a specific course * * @since DozentLMS 1.0.0 * * @param array $data Inserted data * @param object $user User Object * @param object $course Course | Post Object */ do_action( 'dozent_instructor_attach_course_before', $data, $user, $course ); $inserted = $wpdb->insert( $wpdb->dozent_instructor_courses, $data ); if ( $inserted ){ $inserted_id = (int) $wpdb->insert_id; /** * Action hook after attach an instructor to a specific course * * @since DozentLMS 1.0.0 * * @param int $inserted_id Inserted Row ID * @param array $data Inserted data * @param object $user User Object * @param object $course Course | Post Object */ do_action( 'dozent_instructor_attach_course_after', $inserted_id, $data, $user, $course ); return $inserted_id; } } return false; }
Changelog
Version | Description |
---|---|
DozentLMS 1.0.0 | Introduced. |