Filter uncanny-automator-pro

uap_option_all_h5p_content_types

Filters the available H5P content types displayed in the H5P integration settings.

add_filter( 'uap_option_all_h5p_content_types', $callback, 10, 1 );

Description

Filters the available H5P content types for use in Uncanny Automator Pro. Developers can modify this list to include or exclude specific H5P content types from being selectable within the plugin's automation triggers and actions. This filter fires when the H5P content type options are being prepared for display.


Usage

add_filter( 'uap_option_all_h5p_content_types', 'your_function_name', 10, 1 );

Parameters

$option (mixed)
This parameter contains the value of the option being filtered.

Return Value

The filtered value.


Examples

<?php

/**
 * Example function to filter the H5P content types available in Uncanny Automator Pro.
 * This example specifically removes 'H5P.CoursePresentation' from the list if it exists.
 *
 * @param array $h5p_content_types An array of H5P content types.
 * @return array The filtered array of H5P content types.
 */
function my_uncanny_automator_filter_h5p_content_types( $h5p_content_types ) {
	// Check if the specific content type we want to remove exists in the array.
	if ( isset( $h5p_content_types['H5P.CoursePresentation'] ) ) {
		// Unset the specific content type to remove it from the list.
		unset( $h5p_content_types['H5P.CoursePresentation'] );
	}

	// Always return the modified array.
	return $h5p_content_types;
}

// Add the filter to the 'uap_option_all_h5p_content_types' hook.
// The priority is 10 by default, and we are accepting 1 argument ($option).
add_filter( 'uap_option_all_h5p_content_types', 'my_uncanny_automator_filter_h5p_content_types', 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

uncanny-automator-pro/src/integrations/h5p/helpers/h5p-pro-helpers.php:126

public function all_h5p_content_types( $label = null, $option_code = 'H5P_CONTENTTYPE', $any_option = true ) {

		if ( ! $label ) {
			$label = __( 'Type', 'uncanny-automator' );
		}

		global $wpdb;
		$options = array();

		if ( Automator()->helpers->recipe->load_helpers ) {
			// Get the library content
			$types = $wpdb->get_results(
				"SELECT t.id,t.title FROM {$wpdb->prefix}h5p_libraries t WHERE t.runnable = 1 "
			);

			if ( $any_option ) {
				$options['-1'] = __( 'Any type', 'uncanny-automator' );
			}
			if ( ! empty( $types ) ) {
				foreach ( $types as $type ) {
					$options[ $type->id ] = $type->title;
				}
			}
		}
		$option = array(
			'option_code'     => $option_code,
			'label'           => $label,
			'input_type'      => 'select',
			'required'        => true,
			// to setup example, lets define the value the child will be based on
			'current_value'   => false,
			'validation_type' => 'text',
			'options'         => $options,
		);

		return apply_filters( 'uap_option_all_h5p_content_types', $option );
	}

Scroll to Top