Filter tin-canny-learndash-reporting

tincanny_module_url_preview

Filters the URL used for a Tincanny module preview, allowing modification before it's displayed.

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

Description

Allows modification of the module URL for preview. Developers can alter the generated `$src` URL for Tin Can content, useful for custom URL structures or external hosting. The `$post` object is also provided for context.


Usage

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

Parameters

$src (mixed)
This parameter holds the URL of the content item being previewed, typically generated from the site's URL and the item's relative path.
$post (mixed)
This parameter holds the URL of the content being previewed, which is typically constructed from the site's URL and the content's relative path.

Return Value

The filtered value.


Examples

<?php
/**
 * Modify the module URL for preview to point to a specific staging environment if the post is a draft.
 *
 * @param string $src The original module URL.
 * @param object $post The WordPress post object.
 * @return string The potentially modified module URL.
 */
add_filter( 'tincanny_module_url_preview', function ( $src, $post ) {
	// Check if the post status is 'draft' and if we are in a development environment.
	if ( 'draft' === $post->post_status && defined( 'WP_ENVIRONMENT_TYPE' ) && 'local' === WP_ENVIRONMENT_TYPE ) {
		// Construct a staging URL for drafts in a local development environment.
		// This is a hypothetical example; adjust the URL construction based on your actual setup.
		$staging_domain = 'staging.example.com';
		$post_id        = $post->ID;
		$modified_src   = trailingslashit( "http://{$staging_domain}/wp-content/uploads/tincanny_modules/" ) . $post_id . '/index.html'; // Example structure
		return $modified_src;
	}

	// If not a draft or not in a local environment, return the original URL.
	return $src;
}, 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/includes/TinCan_Content_List_Table.php:156

wp_schedule_single_event( time() + 1, 'tincanny_calculate_folder_size', array( $post->ID ) );
					}
				}
				
				$modified_date = ( $post->upload_date && $post->upload_date !== '0000-00-00 00:00:00' ) ? date( 'Y-m-d H:i:s', strtotime( $post->upload_date ) ) : '-';

				$src        = site_url( $post->url );
				$src        = apply_filters( 'tincanny_module_url_preview', $src, $post );
				$user       = wp_get_current_user();
				$user_data  = is_a( $user, 'WP_User' ) && isset( $user->data ) ? $user->data : false;
				$user_name  = $user_data && isset( $user_data->display_name ) ? $user_data->display_name : 'Unknown';
				$user_name  = str_replace( array( '"', "'" ), array( '', '' ), $user_name );
				$user_email = $user_data && isset( $user_data->user_email ) ? $user_data->user_email : '[email protected]';
				$user_email = apply_filters( 'uo_tincanny_actor_mbox', $user_email, $user );


Scroll to Top