uncannyowl-learndash-toolkit-js
Filters the JavaScript object used by the Uncanny LearnDash Toolkit, allowing modification of AJAX, integrity, and translation settings.
add_filter( 'uncannyowl-learndash-toolkit-js', $callback, 10, 1 );
Description
This filter hook allows developers to modify the JavaScript localization data passed to the Uncanny LearnDash Toolkit's frontend scripts. It provides an array containing AJAX settings, integrity checks, internationalized strings, and modal configurations, enabling customization of frontend behavior and text.
Usage
add_filter( 'uncannyowl-learndash-toolkit-js', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
/**
* Example of how to filter the 'uncannyowl-learndash-toolkit-js' hook.
* This function demonstrates adding a custom configuration to the JavaScript object
* localized for the frontend.
*
* @param array $js_config The original JavaScript configuration array.
* @return array The modified JavaScript configuration array.
*/
function my_custom_toolkit_js_config( $js_config ) {
// Add a new custom setting for a hypothetical new feature.
$js_config['customFeatureEnabled'] = true;
// Modify an existing translation string.
$js_config['i18n']['dismiss'] = __( 'Close Modal', 'my-text-domain' );
// Add a new modal configuration if you have a custom modal to display.
$js_config['modals']['welcomeMessage'] = array(
'title' => __( 'Welcome to Our Site!', 'my-text-domain' ),
'content' => __( 'We are happy to have you here. Explore our courses and get started.', 'my-text-domain' ),
'button' => __( 'Get Started', 'my-text-domain' ),
);
// You could also conditionally disable or enable certain built-in features.
// For example, if you have a custom implementation for concurrent login prevention
// and don't want the Uncanny Toolkit's version to run.
if ( function_exists( 'my_custom_concurrent_login_handler' ) ) {
$js_config['integrity']['shouldPreventConcurrentLogin'] = false;
}
return $js_config;
}
add_filter( 'uncannyowl-learndash-toolkit-js', 'my_custom_toolkit_js_config', 10, 1 );
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/boot.php:244
public static function uo_frontend_assets() {
wp_enqueue_style( 'uncannyowl-learndash-toolkit-free', plugins_url( 'src/assets/frontend/dist/bundle.min.css', dirname( __FILE__ ) ), array(), UNCANNY_TOOLKIT_VERSION );
wp_enqueue_script( 'uncannyowl-learndash-toolkit-free', plugins_url( 'src/assets/frontend/dist/bundle.min.js', dirname( __FILE__ ) ), array( 'jquery' ), UNCANNY_TOOLKIT_VERSION );
wp_localize_script(
'uncannyowl-learndash-toolkit-free',
'UncannyToolkit',
apply_filters(
'uncannyowl-learndash-toolkit-js',
array(
'ajax' => array(
'url' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'uncannyowl-learndash-toolkit' ),
),
'integrity' => array(
'shouldPreventConcurrentLogin' => self::ld_is_preventing_concurrent_login(),
),
'i18n' => array(
'dismiss' => __( 'Dismiss', 'uncanny-learndash-toolkit' ),
'preventConcurrentLogin' => __( 'Your account has exceeded maximum concurrent login number.', 'learndash-integrity' ),
'error' => array(
'generic' => __( 'Something went wrong. Please, try again', 'uncanny-learndash-toolkit' ),
),
),
'modals' => array(),
)
)
);
}