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')
- return;
- echo '<p><label for="link_tag_lesson"><small>Mark lesson complete when this tag is applied:</small></label>';
- wpf_render_tag_multiselect( $settings['link_tag_lesson'], 'wpf-settings', 'link_tag_lesson', 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' => 'sfwd-lessons',
- 'nopaging' => true,
- 'meta_query' => array(
- array(
- 'key' => 'wpf-settings-learndash',
- 'compare' => 'EXISTS'
- ),
- ),
- 'fields' => 'ids'
- ) );
- foreach( $lessons as $lesson_id ) {
- $settings = get_post_meta( $lesson_id, 'wpf-settings-learndash', true );
- if ( empty( $settings ) || empty( $settings['link_tag_lesson'] ) ) {
- continue;
- }
- $tag_id = $settings['link_tag_lesson'][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' ) );
- // Mark lesson complete
- learndash_process_mark_complete( $user_id, $lesson_id );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement