Advertisement
verygoodplugins

Untitled

Apr 4th, 2017
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.58 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' && $post->post_type != 'sfwd-topic' )
  6.         return;
  7.  
  8.     echo '<p><label for="tag_trigger_complete"><small>Mark complete when this tag is applied:</small></label>';
  9.  
  10.     wpf_render_tag_multiselect( $settings['tag_trigger_complete'], 'wpf-settings', 'tag_trigger_complete', 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'  => array('sfwd-lessons', 'sfwd-topic'),
  23.         'nopaging'   => true,
  24.         'meta_query' => array(
  25.             array(
  26.                 'key'     => 'wpf-settings',
  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', true );
  36.  
  37.         if ( empty( $settings ) || empty( $settings['tag_trigger_complete'] ) ) {
  38.             continue;
  39.         }
  40.  
  41.         $tag_id = $settings['tag_trigger_complete'][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.             remove_action( 'learndash_topic_completed', array( wp_fusion()->integrations->learndash, 'apply_tags_learndash_complete' ) );
  48.  
  49.             // Mark lesson complete
  50.             learndash_process_mark_complete( $user_id, $lesson_id );
  51.  
  52.         }
  53.  
  54.     }
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement