Advertisement
verygoodplugins

Untitled

Mar 8th, 2021
971
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.12 KB | None | 0 0
  1.  
  2.         /**
  3.          * General function to check if user can view/read step post.
  4.          *
  5.          * @since 3.4.0
  6.          *
  7.          * @param integer $step_post_id Step Post ID.
  8.          *
  9.          * @return boolean True if user can view/read post.
  10.          */
  11.         protected function can_user_read_step( $step_post_id = 0 ) {
  12.             $user_can_read_post = true;
  13.  
  14.             if ( ! empty( $step_post_id ) ) {
  15.                 if ( is_user_logged_in() ) {
  16.                     if ( ! current_user_can( 'read_post', $step_post_id ) ) {
  17.                         $user_can_read_post = false;
  18.                     }
  19.                 } else {
  20.                     $step_post = get_post( $step_post_id );
  21.                     if ( ( $step_post ) && ( is_a( $step_post, 'WP_Post' ) ) ) {
  22.                         if ( ! in_array( $step_post->post_status, array( 'publish' ), true ) ) {
  23.                             $user_can_read_post = false;
  24.                         }
  25.                     }
  26.                 }
  27.             }
  28.  
  29.             /**
  30.              * Filters user can view/read course step.
  31.              *
  32.              * @param boolean  $user_can_read_post True if user can read step post.
  33.              * @param integer  $step_post_id       Step Post ID.
  34.              * @param integer  $course_id          Course ID.
  35.              */
  36.             return apply_filters( 'learndash_can_user_read_step', $user_can_read_post, $step_post_id, $this->post_id );
  37.         }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement