Filter uncanny-automator-pro

uap_option_all_edd_downloads_simple

Filters the options array for all Easy Digital Downloads simple products.

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

Description

Fires after retrieving all Easy Digital Downloads (EDD) downloads, allowing modification of the returned options array. Developers can use this filter to alter the display label, input type, options, or add relevant tokens for automations. This hook is ideal for custom integrations or modifying how EDD downloads are presented within Uncanny Automator Pro recipes.


Usage

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

Parameters

$option (mixed)
This parameter contains the value of the dropdown option, which can be the ID of a download or a placeholder like 'any'.

Return Value

The filtered value.


Examples

/**
 * Example function to modify the options for the UAP EDD Downloads select field.
 * This example will prepend a specific string to the label of each download.
 *
 * @param array $option The array containing the select field options.
 * @return array The modified options array.
 */
add_filter( 'uap_option_all_edd_downloads_simple', function( $option ) {

	// Check if the 'options' key exists and is an array.
	if ( isset( $option['options'] ) && is_array( $option['options'] ) ) {
		// Iterate over each download in the options.
		foreach ( $option['options'] as $download_id => $download_data ) {
			// Prepend a string to the label of each download.
			if ( isset( $download_data['label'] ) ) {
				$option['options'][ $download_id ]['label'] = '[PRO] ' . $download_data['label'];
			}
		}
	}

	return $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

uncanny-automator-pro/src/integrations/edd/helpers/edd-pro-helpers.php:175

public function all_edd_downloads_not_required( $label = null, $option_code = 'EDDPRODUCTS', $any_option = true, $is_recurring = false ) {

		if ( ! $label ) {
			$label = esc_html_x( 'Download', 'Easy Digital Downloads', 'uncanny-automator' );
		}

		$args = array(
			'post_type'      => 'download',
			'posts_per_page' => 9999, //phpcs:ignore WordPress.WP.PostsPerPage.posts_per_page_posts_per_page
			'orderby'        => 'title',
			'order'          => 'ASC',
			'post_status'    => 'publish',
		);

		$downloads = get_posts( $args );

		$all_downloads = array();

		if ( $any_option ) {
			$all_downloads[] = array(
				'text'  => esc_html_x( 'Any download', 'Easy Digital Downloads', 'uncanny-automator' ),
				'value' => '-1',
			);
		}

		if ( $downloads ) {
			foreach ( $downloads as $download ) {
				$download_id = $download->ID;

				// Just list everything
				if ( ! $is_recurring ) {
					$all_downloads[] = array(
						'text'  => $download->post_title,
						'value' => $download_id,
					);
					continue;
				}

				// Check if the product has a recurring option
				if ( edd_recurring()->is_recurring( $download_id ) ) {
					$all_downloads[] = array(
						'text'  => $download->post_title,
						'value' => $download_id,
					);
					continue;
				}

				if ( ! edd_has_variable_prices( $download_id ) ) {
					continue;
				}

				$variable_prices = edd_get_variable_prices( $download_id );

				if ( $variable_prices ) {
					foreach ( $variable_prices as $price ) {
						if ( ! isset( $price['recurring'] ) || 'yes' !== $price['recurring'] ) {
							continue;
						}
						$all_downloads[] = array(
							'text'  => $download->post_title,
							'value' => $download_id,
						);
					}
				}
			}
		}

		$option = array(
			'option_code'     => $option_code,
			'label'           => $label,
			'input_type'      => 'select',
			'required'        => false,
			'options'         => $all_downloads,
			'relevant_tokens' => array(), // empty
		);

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

Scroll to Top