uo_tincanny_reporting_tincanny_data
Filters the Tincanny reporting data before it is displayed to administrators.
add_filter( 'uo_tincanny_reporting_tincanny_data', $callback, 10, 1 );
Description
Filter the data array passed to the Tincanny reporting JavaScript. Developers can modify this array to customize reporting data, such as adding or altering fields like the 'url' or 'administrator_view' status, before it's sent to the frontend.
Usage
add_filter( 'uo_tincanny_reporting_tincanny_data', 'your_function_name', 10, 1 );
Parameters
-
$administrator_view(mixed) - This parameter indicates whether the current user viewing the report has administrator privileges.
Return Value
The filtered value.
Examples
add_filter(
'uo_tincanny_reporting_tincanny_data',
function( $data, $administrator_view ) {
// Example: Conditionally add a new key to the data array if the user is an administrator.
if ( true === $administrator_view ) {
$data['adminSpecificInfo'] = array(
'message' => __( 'Welcome, Administrator!', 'your-text-domain' ),
);
}
// Example: Modify the page length based on a custom user meta field if it exists.
if ( is_user_logged_in() ) {
$user_id = get_current_user_id();
$custom_page_length = get_user_meta( $user_id, 'tincanny_custom_report_page_length', true );
if ( ! empty( $custom_page_length ) && is_numeric( $custom_page_length ) ) {
$data['pageLength'] = intval( $custom_page_length );
}
}
return $data;
},
10, // Priority: Default priority.
2 // Accepted args: The filter provides $data and $administrator_view.
);
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-admin-menu.php:327
public static function get_script_data() {
$roles = array();
if ( is_user_logged_in() ) {
$user = wp_get_current_user();
$roles = (array) $user->roles;
}
$administrator_view = false;
if ( in_array( 'administrator', $roles, true ) ) {
$administrator_view = true;
}
return apply_filters(
'uo_tincanny_reporting_tincanny_data',
array(
'url' => array(
'updateData' => admin_url( 'admin.php?page=learndash_data_upgrades' ),
),
'i18n' => Translations::get_i18n_strings(),
'administratorView' => $administrator_view,
'pageLength' => get_option( 'tincanny_user_report_default_page_length', 50 ),
)
);
}