Action tin-canny-learndash-reporting

tincanny_reporting_wrapper_before_end

Fires just before the Tincanny reporting wrapper ends, allowing for custom actions or modifications.

add_action( 'tincanny_reporting_wrapper_before_end', $callback, 10, 1 );

Description

Fires just before the main reporting wrapper element closes. Developers can use this hook to add custom content or perform actions immediately before the reporting section concludes. It's ideal for injecting additional data or modifying the DOM just prior to rendering.


Usage

add_action( 'tincanny_reporting_wrapper_before_end', 'your_function_name', 10, 1 );

Examples

<?php
/**
 * Add a custom notification to the report if the user has completed less than 50% of the course.
 *
 * This function is hooked into 'tincanny_reporting_wrapper_before_end' to execute
 * just before the main reporting section ends. It checks the completion percentage
 * and if it's below 50%, it appends a notification message.
 */
add_action( 'tincanny_reporting_wrapper_before_end', 'tincanny_custom_completion_notification', 10, 0 );

function tincanny_custom_completion_notification() {
	// This hook doesn't pass any parameters according to the documentation.
	// We'll assume we need to access global variables or rely on other
	// plugin-provided functions to get the necessary context.
	// For demonstration, let's assume there's a global $tincanny_report_data
	// that contains completion percentage. In a real scenario, you'd likely
	// need to pass this data through the hook or access it differently.

	// Replace this with actual logic to get completion percentage.
	// For example, if $tincanny_report_data is available globally:
	// $completion_percentage = isset( $tincanny_report_data['completion_percentage'] ) ? $tincanny_report_data['completion_percentage'] : 0;

	// Placeholder for getting completion percentage. In a real plugin,
	// this data would likely be passed as arguments or available through context.
	// For this example, we'll simulate a scenario.
	$course_id = get_the_ID(); // Assuming we are within the WordPress loop or have a way to get the current course ID.
	$user_id   = get_current_user_id();

	if ( ! $user_id ) {
		return; // No user logged in.
	}

	// This is a hypothetical function. You would replace this with the actual
	// Tincanny function or your custom logic to retrieve completion data.
	// Example: $completion_percentage = Tincanny_Reporting_Helper::get_course_completion_percentage( $course_id, $user_id );
	$completion_percentage = rand( 0, 100 ); // Simulate completion percentage for demonstration.

	if ( $completion_percentage < 50 ) {
		?>
		<div class="tincanny-notification warning">
			<p>
				<?php
				printf(
					esc_html__( 'You have completed %d%% of the course. Keep going to reach 100%%!', 'your-text-domain' ),
					intval( $completion_percentage )
				);
				?>
			</p>
		</div>
		<?php
	}
}
?>

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/reporting/xapi-quiz/xapi-quiz-report.php:57
src/reporting/tin-can/tin-can-report.php:57
src/shortcode-tincanny/frontend.php:80
src/reporting/learndash/templates/course-user-wrapper.php:56

include __DIR__ . '/templates/table.php';
						}

						do_action( 'tincanny_reporting_after_content' );
						?>
					</section>

					<?php do_action( 'tincanny_reporting_wrapper_before_end' ); ?>
				</div>
			</div>
		</div>
	</div>

	<?php do_action( 'tincanny_reporting_wrapper_after_end' ); ?>


Scroll to Top