Filter Since 3.6.4 uncanny-toolkit-pro

uo_group_certificate_url

New filter added so that arguments can be passed. Adding arguments to previous filter above might break sites since there might be no argument supplied with override function Filters the URL for a group certificate, allowing modification of the link based on user, group, and certificate data.

add_filter( 'uo_group_certificate_url', $callback, 10, 3 );

Description

This filter allows developers to dynamically modify the group certificate URL. It fires after the base URL is determined and before the filename is appended. Use this hook to customize the certificate link, perhaps by adding query parameters or changing the base path. It's crucial to pass through the original `$http_link` and other arguments to ensure backward compatibility.


Usage

add_filter( 'uo_group_certificate_url', 'your_function_name', 10, 3 );

Parameters

$http_link (mixed)
- **$user** `mixed`
$group_id (mixed)
- **$certificate_post** `mixed`
$current_time_stamp (mixed)

Return Value

The filtered value.


Examples

/**
 * Example of how to use the 'uo_group_certificate_url' filter hook.
 *
 * This filter allows you to modify the URL where a group completion certificate
 * PDF will be stored or accessed. In this example, we're adding a unique
 * timestamp to the URL to ensure versioning or to prevent caching issues,
 * and we're also prepending a custom directory path.
 */
add_filter( 'uo_group_certificate_url', function( $http_link, $user, $group_id, $certificate_post, $current_time_stamp ) {

	// Ensure we have valid arguments before proceeding.
	if ( ! is_string( $http_link ) || ! is_object( $user ) || ! is_numeric( $group_id ) || ! is_object( $certificate_post ) || ! is_numeric( $current_time_stamp ) ) {
		// If arguments are not as expected, return the original link to prevent errors.
		return $http_link;
	}

	// Get the user's username to use in the path.
	$username = $user->user_login;

	// Define a custom directory path within the uploads directory.
	$custom_path = '/group-certificates/' . sanitize_title( $username ) . '/' . $group_id . '/';

	// Append the custom path to the base HTTP link.
	// We'll also append the timestamp to the http_link itself, assuming it's a base directory.
	$modified_http_link = trailingslashit( content_url() . $custom_path ) . date( 'Y/m/d/', $current_time_stamp );

	// Optionally, you could further modify the $http_link based on the $certificate_post ID or other data.
	// For example:
	// $certificate_title = get_the_title( $certificate_post->ID );
	// $modified_http_link = trailingslashit( $modified_http_link ) . sanitize_title( $certificate_title ) . '/';

	return $modified_http_link;

}, 10, 5 ); // Priority 10, accepts 5 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/group-completion-certificate.php:327

* to previous filter above might break sites since
		 * there might be no argument supplied with override function
		 *
		 * @since  3.6.4
		 * @author Saad
		 * @var $http_link
		 */
		$http_link         = apply_filters( 'uo_group_certificate_url', $http_link, $user, $group_id, $certificate_post, self::$current_time_stamp );
		$http_link_to_file = $http_link . $file_name . '.pdf';
		do_action( 'uo_group_certificate_pdf_url', $http_link_to_file, $group_id, self::$current_time_stamp, $user_id );
		$current_certs = get_user_meta( $user_id, $group_cert_meta, true );
		if ( ! empty( $current_certs ) ) {
			$current_certs[][ self::$current_time_stamp ] = $http_link_to_file;
			update_user_meta( $user_id, $group_cert_meta, $current_certs );
		} else {


Scroll to Top