Advertisement
verygoodplugins

Untitled

Apr 4th, 2017
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.40 KB | None | 0 0
  1. add_action( 'wpf_meta_box_content', 'cea_wpf_ld_meta_box', 40, 2 );
  2.  
  3. function cea_wpf_ld_meta_box( $post, $settings ) {
  4.  
  5.     if($post->post_type != 'sfwd-lessons')
  6.         return;
  7.  
  8.     echo '<p><label for="link_tag_lesson"><small>Mark lesson complete when this tag is applied:</small></label>';
  9.  
  10.     wpf_render_tag_multiselect( $settings['link_tag_lesson'], 'wpf-settings', 'link_tag_lesson', null, false, 'Select Tag', 1 );
  11.  
  12.     echo '</p>';
  13.  
  14.  
  15. }
  16.  
  17. add_action( 'wpf_tags_modified', 'cea_mark_lessons_complete', 10, 2 );
  18.  
  19. function cea_mark_lessons_complete( $user_id, $user_tags ) {
  20.  
  21.     $lessons = get_posts( array(
  22.         'post_type'  => 'sfwd-lessons',
  23.         'nopaging'   => true,
  24.         'meta_query' => array(
  25.             array(
  26.                 'key'     => 'wpf-settings-learndash',
  27.                 'compare' => 'EXISTS'
  28.             ),
  29.         ),
  30.         'fields'     => 'ids'
  31.     ) );
  32.  
  33.     foreach( $lessons as $lesson_id ) {
  34.  
  35.         $settings = get_post_meta( $lesson_id, 'wpf-settings-learndash', true );
  36.  
  37.         if ( empty( $settings ) || empty( $settings['link_tag_lesson'] ) ) {
  38.             continue;
  39.         }
  40.  
  41.         $tag_id = $settings['link_tag_lesson'][0];
  42.  
  43.         if ( in_array( $tag_id, $user_tags ) ) {
  44.  
  45.             // Prevent "lesson complete" tag from being applied
  46.             remove_action( 'learndash_lesson_completed', array( wp_fusion()->integrations->learndash, 'apply_tags_learndash_complete' ) );
  47.  
  48.             // Mark lesson complete
  49.             learndash_process_mark_complete( $user_id, $lesson_id );
  50.  
  51.         }
  52.  
  53.     }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement