Filter uncanny-automator

uap_option_all_edd_downloads

Filters all EDD downloads option before it's retrieved, allowing modification of the data.

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

Description

Filters all Easy Digital Downloads options, including download selections, before they are processed. Developers can use this hook to modify, add, or remove available EDD download options displayed within the Uncanny Automator interface, offering granular control over automation triggers and actions.


Usage

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

Parameters

$option (mixed)
This parameter represents the array of options for the EDD downloads dropdown, which includes label, input type, requirement, and available options.

Return Value

The filtered value.


Examples

add_filter( 'uap_option_all_edd_downloads', 'my_custom_edd_downloads_filter', 10, 1 );

/**
 * Example filter to modify the available EDD download options.
 * This function demonstrates how to conditionally remove or modify options
 * based on specific criteria, such as a download's price or category.
 *
 * @param array $option The array of EDD download options passed by the hook.
 * @return array The modified array of EDD download options.
 */
function my_custom_edd_downloads_filter( $option ) {
	// Check if the 'options' key exists in the $option array.
	if ( isset( $option['options'] ) && is_array( $option['options'] ) ) {
		$modified_options = array();

		// Iterate through each download option.
		foreach ( $option['options'] as $download_id => $download_data ) {
			// Example: Exclude downloads that are not published or have a price greater than 50.
			if ( $download_id !== 'any' && $download_id !== '-1' ) {
				$download_post = get_post( $download_id );

				// Check if the post exists and is published.
				if ( $download_post && 'publish' === $download_post->post_status ) {
					$price = edd_get_download_price( $download_id );

					// Only include downloads with a price less than or equal to 50.
					if ( $price !== false && $price <= 50 ) {
						$modified_options[ $download_id ] = $download_data;
					}
				}
			} else {
				// Keep special options like 'any' or '-1' if they exist.
				$modified_options[ $download_id ] = $download_data;
			}
		}

		// Update the options in the original array.
		$option['options'] = $modified_options;
	}

	return $option;
}

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/edd-recurring/helpers/edd-recurring-helpers.php:123
src/integrations/edd/helpers/edd-helpers.php:252

'label'           => $label,
			'input_type'      => 'select',
			'required'        => true,
			'options'         => $options,
			'relevant_tokens' => $relevant_tokens,
		);

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

	/**
	 * Get price options for a specific download
	 *
	 * @param int|string $download_id The download ID or -1 for any download.
	 * @param bool $include_any Whether to include "Any price option".

Scroll to Top