tincanny_reporting_content
Fires when content is being generated for the TinyMCE editor reporting interface.
add_action( 'tincanny_reporting_content', $callback, 10, 1 );
Description
Fires within the Tin Can reporting section to allow for custom content insertion. Developers can use this hook to add extra elements, modify the default reporting interface, or integrate custom data displays before the reporting content is rendered. It's a prime opportunity for extending reporting functionality.
Usage
add_action( 'tincanny_reporting_content', 'your_function_name', 10, 1 );
Examples
<?php
/**
* Example of how to hook into 'tincanny_reporting_content' to add custom content
* to the reporting section, perhaps displaying additional user data related to xAPI quiz attempts.
*/
add_action( 'tincanny_reporting_content', 'my_custom_tincanny_reporting_content', 10 );
/**
* Custom function to display additional user xAPI quiz reporting data.
*/
function my_custom_tincanny_reporting_content() {
// In a real scenario, you would likely check if a user is logged in,
// retrieve relevant data based on selected filters (which are handled
// before this hook is fired in the source code), and then display it.
// For demonstration, let's assume we have a way to get the current user's ID.
$current_user_id = get_current_user_id();
if ( $current_user_id ) {
// Assume you have a function to get xAPI quiz data for a user.
// Replace 'get_user_xapi_quiz_attempts' with your actual function.
$quiz_data = get_user_xapi_quiz_attempts( $current_user_id );
if ( ! empty( $quiz_data ) ) {
?>
<div class="my-custom-tincanny-reporting-section">
<h3><?php _e( 'Additional Quiz Performance Details', 'your-text-domain' ); ?></h3>
<ul>
<?php foreach ( $quiz_data as $attempt ) : ?>
<li>
<strong><?php echo esc_html( $attempt['quiz_title'] ); ?></strong>:
<?php printf(
// Translators: %s is the score.
__( 'Score: %s', 'your-text-domain' ),
esc_html( $attempt['score'] )
); ?> -
<?php printf(
// Translators: %s is the date.
__( 'Completed: %s', 'your-text-domain' ),
esc_html( $attempt['completion_date'] )
); ?>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php
} else {
?>
<div class="my-custom-tincanny-reporting-section">
<p><?php _e( 'No specific quiz performance data found for this user.', 'your-text-domain' ); ?></p>
</div>
<?php
}
} else {
// If no user is logged in, or if you need to display a message for logged-out users.
// However, the source code suggests this hook is called only when filters are applied,
// implying a user context is likely available or relevant.
}
}
/**
* Placeholder function to simulate fetching xAPI quiz attempts for a user.
* In a real plugin, this would query your xAPI data store.
*
* @param int $user_id The ID of the user.
* @return array An array of quiz attempt data.
*/
function get_user_xapi_quiz_attempts( $user_id ) {
// This is a mock implementation. Replace with actual data retrieval.
// Simulate some data for demonstration purposes.
if ( $user_id === get_current_user_id() ) { // Only return data for the current user in this mock
return array(
array(
'quiz_id' => 123,
'quiz_title' => 'WordPress Basics Quiz',
'score' => '85%',
'completion_date' => '2023-10-27 10:30:00',
'passed' => true,
),
array(
'quiz_id' => 456,
'quiz_title' => 'Advanced PHP Concepts',
'score' => '70%',
'completion_date' => '2023-10-26 15:00:00',
'passed' => false,
),
);
}
return array();
}
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:48
src/reporting/tin-can/tin-can-report.php:48
src/shortcode-tincanny/frontend.php:74
src/reporting/learndash/templates/course-user-wrapper.php:50
if ( ! ultc_filter_has_var( 'tc_filter_mode' ) ) {
?>
<div class="tincanny-tin-canny-error">
<p><?php _e( 'Please select your criteria to filter the xAPI Quiz data', 'uncanny-learndash-reporting' ); ?></p>
</div>
<?php
} else {
do_action( 'tincanny_reporting_content' );
include __DIR__ . '/templates/table.php';
}
do_action( 'tincanny_reporting_after_content' );
?>
</section>