Skip to content

Instantly share code, notes, and snippets.

@launchthatbrand
launchthatbrand / functions.php
Created October 19, 2022 06:01 — forked from firasd/functions.php
Redirect WordPress user from LearnDash course page to first lesson page
<?php
add_action('template_redirect', function () {
if (is_user_logged_in()) {
$q_object = get_queried_object();
if (($q_object) && (is_a($q_object, 'WP_Post')) && ($q_object->post_type == 'sfwd-courses')) {
if (sfwd_lms_has_access($q_object->ID)) {
$steps = learndash_get_course_steps($q_object->ID);
if (count($steps)) {
wp_redirect(get_permalink($steps[0]));
function require_onboarding( $can_access, $user_id, $post_id ) {
$wpflearndash = get_post_meta( $post_id, 'wpf-settings-learndash', true );
$wpflearndash = $wpflearndash['tag_link'][0];
if ( is_user_logged_in() && !current_user_can( 'manage_options' ) // if use is logged in and not an admin...
&& !wpf_has_tag( 'status - disclaimer signed' ) // and the user doesn't have the tag 'status - disclaimer signed'...
&& ( !empty( array_filter( wp_fusion()->access->get_post_access_meta( $post_id ))) || !empty($wpflearndash) ) // and the wpf settings array exists OR the learndash linked tag exists...