Filter uncanny-learndash-toolkit

certificate_list_widget

Filters the list of certificates displayed in the widget before it is rendered to the user.

add_filter( 'certificate_list_widget', $callback, 10, 1 );

Description

This filter hook, `certificate_list_widget`, allows developers to modify the array of certificates displayed in the widget. It fires after the certificates are fetched but before they are rendered. Developers can add, remove, or alter certificate data, ensuring custom logic is applied to the widget's output. Always ensure the returned value is an array to prevent unexpected behavior.


Usage

add_filter( 'certificate_list_widget', 'your_function_name', 10, 1 );

Parameters

$certificate_list (mixed)
This parameter contains an array of certificates that will be displayed in the widget.

Return Value

The filtered value.


Examples

/**
 * Example filter for the certificate_list_widget hook.
 * This function demonstrates how to modify the list of certificates displayed in the widget.
 * For instance, it could be used to only show certificates published after a certain date,
 * or to remove specific certificates based on their ID or title.
 */
add_filter( 'certificate_list_widget', function( $certificate_list ) {
    // Example: Only include certificates where the title contains the word "Advanced".
    $filtered_list = [];
    if ( is_array( $certificate_list ) ) {
        foreach ( $certificate_list as $certificate_id => $certificate_data ) {
            // Assuming $certificate_data is an array and has a 'title' key.
            // The actual structure of $certificate_data will depend on how the widget generates it.
            if ( isset( $certificate_data['title'] ) && strpos( $certificate_data['title'], 'Advanced' ) !== false ) {
                $filtered_list[ $certificate_id ] = $certificate_data;
            }
        }
    }

    // If the filtering resulted in an empty list, you might want to return the original list
    // or handle it differently based on your needs. For this example, we'll return the filtered list.
    // If $filtered_list is empty, the widget will display the "no_certs" message.
    return $filtered_list;
}, 10, 1 ); // Priority 10, accepts 1 argument.

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/widget-cert.php:273

esc_html( $certificate_title )
						),
					);
				}
			}
		}

		$filtered_certificate_list = apply_filters( 'certificate_list_widget', $certificate_list );
		if( ! is_array( $filtered_certificate_list ) ) {
			$filtered_certificate_list = $certificate_list; // Make sure to fallback to original list.
		}

		if ( empty( $filtered_certificate_list )  ) {
			printf( '<p>%s</p>', esc_html( $instance['no_certs'] ) );
		} else {

Scroll to Top