Filter uncanny-automator-pro

uap_option_all_wp_sites

Filters the list of all WordPress sites for UAP integration before it is retrieved.

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

Description

Filters the options array for the "all WordPress sites" select field in Uncanny Automator Pro's WP Multisite integrations. Developers can use this hook to modify the available site options, such as adding custom sites or filtering existing ones. It fires when the form field is being rendered.


Usage

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

Parameters

$option (mixed)
This parameter contains the current value of the 'all_wp_sites' option, which is intended to be modified by the filter.

Return Value

The filtered value.


Examples

/**
 * Filters the list of WordPress sites to be used in Uncanny Automator Pro's
 * Multisite integration. This example shows how to exclude a specific site
 * from the list based on its ID.
 *
 * @param array $option The array of site options, where each element is an array
 *                      representing a site with 'value' and 'label' keys.
 * @return array The modified array of site options.
 */
add_filter( 'uap_option_all_wp_sites', function( $option ) {
	// Define the site ID you want to exclude. Replace with the actual site ID.
	$site_id_to_exclude = 5;

	// Check if the $option is an array and not empty.
	if ( is_array( $option ) && ! empty( $option ) ) {
		// Iterate through the options and remove the site with the specified ID.
		foreach ( $option as $key => $site_data ) {
			// Ensure site_data is an array and has a 'value' key before accessing it.
			if ( is_array( $site_data ) && isset( $site_data['value'] ) ) {
				// Convert the site ID to string for consistent comparison if necessary,
				// though typically site IDs are integers.
				if ( (int) $site_data['value'] === $site_id_to_exclude ) {
					unset( $option[ $key ] );
				}
			}
		}
		// Re-index the array after removing elements to maintain sequential keys.
		$option = array_values( $option );
	}

	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/wpmu/helpers/wpmu-pro-helpers.php:52

public function get_site_ids( $label = null, $option_code = 'WPMUSITEID' ) {

		if ( ! $label ) {
			$label = esc_attr__( 'Subsite', 'uncanny-automator-pro' );
		}
		$options = array();
		$sites   = get_sites( array( 'number' => 9999 ) );
		if ( $sites ) {
			/** @var WP_Site $site */
			foreach ( $sites as $site ) {
				$options[ $site->blog_id ] = sprintf( '%s - %s', $site->blogname, $site->domain );
			}
		}

		$option = array(
			'option_code'           => $option_code,
			'label'                 => $label,
			'input_type'            => 'select',
			'required'              => true,
			'options'               => $options,
			'relevant_tokens'       => array(),
			'supports_custom_value' => true,
		);

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

Scroll to Top