Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'wpf_meta_box_content', 'cea_wpf_ld_meta_box', 40, 2 );
- function cea_wpf_ld_meta_box( $post, $settings ) {
- if($post->post_type != 'sfwd-lessons' && $post->post_type != 'sfwd-topic' )
- return;
- echo '<p><label for="tag_trigger_complete"><small>Mark complete when this tag is applied:</small></label>';
- wpf_render_tag_multiselect( $settings['tag_trigger_complete'], 'wpf-settings', 'tag_trigger_complete', null, false, 'Select Tag', 1 );
- echo '</p>';
- }
- add_action( 'wpf_tags_modified', 'cea_mark_lessons_complete', 10, 2 );
- function cea_mark_lessons_complete( $user_id, $user_tags ) {
- $lessons = get_posts( array(
- 'post_type' => array('sfwd-lessons', 'sfwd-topic'),
- 'nopaging' => true,
- 'meta_query' => array(
- array(
- 'key' => 'wpf-settings',
- 'compare' => 'EXISTS'
- ),
- ),
- 'fields' => 'ids'
- ) );
- foreach( $lessons as $lesson_id ) {
- $settings = get_post_meta( $lesson_id, 'wpf-settings', true );
- if ( empty( $settings ) || empty( $settings['tag_trigger_complete'] ) ) {
- continue;
- }
- $tag_id = $settings['tag_trigger_complete'][0];
- if ( in_array( $tag_id, $user_tags ) ) {
- // Prevent "lesson complete" tag from being applied
- remove_action( 'learndash_lesson_completed', array( wp_fusion()->integrations->learndash, 'apply_tags_learndash_complete' ) );
- remove_action( 'learndash_topic_completed', array( wp_fusion()->integrations->learndash, 'apply_tags_learndash_complete' ) );
- // Mark lesson complete
- learndash_process_mark_complete( $user_id, $lesson_id );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement