Filter uncanny-automator-pro

uap_option_wp_post_statuses

Filters the list of available WordPress post statuses for use within the UAP plugin.

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

Description

Filters the available WordPress post status options used within Uncanny Automator Pro recipes. Developers can modify this array to add, remove, or alter post statuses that users can select for triggers or actions, such as publishing, drafting, or setting custom statuses.


Usage

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

Parameters

$option (mixed)
This parameter holds the current value of the post status option being filtered, which can be any data type depending on the context.

Return Value

The filtered value.


Examples

<?php
/**
 * Filters the available WordPress post statuses for Uncanny Automator.
 *
 * This example demonstrates how to add a custom post status to the list
 * of available statuses that can be used in Uncanny Automator recipes.
 *
 * @param array $option The array of available post status options.
 * @return array The modified array of post status options.
 */
add_filter( 'uap_option_wp_post_statuses', 'my_custom_wp_post_statuses', 10, 1 );

function my_custom_wp_post_statuses( $option ) {
	// First, get all registered post statuses from WordPress.
	$registered_statuses = get_post_statuses();

	// Prepare a new array for our custom statuses.
	$custom_statuses = array();

	// Iterate through the registered statuses and format them for Uncanny Automator.
	foreach ( $registered_statuses as $slug => $name ) {
		// You can add conditions here to only include specific statuses if needed.
		// For this example, we'll include all.
		$custom_statuses[ $slug ] = $name;
	}

	// Merge our custom statuses with the existing ones.
	// This will ensure any default statuses provided by Uncanny Automator are preserved.
	$merged_statuses = array_merge( $option, $custom_statuses );

	// You could also replace existing options if you wanted to.
	// For example, to remove 'draft':
	// unset($merged_statuses['draft']);

	return $merged_statuses;
}

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/wp/helpers/wp-pro-helpers.php:599

public function wp_post_statuses( $label = null, $option_code = 'WPPOSTSTATUSES', $args = array() ) {

		if ( ! $label ) {
			$label = __( 'Status', 'uncanny-automator-pro' );
		}

		$is_any          = key_exists( 'is_any', $args ) ? $args['is_any'] : false;
		$any_label       = key_exists( 'any_label', $args ) ? $args['any_label'] : __( 'Any status', 'uncanny-autoamtor-pro' );
		$relevant_tokens = key_exists( 'relevant_tokens', $args ) ? $args['relevant_tokens'] : array();
		$options         = array();

		if ( $is_any ) {
			$options['-1'] = $any_label;
		}

		if ( empty( $relevant_tokens ) ) {
			$include_relevant = key_exists( 'include_relevant_tokens', $args ) ? (bool) $args['include_relevant_tokens'] : true;
			if ( $include_relevant ) {
				$relevant_tokens = array(
					$option_code => __( 'Status', 'uncanny-automator-pro' ),
				);
			}
		}

		$post_statuses = get_post_stati( array(), 'objects' );

		if ( ! empty( $post_statuses ) ) {
			foreach ( $post_statuses as $name => $status ) {
				$options[ $name ] = esc_html( $status->label );
			}
		}

		if ( class_exists( 'EF_Custom_Status' ) ) {
			$ef_Custom_Status = $this->register_edit_flow_status();
			if ( ! empty( $ef_Custom_Status ) ) {
				foreach ( $ef_Custom_Status as $ef_status ) {
					$options[ $ef_status->slug ] = esc_html( $ef_status->name );
				}
			}
		}

		$type = 'select';

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

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

Scroll to Top