Filter uncanny-continuing-education-credits

uo_ceu_credit_report_table_data

Filters the data used to generate the CEU credit report table.

add_filter( 'uo_ceu_credit_report_table_data', $callback, 10, 2 );

Description

Allows modification of the data array used to populate the CEU credit report table. Developers can filter this array to customize the reported CEU data before it's displayed, offering control over what information is presented to users.


Usage

add_filter( 'uo_ceu_credit_report_table_data', 'your_function_name', 10, 2 );

Parameters

$this (mixed)
This parameter represents the current instance of the course report class, which contains methods and properties related to generating and managing course reports.
$this (mixed)
This parameter is likely a reference to the current instance of the `CourseReport` class, providing access to its methods and properties.

Return Value

The filtered value.


Examples

/**
 * Example function to modify the CEU credit report data.
 *
 * This function demonstrates how to hook into the 'uo_ceu_credit_report_table_data'
 * filter to add, remove, or modify the data displayed in the CEU credit report table.
 * In this example, we'll simulate adding a new column or modifying existing data
 * based on some hypothetical logic.
 *
 * @param array $users_ceus The original array of CEU data for users.
 * @param object $course_report_instance The instance of the CourseReport class.
 * @return array The modified array of CEU data.
 */
add_filter( 'uo_ceu_credit_report_table_data', function( $users_ceus, $course_report_instance ) {

    // Simulate fetching additional data or applying conditional logic.
    // For demonstration, let's assume we want to add a "completion_status"
    // to each CEU entry if it's not already present.
    if ( ! empty( $users_ceus ) && is_array( $users_ceus ) ) {
        foreach ( $users_ceus as &$user_data ) {
            // Ensure user_data is an array and has the expected structure.
            if ( is_array( $user_data ) && isset( $user_data['courses'] ) && is_array( $user_data['courses'] ) ) {
                foreach ( $user_data['courses'] as &$course_entry ) {
                    // Add a hypothetical completion status.
                    // In a real scenario, this would be based on actual data.
                    if ( ! isset( $course_entry['completion_status'] ) ) {
                        // Example: if course duration is more than 10 hours, mark as 'Advanced'
                        $course_duration = isset( $course_entry['duration'] ) ? (int) $course_entry['duration'] : 0;
                        if ( $course_duration > 10 ) {
                            $course_entry['completion_status'] = __( 'Advanced', 'your-text-domain' );
                        } else {
                            $course_entry['completion_status'] = __( 'Standard', 'your-text-domain' );
                        }
                    }

                    // Example: Modify an existing field if needed
                    if ( isset( $course_entry['title'] ) ) {
                        $course_entry['title'] = sanitize_text_field( $course_entry['title'] );
                    }
                }
                unset( $course_entry ); // Unset to avoid potential issues with the reference
            }
        }
        unset( $user_data ); // Unset to avoid potential issues with the reference
    }

    // You could also add entirely new rows or structure the data differently.
    // For example, to add a summary row at the beginning or end.

    // Return the modified data.
    return $users_ceus;

}, 10, 2 ); // Priority 10, accepting 2 arguments.

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:352

$api_setup = array(
			'api'               => array(
				'root'  => esc_url_raw( rest_url() . $this->root_path ),
				'nonce' => wp_create_nonce( 'wp_rest' ),
			),
			'columns'           => $this->get_report_columns(),
			'buttons'           => $this->get_buttons(),
			'data'              => apply_filters( 'uo_ceu_credit_report_table_data', $this->users_ceus, $this ),
			'report_mode'       => $this->get_mode(),
			'ceu_courses'       => $this->get_ceu_courses(),
			'group_leader_data' => $this->get_group_leader_data(),
			'page_length'       => (int) get_option( 'ceu_default_page_length', 50 ),
			'l10n'              => array(
				'report'  => array(
					'create' => array(

Scroll to Top