Filter uncanny-continuing-education-credits

uo_ceu_credit_report_action_buttons

Filters the action buttons displayed on the CEU credit report, allowing customization of the report's interactive elements.

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

Description

Filters the array of action buttons displayed on the CEU credit report. Developers can use this to add, remove, or modify buttons for report actions. The `$this` object provides access to the course report instance.


Usage

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

Parameters

$this (mixed)
This parameter contains the default array of action buttons for the CEU credit report.
$this (mixed)
This parameter contains the array of action buttons to be displayed on the CEU credit report.

Return Value

The filtered value.


Examples

/**
 * Add a custom button to the CEU credit report action buttons.
 *
 * This function will add a new button to the existing array of action buttons
 * displayed on the CEU credit report screen. The new button will have a label
 * "Download Report" and a link to a hypothetical report generation URL.
 *
 * @param array $buttons The original array of action buttons.
 * @param object $course_report_object The instance of the CourseReport object.
 * @return array The modified array of action buttons, including the new custom button.
 */
add_filter( 'uo_ceu_credit_report_action_buttons', function( $buttons, $course_report_object ) {
    // Ensure the course_report_object is valid and has a course_id property
    if ( ! is_a( $course_report_object, 'CourseReport' ) || ! isset( $course_report_object->course_id ) ) {
        return $buttons;
    }

    // Define the details for the new button
    $new_button = array(
        'name'  => 'download_report',
        'label' => __( 'Download Report', 'your-text-domain' ),
        'url'   => add_query_arg(
            array(
                'action'    => 'download_ceu_report',
                'course_id' => $course_report_object->course_id,
                '_wpnonce'  => wp_create_nonce( 'download_ceu_report_' . $course_report_object->course_id ),
            ),
            admin_url( 'admin-ajax.php' ) // Using admin-ajax.php for AJAX actions
        ),
        'class' => 'button button-secondary',
    );

    // Add the new button to the end of the existing buttons array
    $buttons[] = $new_button;

    return $buttons;
}, 10, 2 );

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

public function get_buttons() {
		return apply_filters(
			'uo_ceu_credit_report_action_buttons',
			$this->buttons,
			$this
		);
	}


Scroll to Top