uo_ceu_credit_report_custom_courses
Filters the custom course options displayed in the CEU credit report.
add_filter( 'uo_ceu_credit_report_custom_courses', $callback, 10, 3 );
Description
Filters the arguments used to retrieve custom courses for the CEU credit report. Developers can modify the course post type, order, and other query parameters to customize which courses appear in the report dropdown. This hook is executed before the course query.
Usage
add_filter( 'uo_ceu_credit_report_custom_courses', 'your_function_name', 10, 3 );
Parameters
-
$options(mixed) - This parameter contains an array of arguments used to query for courses, which can be filtered by custom courses.
-
$this(mixed) - This parameter contains an array of options that can be used to modify the query for retrieving course data.
-
$args(mixed) - This parameter likely refers to the instance of the class where the `get_courses_dropdown` method is being called, providing access to its properties and other methods.
Return Value
The filtered value.
Examples
add_filter( 'uo_ceu_credit_report_custom_courses', 'my_custom_ceu_courses_filter', 10, 3 );
/**
* Example filter to modify the list of courses displayed in the Uncanny CEU credit report.
* This example excludes courses with the tag 'internal-training'.
*
* @param array $options The current array of course options (value/text pairs).
* @param int $this_course The currently selected course ID.
* @param array $args The arguments used to fetch the courses.
*
* @return array The modified array of course options.
*/
function my_custom_ceu_courses_filter( $options, $this_course, $args ) {
// Check if we have any options to process.
if ( empty( $options ) || ! is_array( $options ) ) {
return $options;
}
// Remove the 'All courses' option if it's the first one, as we'll re-add it later if needed.
$all_courses_option = array();
if ( isset( $options[0] ) && '0' === $options[0]['value'] ) {
$all_courses_option = array_shift( $options );
}
$filtered_options = array();
// Iterate through each course option.
foreach ( $options as $option ) {
// Get the course ID.
$course_id = absint( $option['value'] );
// Skip this course if it's not a valid ID or if it has the 'internal-training' tag.
if ( $course_id > 0 && ! has_tag( 'internal-training', $course_id ) ) {
$filtered_options[] = $option;
}
}
// Re-add the 'All courses' option if it was originally present.
if ( ! empty( $all_courses_option ) ) {
array_unshift( $filtered_options, $all_courses_option );
}
// If after filtering, there are no courses left and the 'All courses' option was the only thing remaining,
// we might want to ensure at least 'All courses' is present.
if ( empty( $filtered_options ) && ! empty( $all_courses_option ) ) {
$filtered_options[] = $all_courses_option;
} elseif ( empty( $filtered_options ) && empty( $all_courses_option ) ) {
// If there were no courses and no 'All courses' option, maybe add a placeholder.
$filtered_options[] = array(
'value' => '0',
'text' => __( 'No courses available', 'your-text-domain' ),
);
}
return $filtered_options;
}
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/classes/course-report.php:1856
public function get_courses_dropdown() {
// Check if course is set.
if ( 0 === $this->course ) {
$course_var = $this->get_url_variable( 'course' );
if ( ! empty( $course_var ) ) {
$this->course = absint( $course_var );
}
}
// Get course posts.
$args = array(
'post_type' => 'sfwd-courses',
'posts_per_page' => 99999, // phpcs:ignore WordPress.WP.PostsPerPage.posts_per_page_posts_per_page
'orderby' => 'title',
'order' => 'ASC',
'cache_results' => false,
'update_post_meta_cache' => false,
'update_term_meta_cache' => false,
);
$courses = get_posts( $args );
// Maybe filter group leader courses.
$courses = $this->maybe_filter_group_leader_data( $courses, 'ID', 'all_course_ids' );
// Build options.
$options = array(
array(
'value' => '0',
'text' => __( 'All courses', 'uncanny-ceu' ),
),
);
$selected = 0;
if ( ! empty( $courses ) ) {
foreach ( $courses as $course ) {
$options[] = array(
'value' => (int) $course->ID,
'text' => sprintf(
// translators: %s: Course title, %s Post ID.
'%s (ID: %d)',
$course->post_title,
$course->ID
),
);
if ( (int) $this->course === (int) $course->ID ) {
$selected = (int) $course->ID;
}
}
}
// Generate HTML.
$options = Utilities::generate_select_options( $options, $selected );
// Allow custom courses
return apply_filters( 'uo_ceu_credit_report_custom_courses', $options, $this->course, $args );
}