performance_timer_url
Filters the URL path for the simple timer performance script, allowing modification before it's loaded.
add_filter( 'performance_timer_url', $callback, 10, 1 );
Description
This filter hook allows developers to modify the URL for the performance timer script. It fires when the performance timer settings are being initialized. Developers can use this hook to dynamically change the path to the performance timer script, perhaps for custom integrations or alternative script locations. The default value points to a core plugin file.
Usage
add_filter( 'performance_timer_url', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to hook into the 'performance_timer_url' filter.
* This example demonstrates changing the default performance timer script URL
* to a custom one, perhaps for a different version or a localized file.
*/
add_filter( 'performance_timer_url', 'my_custom_performance_timer_url', 10, 1 );
/**
* Modifies the URL for the performance timer script.
*
* @param string $default_url The default URL provided by the plugin.
* @return string The modified or custom URL for the performance timer script.
*/
function my_custom_performance_timer_url( $default_url ) {
// Get the current plugin directory URL.
// Assuming UO_FILE is defined elsewhere and points to the main plugin file.
// If UO_FILE is not available, you might need to use plugins_url() directly
// with your plugin's slug.
if ( defined( 'UO_FILE' ) ) {
$plugin_dir_path = dirname( UO_FILE );
$custom_url = plugins_url( basename( $plugin_dir_path ) ) . '/assets/js/my-custom-timer.js';
} else {
// Fallback if UO_FILE is not defined, assuming a plugin slug like 'ultimate-online-courses'.
// Adjust 'ultimate-online-courses' to your actual plugin slug.
$custom_url = plugins_url( 'assets/js/my-custom-timer.js', 'ultimate-online-courses' );
}
// You could also dynamically decide based on some condition, for example:
// if ( is_user_logged_in() && current_user_can('edit_posts') ) {
// return $custom_url;
// }
// For this example, we'll always return the custom URL.
return $custom_url;
}
?>
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/classes/course-timer.php:1062
'timedOutMessage' => $timed_out_message,
'uoHeartBeatInterval' => (int) $timer_interval,
'enablePerformanceTimer' => $disable_performance_timer,
'enableDebugMode' => $enable_debug_mode,
'enableLogouMode' => $enable_logout_mode,
'WPAdminURL' => admin_url('admin-ajax.php'),
'timerLogoutNonce' => wp_create_nonce('uo_course_timer_logout_nonce'),
'performanceApiUrl' => apply_filters( 'performance_timer_url', plugins_url( basename( dirname( UO_FILE ) ) ) . '/src/includes/simple_timer_performance.php' ),
);
wp_localize_script( 'uo-timer-js', 'uoTimer', $localize_data_array );
wp_enqueue_script( 'uo-timer-js' );