Created
February 6, 2017 06:19
-
-
Save iworks/4848d61ae6e9582e02f2dd50fa9ce7fb to your computer and use it in GitHub Desktop.
CoursePress: Enroll new registered user to all available courses. Be careful it can break your site if you have a lot of available courses.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Enroll new user! | |
* Plugin URI: https://premium.wpmudev.org/ | |
* Description: Enroll new registered user to all available courses. Be careful it can break your site if you have a lot of available courses. | |
* Version: 1.0 | |
* Author: Marcin Pietrzak (Incsub) | |
* Author URI: https://premium.wpmudev.org/profile/marcin10 | |
* License: GPL2+ | |
*/ | |
add_action('user_register', 'coursepress_custom_enroll_for_all'); | |
function coursepress_custom_enroll_for_all( $student_id ) { | |
/** | |
* get post id for anny published courses | |
*/ | |
$args = array( | |
'post_type' => CoursePress_Data_Course::get_post_type_name(), | |
'nopaging' => true, | |
'status' => array( 'publish' ), | |
'fields' => 'ids', | |
); | |
$the_query = new WP_Query( $args ); | |
if ( $the_query->have_posts() ) { | |
while ( $the_query->have_posts() ) { | |
$the_query->the_post(); | |
$course_id = get_the_ID(); | |
/** | |
* avoid to add to full courses | |
*/ | |
if ( CoursePress_Data_Course::is_full( $course_id ) ) { | |
continue; | |
} | |
/** | |
* enroll student to course | |
*/ | |
CoursePress_Data_Course::enroll_student( $student_id, $course_id ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment