Filter uncanny-automator

uap_option_all_wplms_units

Filters the settings for all WPLMS units, allowing customization before they are applied.

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

Description

Filters the available WPLMS unit options for Uncanny Automator. Developers can use this to add custom unit-related tokens or modify existing ones. This hook fires when Uncanny Automator is preparing its list of available WPLMS units for triggers and actions.


Usage

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

Return Value

The filtered value.


Examples

/**
 * Example of how to use the uap_option_all_wplms_units filter hook.
 *
 * This filter allows you to modify the options available for WPLMS units in Uncanny Automator.
 * In this example, we're adding a new option to display the author's display name for each unit.
 *
 * @param array $option The original array of options.
 * @return array The modified array of options.
 */
function my_automator_add_wplms_unit_author_option( $option ) {
	// Check if the WPLMS units option group exists.
	if ( isset( $option['options']['WPLMS_UNITS'] ) && is_array( $option['options']['WPLMS_UNITS'] ) ) {
		// Get the existing unit options array.
		$unit_options = $option['options']['WPLMS_UNITS'];

		// Add a new option for the unit author's display name.
		// We'll use a placeholder 'UNIT_AUTHOR_DISPLAY_NAME' and provide a descriptive label.
		$unit_options['UNIT_AUTHOR_DISPLAY_NAME'] = esc_attr__( 'Unit Author Display Name', 'uncanny-automator' );

		// Update the options array in the main $option array.
		$option['options']['WPLMS_UNITS'] = $unit_options;
	}

	// Always return the modified (or original if no changes were made) $option array.
	return $option;
}
add_filter( 'uap_option_all_wplms_units', 'my_automator_add_wplms_unit_author_option', 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/integrations/wplms/helpers/wplms-helpers.php:177

public function all_wplms_units( $label = null, $option_code = 'WPLMS_UNIT', $any_option = true ) {

		if ( ! $label ) {
			$label = esc_attr__( 'Unit', 'uncanny-automator' );
		}

		$args = array(
			'post_type'      => 'unit',
			'posts_per_page' => 9999,
			'orderby'        => 'title',
			'order'          => 'ASC',
			'post_status'    => 'publish',
		);

		$options = Automator()->helpers->recipe->options->wp_query( $args, $any_option, esc_attr__( 'Any unit', 'uncanny-automator' ) );

		$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,
			'relevant_tokens' => array(
				$option_code                => esc_attr__( 'Unit title', 'uncanny-automator' ),
				$option_code . '_ID'        => esc_attr__( 'Unit ID', 'uncanny-automator' ),
				$option_code . '_URL'       => esc_attr__( 'Unit URL', 'uncanny-automator' ),
				$option_code . '_THUMB_ID'  => esc_attr__( 'Unit featured image ID', 'uncanny-automator' ),
				$option_code . '_THUMB_URL' => esc_attr__( 'Unit featured image URL', 'uncanny-automator' ),
			),
		);

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

Scroll to Top