get_var($wpdb->prepare("SELECT ID from $wpdb->posts where post_status = 'publish' and post_type = %s and post_author = %d", acadlix()->cpt()->course()->get_post_type(), $post_author)); if ($course_id) { $post = get_post($course_id); setup_postdata($post); return true; } return false; } } if (!function_exists('aelms_get_course')) { function aelms_get_course() { global $post; $course_id = $post->ID; $course_post_type = acadlix()->cpt()->course()->get_post_type(); if (is_single() && $post->post_type == $course_post_type) { return true; } $cpt = acadlix()->cpt(); if (method_exists($cpt, 'course_bundle')) { $course_bundle_post_type = $cpt->course_bundle()->get_post_type(); if (is_single() && $post->post_type == $course_bundle_post_type) { return true; } } // if ( $post->post_type == 'elementor_library' ) { // $is_acadlix_template = get_post_meta( $post->ID, '_acadlix_lms_elementor_template_id', true ); // if ( $is_acadlix_template ) { // return aelms_setup_course_data(); // } // } if (\Elementor\Plugin::instance()->editor->is_edit_mode()) { $elementor_course_id = \Elementor\Plugin::instance()->editor->get_post_id(); if ($post->post_type == $course_post_type && $course_id === $elementor_course_id) { return true; } return aelms_setup_course_data(); } return false; } } if (!function_exists('aelms_get_course_categories')) { function aelms_get_course_categories() { $course_categories = array(); // Fetch terms from your custom taxonomy $terms = get_terms(array( 'taxonomy' => acadlix()->cpt()->course()->get_course_category_taxonomy(), // your custom taxonomy slug 'hide_empty' => false, // Set to true if you want only categories that have posts )); if (!is_wp_error($terms) && !empty($terms)) { foreach ($terms as $term) { $course_categories[$term->term_id] = $term->name; } } return $course_categories; } } if (!function_exists('aelms_get_course_tags')) { function aelms_get_course_tags() { $course_tags = array(); $terms = get_terms(array( 'taxonomy' => acadlix()->cpt()->course()->get_course_tag_taxonomy(), 'hide_empty' => false, )); if (!is_wp_error($terms) && !empty($terms)) { foreach ($terms as $term) { $course_tags[$term->term_id] = $term->name; } } return $course_tags; } } if (!function_exists('aelms_get_authors')) { function aelms_get_authors() { $authors = array(); // Fetch users with role "author" (or any role you want) $users = get_users(array( 'role__in' => array('author', 'administrator', 'editor'), // You can customize this )); if (!empty($users)) { foreach ($users as $user) { $authors[$user->ID] = $user->display_name; } } return $authors; } } if (!function_exists('acadlix_get_courses_query')) { function acadlix_get_courses_query($args = []) { $paged = isset($args['paged']) ? intval($args['paged']) : 1; $post_type = isset($args['post_type']) ? (array) $args['post_type'] : [acadlix()->cpt()->course()->get_post_type()]; $post_per_page = isset($args['posts_per_page']) ? intval($args['posts_per_page']) : 6; $include_categories = isset($args['include_categories']) ? array_map('intval', $args['include_categories']) : []; $exclude_categories = isset($args['exclude_categories']) ? array_map('intval', $args['exclude_categories']) : []; $include_tags = isset($args['include_tags']) ? array_map('intval', $args['include_tags']) : []; $exclude_tags = isset($args['exclude_tags']) ? array_map('intval', $args['exclude_tags']) : []; $include_authors = isset($args['include_authors']) ? array_map('intval', $args['include_authors']) : []; $exclude_authors = isset($args['exclude_authors']) ? array_map('intval', $args['exclude_authors']) : []; $orderby = isset($args['orderby']) ? sanitize_text_field($args['orderby']) : 'post_date'; $order = isset($args['order']) ? sanitize_text_field($args['order']) : 'desc'; $search = isset($args['search']) ? sanitize_text_field($args['search']) : ''; $courseBundleIds = []; if (acadlix()->helper()->is_course_bundle_addon_active() && in_array(acadlix()->cpt()->course_bundle()->get_post_type(), $post_type)) { $courseBundleIds = acadlix() ->model() ->bundleCourses() ->when(!empty($include_categories), function ($query) use ($include_categories) { $query ->whereHas('course', function ($q) use ($include_categories) { $q->whereHas('course_categories', function ($c) use ($include_categories) { $c->whereIn('term_id', $include_categories); }); }); }) ->pluck('course_bundle_id') ->toArray(); } $query = acadlix() ->model() ->course() ->whereIn('post_type', $post_type) ->when(!empty($search), function ($query) use ($search) { $query->where('post_title', 'like', '%' . $search . '%'); }) ->where('post_status', 'publish') ->orderBy($orderby, $order); $query->when(!empty($include_categories), function ($query) use ($include_categories, $courseBundleIds) { $query->where(function ($query) use ($include_categories) { $query->where('post_type', ACADLIX_COURSE_CPT) ->whereHas('course_categories', function ($q) use ($include_categories) { $q->whereIn('term_id', $include_categories); }); }); if (acadlix()->helper()->is_course_bundle_addon_active()) { $query->orWhere(function ($query) use ($courseBundleIds) { $query->where('post_type', ACADLIX_COURSE_BUNDLE_CPT) ->whereIn('ID', $courseBundleIds); }); } }); $query->when(!empty($exclude_categories), function ($query) use ($exclude_categories) { $query->where(function ($query) use ($exclude_categories) { $query->where('post_type', ACADLIX_COURSE_CPT) ->whereDoesntHave('course_categories', function ($q) use ($exclude_categories) { $q->whereIn('term_id', $exclude_categories); }); }); }); $query->when(!empty($include_tags), function ($query) use ($include_tags) { $query->where(function ($query) use ($include_tags) { $query->where('post_type', ACADLIX_COURSE_CPT) ->whereHas('course_tags', function ($q) use ($include_tags) { $q->whereIn('term_id', $include_tags); }); }); }); $query->when(!empty($exclude_tags), function ($query) use ($exclude_tags) { $query->where(function ($query) use ($exclude_tags) { $query->where('post_type', ACADLIX_COURSE_CPT) ->whereDoesntHave('course_tags', function ($q) use ($exclude_tags) { $q->whereIn('term_id', $exclude_tags); }); }); }); $query->when(!empty($include_authors), function ($query) use ($include_authors) { $query->whereIn('post_author', $include_authors); }); $query->when(!empty($exclude_authors), function ($query) use ($exclude_authors) { $query->whereNotIn('post_author', $exclude_authors); }); $course_count = $query->count(); $course = $query->skip(($paged - 1) * $post_per_page)->take($post_per_page)->get(); return [ 'course_count' => $course_count, 'course' => $course, ]; // $defaults = [ // 'post_type' => acadlix()->cpt()->course()->get_post_type(), // 'post_status' => 'publish', // 'posts_per_page' => 6, // 'paged' => 1, // 'tax_query' => ['relation' => 'AND'], // 'search' => '', // 'search_columns' => array('post_title'), // ]; // $args = wp_parse_args($args, $defaults); // // Category include // if (!empty($args['include_categories'])) { // $args['tax_query'][] = [ // 'taxonomy' => acadlix()->cpt()->course()->get_course_category_taxonomy(), // 'field' => 'term_id', // 'terms' => array_map('intval', $args['include_categories']), // ]; // } // // Category exclude // if (!empty($args['exclude_categories'])) { // $args['tax_query'][] = [ // 'taxonomy' => acadlix()->cpt()->course()->get_course_category_taxonomy(), // 'field' => 'term_id', // 'terms' => array_map('intval', $args['exclude_categories']), // 'operator' => 'NOT IN', // ]; // } // if (!empty($args['include_authors'])) { // $args['author__in'] = array_map('intval', $args['include_authors']); // } // if (!empty($args['exclude_authors'])) { // $args['author__not_in'] = array_map('intval', $args['exclude_authors']); // } // if (!empty($args['orderby'])) { // $allowed = ['date', 'title', 'menu_order', 'ID']; // $args['orderby'] = in_array($args['orderby'], $allowed, true) ? $args['orderby'] : 'date'; // $args['order'] = strtoupper($args['order']) === 'ASC' ? 'ASC' : 'DESC'; // } // if (!empty($args['search'])) { // $args['s'] = sanitize_text_field($args['search']); // } // return new WP_Query($args); } } if (!function_exists('aelms_allowed_html')) { function aelms_allowed_html() { return [ 'html' => ['class' => true, 'id' => true, 'style' => true, 'lang' => true, 'dir' => true], 'body' => ['class' => true, 'id' => true, 'style' => true], 'head' => ['class' => true, 'id' => true, 'style' => true], 'meta' => ['name' => true, 'content' => true], 'link' => ['rel' => true, 'href' => true, 'type' => true, 'media' => true, 'title' => true], 'main' => ['id' => true, 'class' => true, 'role' => true, 'style' => true], 'section' => ['id' => true, 'class' => true, 'style' => true], 'header' => ['id' => true, 'class' => true, 'style' => true], 'footer' => ['id' => true, 'class' => true, 'style' => true], 'nav' => ['id' => true, 'class' => true, 'role' => true, 'style' => true, 'aria-*' => true], 'div' => ['id' => true, 'class' => true, 'style' => true, 'role' => true, 'data-*' => true, 'aria-*' => true, 'acadlix-ratings-selectable' => true], 'span' => ['id' => true, 'class' => true, 'style' => true, 'data-*' => true, 'aria-*' => true], 'p' => ['id' => true, 'class' => true, 'style' => true], 'a' => [ 'href' => true, 'class' => true, 'target' => true, 'rel' => true, 'title' => true, 'id' => true, 'style' => true, 'aria-*' => true, 'data-*' => true, ], 'ul' => ['id' => true, 'class' => true, 'style' => true], 'ol' => ['id' => true, 'class' => true, 'style' => true], 'li' => ['id' => true, 'class' => true, 'style' => true], 'strong' => [], 'em' => [], 'br' => [], 'small' => ['class' => true, 'style' => true], 'h1' => ['id' => true, 'class' => true, 'style' => true], 'h2' => ['id' => true, 'class' => true, 'style' => true], 'h3' => ['id' => true, 'class' => true, 'style' => true], 'h4' => ['id' => true, 'class' => true, 'style' => true], 'h5' => ['id' => true, 'class' => true, 'style' => true], 'h6' => ['id' => true, 'class' => true, 'style' => true], 'img' => [ 'src' => true, 'alt' => true, 'class' => true, 'width' => true, 'height' => true, 'loading' => true, 'srcset' => true, 'sizes' => true, 'style' => true, 'data-*' => true, ], 'i' => ['class' => true, 'aria-hidden' => true, 'style' => true, 'data-*' => true], 'svg' => ['class' => true, 'viewBox' => true, 'xmlns' => true, 'width' => true, 'height' => true, 'aria-hidden' => true, 'focusable' => true, 'role' => true], 'path' => ['d' => true, 'fill' => true, 'stroke' => true, 'stroke-width' => true], 'button' => ['type' => true, 'class' => true, 'id' => true, 'data-*' => true, 'aria-*' => true, 'style' => true], 'input' => ['type' => true, 'name' => true, 'value' => true, 'placeholder' => true, 'class' => true, 'id' => true, 'checked' => true, 'disabled' => true, 'aria-*' => true, 'data-*' => true, 'style' => true], 'label' => ['for' => true, 'class' => true, 'id' => true, 'style' => true], 'select' => ['name' => true, 'class' => true, 'id' => true, 'style' => true], 'option' => ['value' => true, 'selected' => true, 'label' => true], 'textarea' => ['name' => true, 'class' => true, 'id' => true, 'rows' => true, 'cols' => true, 'placeholder' => true, 'style' => true], 'form' => ['action' => true, 'method' => true, 'class' => true, 'id' => true, 'style' => true], 'time' => ['datetime' => true, 'class' => true], 'figure' => ['class' => true], 'figcaption' => ['class' => true], 'style' => ['id' => true, 'type' => true], ]; } }