Advertisement
verygoodplugins

Untitled

Sep 17th, 2020
1,108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.96 KB | None | 0 0
  1.  
  2.     /**
  3.      * //
  4.      * // BATCH TOOLS
  5.      * //
  6.      **/
  7.  
  8.     /**
  9.      * Adds LearnDash courses to available export options
  10.      *
  11.      * @access public
  12.      * @return array Options
  13.      */
  14.  
  15.     public function export_options( $options ) {
  16.  
  17.         $options['learndash_courses'] = array(
  18.             'label'   => __( 'LearnDash course enrollment statuses', 'wp-fusion' ),
  19.             'title'   => __( 'Users', 'wp-fusion' ),
  20.             '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 ),
  21.         );
  22.  
  23.         return $options;
  24.  
  25.     }
  26.  
  27.     /**
  28.      * Gets users to be processed
  29.      *
  30.      * @access public
  31.      * @return int Count
  32.      */
  33.  
  34.     public function batch_init() {
  35.  
  36.         $args = array( 'fields' => 'ID' );
  37.  
  38.         $users = get_users( $args );
  39.  
  40.         wpf_log( 'info', 0, 'Beginning <strong>LearnDash course enrollment statuses</strong> batch operation on ' . count( $users ) . ' users', array( 'source' => 'batch-process' ) );
  41.  
  42.         return $users;
  43.  
  44.     }
  45.  
  46.     /**
  47.      * Process user enrollments one at a time
  48.      *
  49.      * @access public
  50.      * @return void
  51.      */
  52.  
  53.     public function batch_step( $user_id ) {
  54.  
  55.         // Get courses
  56.         $enrolled_courses = learndash_user_get_enrolled_courses( $user_id, array() );
  57.  
  58.         // We won't look at courses a user is in because of a group
  59.         $groups_courses = learndash_get_user_groups_courses_ids( $user_id );
  60.  
  61.         $enrolled_courses = array_diff( $enrolled_courses, $groups_courses );
  62.  
  63.         if ( ! empty( $enrolled_courses ) ) {
  64.  
  65.             foreach ( $enrolled_courses as $course_id ) {
  66.  
  67.                 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' ) );
  68.  
  69.                 $this->updated_course_access( $user_id, $course_id );
  70.  
  71.             }
  72.         }
  73.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement