Filter uncanny-automator

uap_option_ad_statuses

Filters the available ad statuses for display, allowing customization before they are shown.

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

Description

Filters the available ad statuses for the AdRotate widget. Developers can modify the `$option` array to add, remove, or alter ad status options. This filter fires when the AdRotate widget is initialized. Ensure the modified options are valid for AdRotate to avoid unexpected behavior.


Usage

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

Parameters

$option (mixed)
This parameter contains the current option code being processed by the filter.

Return Value

The filtered value.


Examples

<?php
/**
 * Example of how to filter the available ad statuses for the UAP integration.
 * This example adds a custom ad status to the list.
 */
add_filter( 'uap_option_ad_statuses', function( $option ) {
	// Assume $option is an array of existing ad statuses, likely with keys and labels.
	// For demonstration, let's simulate an existing $statuses array that might be inside $option.
	// In a real scenario, you would inspect the structure of $option to ensure correct modification.

	// Let's assume $option contains an 'options' key which holds the actual statuses array.
	if ( isset( $option['options'] ) && is_array( $option['options'] ) ) {
		// Add a new custom ad status.
		// The key is the internal identifier, and the value is the user-facing label.
		$option['options']['custom_pending'] = __( 'Custom Pending Review', 'your-text-domain' );

		// You could also reorder or remove existing statuses if needed.
		// For example, to remove a status:
		// unset( $option['options']['draft'] );
	}

	// It's important to always return the modified (or unmodified) $option.
	return $option;
}, 10, 1 ); // 10 is the default priority, 1 is the number of arguments the callback accepts.
?>

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/advanced-ads/helpers/advanced-ads-helpers.php:97

public function ad_statuses( $option_code, $is_any = false, $label = null, $tokens = array() ) {
		$expiry_key = defined( 'Advanced_Ads_Ad_Expiration::POST_STATUS' ) ? Advanced_Ads_Ad_Expiration::POST_STATUS : 'advanced_ads_expired';

		$statuses = array(
			'draft'     => esc_html__( 'Draft', 'uncanny-automator' ),
			'pending'   => esc_html__( 'Pending Review', 'uncanny-automator' ),
			'publish'   => esc_html__( 'Publish', 'uncanny-automator' ),
			$expiry_key => esc_html__( 'Expired', 'uncanny-automator' ),
		);

		if ( true === $is_any ) {
			$statuses = array( '-1' => esc_html__( 'Any status', 'uncanny-automator' ) ) + $statuses;
		}

		$option = array(
			'option_code'     => $option_code,
			'label'           => ( empty( $label ) ) ? esc_attr__( 'Status', 'uncanny-automator' ) : $label,
			'input_type'      => 'select',
			'required'        => true,
			'options_show_id' => false,
			'relevant_tokens' => $tokens,
			'options'         => $statuses,
		);

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

Scroll to Top