Advertisement
verygoodplugins

Untitled

Mar 25th, 2021
605
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.01 KB | None | 0 0
  1.  
  2.     /**
  3.      * If query filtering is enabled, hide course steps from the course
  4.      * navigation.
  5.      *
  6.      * @since  3.36.16
  7.      *
  8.      * @param  bool  $can_read  Can the user read the step?
  9.      * @param  int   $step_id   The step ID.
  10.      * @param  int   $course_id The course ID.
  11.      * @return bool  True if able to user read step, False otherwise.
  12.      */
  13.     public function can_user_read_step( $can_read, $step_id, $course_id ) {
  14.  
  15.         if ( ! $can_read ) {
  16.             return $can_read;
  17.         }
  18.  
  19.         if ( $can_read ) {
  20.  
  21.             // If Filter Course Steps is on
  22.  
  23.             $settings = get_post_meta( $course_id, 'wpf-settings-learndash', true );
  24.  
  25.             if ( ! empty( $settings ) && ! empty( $settings['filter_steps'] ) ) {
  26.                 if ( ! wpf_user_can_access( $step_id ) ) {
  27.                     $can_read = false;
  28.                 }
  29.             }
  30.         }
  31.  
  32.         if ( false === $can_read ) {
  33.  
  34.             // Reduce the course step count
  35.  
  36.             add_filter( 'learndash-course-progress-stats', function( $progress ) {
  37.  
  38.                 $progress['total'] -= 1;
  39.  
  40.                 return $progress;
  41.  
  42.             } );
  43.  
  44.         }
  45.  
  46.         return $can_read;
  47.  
  48.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement