在作业批准后,LearnDash Auto完成了主题

发布于 2025-02-13 06:48:25 字数 2911 浏览 1 评论 0原文

因此,我已经在WordPress中创建了一个ED-Tech网站,并使用了LearnDash LMS系统,但是我想做一些事情,例如,教师批准了作业,因此它将自动完成该主题并显示完整的标记,目前在批准分配学生后批准了该主题单击“单击并继续”按钮后,需要完成该分配主题。

我还创建了一个函数并在此处附加代码。

代码从这里开始:

add_action('acf/save_post', 'assignment_custom_acf_save', 5);

function assignment_custom_acf_save($post_id) {

    if (get_post_type($post_id) == 'sfwd-assignment') {
        $prev_value = get_field('custom_approval_status', $post_id);
        $current_values = $_POST['acf'];        
        $new_status = $current_values['field_628fdf0a73412'];
        $assignment = get_post($post_id);
        $assignment_data = get_post_meta($assignment->ID);

        $student_id = $assignment->post_author;
        $course_id = $assignment_data['course_id'][0];
        $course_title = get_post_field('post_title', $assignment_data['course_id'][0]);
        $lesson_id = $assignment_data['lesson_id'][0];
        $lesson_title = $assignment_data['lesson_title'][0];
        $teachers_comment = $current_values['field_628fdef373411'];

        if ($new_status == 1) {
            delete_post_meta($post_id, 'approval_status');
            learndash_process_mark_incomplete($student_id, $course_id, $lesson_id);
            send_email_after_assignment_rejection($post_id, $teachers_comment);
            
            $rejection_message = 'Thanks for your submission for <b><a href="' . get_permalink($lesson_id) . '">' . $lesson_title . '</a></b> in the ' .
                '<b><a href="' . get_permalink($course_id) . '">' . $course_title . '</a></b>.<br><br>' .
                'Unfortunately, it didn\'t meet the requirements for this assignment.<br>' .
                (empty($teachers_comment) ? '' : 'This is the comment to your work: <b>' . $teachers_comment . '</b>') .
                '<br><br>Let\'s give it another go!';

            send_new_message($student_id, $rejection_message);
        } else if ($new_status == 2) {
            update_post_meta($post_id, 'approval_status', 1);
            learndash_process_mark_complete(I am not sure what should I put here because I am not able to create a topic id);
            send_email_after_assignment_approval($post_id, $teachers_comment);
            
            $approval_message = 'Great job on your assignment! <br><b>' . $teachers_comment . '</b>' . (empty($teachers_comment) ? '' : '<br>') .
                'Your submission for <b><a href="' . get_permalink($lesson_id) . '">' . $lesson_title . '</a></b> in the ' .
                '<b><a href="' . get_permalink($course_id) . '">' . $course_title . '</a></b> is now approved. <br>Thanks for spending the time to get that in.';

            send_new_message($student_id, $approval_message);
            
        }
    }
}

So I have created an ed-tech website in WordPress and used the Learndash LMS system but I want to do something like if the instructor approves an assignment so it will automatically complete that topic and shows the complete mark, currently after approval of the assignments student need to complete that assignment topic after clicking on "Click and Continue" button.

I also created a function and also attaching the code here.

Code starts here:

add_action('acf/save_post', 'assignment_custom_acf_save', 5);

