Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * //
- * // BATCH TOOLS
- * //
- **/
- /**
- * Adds LearnDash courses to available export options
- *
- * @access public
- * @return array Options
- */
- public function export_options( $options ) {
- $options['learndash_courses'] = array(
- 'label' => __( 'LearnDash course enrollment statuses', 'wp-fusion' ),
- 'title' => __( 'Users', 'wp-fusion' ),
- 'tooltip' => sprintf( __( 'For each user on your site, applies tags in %s based on their current LearnDash course enrollments, using the settings configured on each course. <br /><br />Note that this does not apply to course enrollments that have been granted via Groups.' ), wp_fusion()->crm->name ),
- );
- return $options;
- }
- /**
- * Gets users to be processed
- *
- * @access public
- * @return int Count
- */
- public function batch_init() {
- $args = array( 'fields' => 'ID' );
- $users = get_users( $args );
- wpf_log( 'info', 0, 'Beginning <strong>LearnDash course enrollment statuses</strong> batch operation on ' . count( $users ) . ' users', array( 'source' => 'batch-process' ) );
- return $users;
- }
- /**
- * Process user enrollments one at a time
- *
- * @access public
- * @return void
- */
- public function batch_step( $user_id ) {
- // Get courses
- $enrolled_courses = learndash_user_get_enrolled_courses( $user_id, array() );
- // We won't look at courses a user is in because of a group
- $groups_courses = learndash_get_user_groups_courses_ids( $user_id );
- $enrolled_courses = array_diff( $enrolled_courses, $groups_courses );
- if ( ! empty( $enrolled_courses ) ) {
- foreach ( $enrolled_courses as $course_id ) {
- wpf_log( 'info', $user_id, 'Processing LearnDash course enrollment status for <a href="' . admin_url( 'post.php?post=' . $course_id . '&action=edit' ) . '">' . get_the_title( $course_id ) . '</a>', array( 'source' => 'batch-process' ) );
- $this->updated_course_access( $user_id, $course_id );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement