Filter uncanny-continuing-education-credits

uncanny_owl_notification_content_display

Filters the notification content before it is displayed to users.

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

Description

Allows developers to modify the formatted content of notifications before they are displayed. Applied after `wpautop`, this filter provides an opportunity to further customize or sanitize the notification text, ensuring dynamic presentation. Use this to add custom HTML, links, or modify the existing content as needed.


Usage

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

Parameters

$notifications (mixed)
This parameter contains an array of notification data that will be processed to format their content.

Return Value

The filtered value.


Examples

/**
 * Example function to modify the notification content display.
 * This function will add a specific prefix to the notification content.
 *
 * @param string $notification_content The current notification content.
 * @return string The modified notification content.
 */
function my_custom_notification_content_prefix( $notification_content ) {
    // Ensure we are working with a string and it's not empty.
    if ( is_string( $notification_content ) && ! empty( $notification_content ) ) {
        // Add a custom prefix to the beginning of the notification content.
        $prefix = '<strong class="my-custom-notification-prefix">[IMPORTANT]</strong> ';
        return $prefix . $notification_content;
    }

    // Return the original content if it's not a non-empty string.
    return $notification_content;
}

// Add the filter to WordPress.
// The second parameter '1' indicates that our callback function accepts one argument.
add_filter( 'uncanny_owl_notification_content_display', 'my_custom_notification_content_prefix', 10, 1 );

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/notifications/notifications.php:536

public function get_notifications_with_formatted_content( $notifications ) {
			if ( ! is_array( $notifications ) || empty( $notifications ) ) {
				return $notifications;
			}

			foreach ( $notifications as $key => $notification ) {
				if ( ! empty( $notification['content'] ) ) {
					$notifications[ $key ]['content'] = wpautop( $notification['content'] );
					$notifications[ $key ]['content'] = apply_filters( 'uncanny_owl_notification_content_display', $notifications[ $key ]['content'] );
				}
			}

			return $notifications;
		}

Scroll to Top