Filter tin-canny-learndash-reporting

h5p-xapi-auth-settings

Filters H5P xAPI authentication settings before they are saved.

add_filter( 'h5p-xapi-auth-settings', $callback, 10, 1 );

Description

Filters the H5P xAPI authentication settings before they are used. Developers can modify the endpoint URL, username, or password. If no custom settings are returned, defaults are loaded from WordPress options.


Usage

add_filter( 'h5p-xapi-auth-settings', 'your_function_name', 10, 1 );

Return Value

The filtered value.


Examples

add_filter( 'h5p-xapi-auth-settings', 'my_custom_h5pxapi_auth_settings', 10, 1 );

/**
 * Filters the H5P xAPI authentication settings.
 *
 * This function allows developers to override the default H5P xAPI
 * authentication settings, for example, by fetching them from
 * a custom configuration or an environment variable.
 *
 * @param mixed $settings The current authentication settings.
 * @return array An array of authentication settings, including 'endpoint_url', 'username', and 'password'.
 */
function my_custom_h5pxapi_auth_settings( $settings ) {
	// If no settings have been provided by other plugins or the default get_option calls,
	// we can provide our own custom settings here.
	if ( ! $settings ) {
		// Example: Fetching settings from environment variables for enhanced security.
		// In a real-world scenario, you might also check for a custom plugin's options
		// or a dedicated configuration file.
		$custom_endpoint_url = getenv( 'H5P_XAPI_ENDPOINT_URL' );
		$custom_username       = getenv( 'H5P_XAPI_USERNAME' );
		$custom_password       = getenv( 'H5P_XAPI_PASSWORD' );

		// Only override if custom settings are found.
		if ( $custom_endpoint_url && $custom_username && $custom_password ) {
			$settings = array(
				'endpoint_url' => $custom_endpoint_url,
				'username'     => $custom_username,
				'password'     => $custom_password,
			);
		}
		// If no custom settings are found, the default get_option calls in the
		// original function will handle it, so we don't need an 'else' here.
	}

	return $settings;
}

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/h5p-xapi/plugin.php:16
src/h5p-xapi/wp-h5p-xapi.php:96

function h5pxapi_get_auth_settings() {
		$settings=apply_filters("h5p-xapi-auth-settings",NULL);

		if (!$settings) {
			$settings=array(
				"endpoint_url"=>get_option("h5pxapi_endpoint_url"),
				"username"=>get_option("h5pxapi_username"),
				"password"=>get_option("h5pxapi_password")
			);
		}

		return $settings;
	}

Scroll to Top