uo_show_group_certificate_link
Filters the certificate link shown for a user group, allowing modification before display.
add_filter( 'uo_show_group_certificate_link', $callback, 10, 2 );
Description
Filters the anchor tag for a group certificate link. Developers can modify the link's HTML, the link URL, or the displayed text. This hook is applied before the certificate link is outputted by the `uo_show_group_certificate_link` shortcode.
Usage
add_filter( 'uo_show_group_certificate_link', 'your_function_name', 10, 2 );
Parameters
-
$certificate_link(mixed) - The `$certificate_link` parameter contains the URL to the group certificate, which can be modified by the filter.
-
$group(mixed) - This parameter passes the current logged-in WordPress user object to the filter.
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to use the uo_show_group_certificate_link filter.
*
* This filter allows you to modify the HTML link for a group certificate.
* In this example, we're adding a class to the anchor tag for styling.
*/
add_filter( 'uo_show_group_certificate_link', function( $certificate_link_html, $current_user, $group ) {
// Check if the current user is an administrator. If so, add a special class.
if ( user_can( $current_user->ID, 'manage_options' ) ) {
$certificate_link_html = str_replace( '<a target="_blank"', '<a target="_blank" class="admin-certificate-link"', $certificate_link_html );
}
// You could also conditionally modify the link based on the group's properties.
// For example, if the group post type is 'custom_group_type':
// if ( 'custom_group_type' === $group->post_type ) {
// $certificate_link_html = str_replace( '<a target="_blank"', '<a target="_blank" data-group-type="custom"', $certificate_link_html );
// }
// Always return the modified or original HTML link.
return $certificate_link_html;
}, 10, 3 );
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/show-certificates-shortcode.php:266
} else {
$certificate_title = $group->post_title;
}
$certificate_link = esc_url( learndash_get_group_certificate_link( $group->ID ) );
if ( $certificate_link && '' !== $certificate_link ) {
$link = apply_filters( 'uo_show_group_certificate_link', sprintf( '<a target="_blank" href="%s">%s</a>', $certificate_link, esc_html( $certificate_title ) ), wp_get_current_user(), $group );
$certificate_list .= $link . '<br>';
}
}
}
}
$certificate_list = apply_filters_deprecated( 'certificate_list_shortcode', array( $certificate_list ), '3.6.2', 'uo_certificate_list_shortcode' );