function assignment_custom_acf_save($post_id) {

    if (get_post_type($post_id) == 'sfwd-assignment') {
        $prev_value = get_field('custom_approval_status', $post_id);
        $current_values = $_POST['acf'];        
        $new_status = $current_values['field_628fdf0a73412'];
        $assignment = get_post($post_id);
        $assignment_data = get_post_meta($assignment->ID);

        $student_id = $assignment->post_author;
        $course_id = $assignment_data['course_id'][0];
        $course_title = get_post_field('post_title', $assignment_data['course_id'][0]);
        $lesson_id = $assignment_data['lesson_id'][0];
        $lesson_title = $assignment_data['lesson_title'][0];
        $teachers_comment = $current_values['field_628fdef373411'];

        if ($new_status == 1) {
            delete_post_meta($post_id, 'approval_status');
            learndash_process_mark_incomplete($student_id, $course_id, $lesson_id);
            send_email_after_assignment_rejection($post_id, $teachers_comment);
            
            $rejection_message = 'Thanks for your submission for <b><a href="' . get_permalink($lesson_id) . '">' . $lesson_title . '</a></b> in the ' .
                '<b><a href="' . get_permalink($course_id) . '">' . $course_title . '</a></b>.<br><br>' .
                'Unfortunately, it didn\'t meet the requirements for this assignment.<br>' .
                (empty($teachers_comment) ? '' : 'This is the comment to your work: <b>' . $teachers_comment . '</b>') .
                '<br><br>Let\'s give it another go!';

            send_new_message($student_id, $rejection_message);
        } else if ($new_status == 2) {
            update_post_meta($post_id, 'approval_status', 1);
            learndash_process_mark_complete(I am not sure what should I put here because I am not able to create a topic id);
            send_email_after_assignment_approval($post_id, $teachers_comment);
            
            $approval_message = 'Great job on your assignment! <br><b>' . $teachers_comment . '</b>' . (empty($teachers_comment) ? '' : '<br>') .
                'Your submission for <b><a href="' . get_permalink($lesson_id) . '">' . $lesson_title . '</a></b> in the ' .
                '<b><a href="' . get_permalink($course_id) . '">' . $course_title . '</a></b> is now approved. <br>Thanks for spending the time to get that in.';

            send_new_message($student_id, $approval_message);
            
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倾`听者〃 2025-02-20 06:48:25

您需要两个函数来构建您的代码:

Learndash_is_assignment_approved_by_meta(检查是否批准了评估)
https://developers.learndash.com/function/learndash_is_assignment_approved_by_meta/

LearnDash_process_mark_complete(Automark完成)
https://developers.learndash.com/function/learndash_process_mark_complete/

That's an example of an我写的自动完成功能,也许可以帮助更好地了解其工作原理。

function ld_automark_complete()
{
    global $post, $current_user;
    
    $included_courses = array(
        30215,
         1107, 
        43013, 
        60082, 
        27081, 
        26025, 
        27180, 
        27341, 
        27200, 
 
    );

    $course_id = learndash_get_course_id();

    if (empty($course_id) || !in_array($course_id, $included_courses))
        return;
    
    if (! empty($current_user->ID) && ! empty($post->post_type) && $post->post_type == 'sfwd-lessons') {
        learndash_process_mark_complete($current_user->ID, $post->ID);
    }
    if (! empty($current_user->ID) && ! empty($post->post_type) && $post->post_type == 'sfwd-topic') {
        learndash_process_mark_complete($current_user->ID, $post->ID);
    }
}

add_action('wp', 'ld_automark_complete');

You need two functions to build your code:

learndash_is_assignment_approved_by_meta ( check if an assigment is approved )
https://developers.learndash.com/function/learndash_is_assignment_approved_by_meta/

learndash_process_mark_complete ( automark as complete )
https://developers.learndash.com/function/learndash_process_mark_complete/

That's an example of an autocomplete function I wrote, maybe it could help to better understand how it works.

function ld_automark_complete()
{
    global $post, $current_user;
    
    $included_courses = array(
        30215,
         1107, 
        43013, 
        60082, 
        27081, 
        26025, 
        27180, 
        27341, 
        27200, 
 
    );

    $course_id = learndash_get_course_id();

    if (empty($course_id) || !in_array($course_id, $included_courses))
        return;
    
    if (! empty($current_user->ID) && ! empty($post->post_type) && $post->post_type == 'sfwd-lessons') {
        learndash_process_mark_complete($current_user->ID, $post->ID);
    }
    if (! empty($current_user->ID) && ! empty($post->post_type) && $post->post_type == 'sfwd-topic') {
        learndash_process_mark_complete($current_user->ID, $post->ID);
    }
}

add_action('wp', 'ld_automark_complete');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文