tincanny_additional_user_profile
Fires to allow adding custom fields and content to the user profile page before it is displayed.
add_action( 'tincanny_additional_user_profile', $callback, 10, 1 );
Description
Fired on the WordPress user profile edit screen, this action allows developers to add custom fields or functionality related to Tin Can data management for administrators. Use it to integrate custom controls or display additional user-specific Tin Can information before the profile is saved.
Usage
add_action( 'tincanny_additional_user_profile', 'your_function_name', 10, 1 );
Parameters
-
$profileuser(mixed) - This parameter, `$profileuser`, is a mixed type and is expected to contain information about the user whose profile is currently being displayed.
Examples
// Add extra information to the Uncanny Tin Can user profile page.
// This action hook is triggered on the user profile page when the user has 'manage_options' capability.
// It allows developers to add custom fields or information to the user's profile.
add_action( 'tincanny_additional_user_profile', 'my_uncanny_tin_can_extra_profile_info', 10, 1 );
/**
* Adds custom information to the Uncanny Tin Can user profile page.
*
* @param WP_User $profileuser The WP_User object for the current user profile being displayed.
*/
function my_uncanny_tin_can_extra_profile_info( $profileuser ) {
// This function is intended to be an example and can be expanded.
// For instance, you might want to display the number of Tin Can statements for this user.
// Check if the current user has the capability to view this sensitive data.
if ( current_user_can( 'read_private_reports' ) ) {
?>
<h3><?php esc_html_e( 'Tin Can Activity Summary', 'my-text-domain' ); ?></h3>
<table class="form-table">
<tbody>
<tr>
<th scope="row"><?php esc_html_e( 'Total Tin Can Statements', 'my-text-domain' ); ?></th>
<td>
<?php
// Example: Fetch and display the count of Tin Can statements for the user.
// Replace this with actual logic to query your Tin Can data.
$tincan_statement_count = 0; // Placeholder for actual count.
// $tincan_statement_count = Uncanny_Tin_CanData_Manager::get_statement_count( $profileuser->ID );
if ( $tincan_statement_count > 0 ) {
echo esc_html( $tincan_statement_count );
} else {
esc_html_e( 'No Tin Can statements found for this user.', 'my-text-domain' );
}
?>
</td>
</tr>
<tr>
<th scope="row"><?php esc_html_e( 'Last Statement Date', 'my-text-domain' ); ?></th>
<td>
<?php
// Example: Fetch and display the date of the last Tin Can statement.
// Replace this with actual logic to query your Tin Can data.
$last_statement_date = 'N/A'; // Placeholder for actual date.
// $last_statement_date = Uncanny_Tin_CanData_Manager::get_last_statement_date( $profileuser->ID );
if ( 'N/A' !== $last_statement_date ) {
echo esc_html( date_i18n( get_option( 'date_format' ), strtotime( $last_statement_date ) ) );
} else {
esc_html_e( 'No Tin Can statements found for this user.', 'my-text-domain' );
}
?>
</td>
</tr>
</tbody>
</table>
<?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/uncanny-tincan/classes/Init.php:147
public function show_user_profile( $profileuser ) {
if ( current_user_can( 'manage_options' ) ) {
$args = array(
'numberposts' => 9999, // phpcs:ignore WordPress.WP.PostsPerPage.posts_per_page_numberposts
'post_type' => 'sfwd-courses',
'orderby' => 'title',
'order' => 'ASC',
);
$ld_courses = get_posts( $args );
?>
<h2><?php esc_html_e( 'Permanently Delete Tin Can Data', 'uncanny-learndash-reporting' ); ?></h2>
<p>
<input type="checkbox" id="purge_tincanny_records" name="purge_tincanny_records"/>
<label for="purge_tincanny_records">
<?php
// translators: %1$s is "Update", and %2$s is "tin can data"
printf( _x( 'Check and click %1$s to delete all %2$s for this user.', '%1$s is "Update", and %2$s is "tin can data"', 'uncanny-learndash-reporting' ), sprintf( '<em>%s</em>', esc_html__( 'Update', 'uncanny-learndash-reporting' ) ), sprintf( '<strong>%s</strong>', esc_html__( 'tin can data', 'uncanny-learndash-reporting' ) ) );
?>
<strong><?php esc_html_e( 'This cannot be undone.', 'uncanny-learndash-reporting' ); ?></strong>
</label>
</p>
<p>
<input type="checkbox" id="purge_resume_records" name="purge_resume_records"/>
<label for="purge_resume_records">
<?php
// translators: %1$s is "Update", and %2$s is "bookmark data"
printf( esc_html_x( 'Check and click %1$s to delete all %2$s for this user.', '%1$s is "Update", and %2$s is "bookmark data"', 'uncanny-learndash-reporting' ), sprintf( '<em>%s</em>', esc_html__( 'Update', 'uncanny-learndash-reporting' ) ), sprintf( '<strong>%s</strong>', esc_html__( 'bookmark data', 'uncanny-learndash-reporting' ) ) );
?>
<strong><?php esc_html_e( 'This cannot be undone.', 'uncanny-learndash-reporting' ); ?></strong>
</label>
</p>
<p>
<label for="purge_course_resume_records">
<?php
// translators: %1$s is "Update", and %2$s is "bookmark data"
printf( esc_html_x( 'Choose a course and click %1$s to delete all %2$s for the selected course for this user.', '%1$s is "Update", and %2$s is "bookmark data"', 'uncanny-learndash-reporting' ), sprintf( '<em>%s</em>', esc_html__( 'Update', 'uncanny-learndash-reporting' ) ), sprintf( '<strong>%s</strong>', esc_html__( 'bookmark data', 'uncanny-learndash-reporting' ) ) );
?>
<strong><?php esc_html_e( 'This cannot be undone.', 'uncanny-learndash-reporting' ); ?></strong>
<div class="purge_course_resume_wrapper">
<?php if( ! empty($ld_courses) ) : ?>
<select class="uo_settings_single" id="purge_course_resume_records" name="purge_course_resume_records">
<option value='' selected><?php echo esc_html__( '-No Action-', 'uncanny-learndash-reporting' ); ?></option>
<?php foreach ( $ld_courses as $course ) { ?>
<option value="<?php echo esc_attr( $course->ID ); ?>">
<?php echo esc_html( $course->post_title ); ?>
</option>
<?php } // foreach( $ld_courses ) ?>
</select>
<?php else : ?>
<select disabled class="uo_settings_single" id="purge_course_resume_records" name=>
<option value='' disabled selected><?php echo esc_html__( 'No courses found.', 'uncanny-learndash-reporting' ); ?></option>
</select>
<?php endif; ?>
</div>
</label>
</p>
<?php
// Action for additional user information.
do_action( 'tincanny_additional_user_profile', $profileuser );
}
}