Filter uncanny-automator

uap_option_all_posts

Filters the option value for all posts, allowing modification before it's used.

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

Description

Fires when retrieving all available options for posts. Developers can use this filter to add, remove, or modify options for post-related data within the Uncanny Automator plugin, influencing what data triggers or actions can access.


Usage

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

Return Value

The filtered value.


Examples

/**
 * Example: Add a new option to the 'uap_option_all_posts' filter to include the post's publication date.
 * This hook is likely used by the Uncanny Automator plugin to populate lists of available data
 * points for use in automations.
 *
 * @param array $option The current array of post options.
 * @return array The modified array of post options, including the new publication date option.
 */
add_filter( 'uap_option_all_posts', 'my_custom_add_post_publication_date_option', 10, 1 );

function my_custom_add_post_publication_date_option( $option ) {
	// Ensure the structure is as expected before adding to it.
	// We're assuming the structure is an array of arrays, where the first level keys
	// are categories and the second level keys are option codes.
	if ( is_array( $option ) && isset( $option['posts'] ) && is_array( $option['posts'] ) ) {
		// Add the new option for post publication date.
		// 'POSTPUBDATE' is a made-up code for demonstration.
		// esc_attr_x is used for translatable strings that are safe for attribute contexts.
		$option['posts']['POSTPUBDATE'] = esc_attr_x( 'Post Publication Date', 'WordPress', 'uncanny-automator' );
	}

	// Always return the modified (or original if conditions weren't met) option array.
	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/wp/helpers/wp-helpers.php:201

public function all_posts( $label = null, $option_code = 'WPPOST', $any_option = true ) {

		if ( ! $label ) {
			/* translators: Noun */
			$label = esc_attr_x( 'Post', 'WordPress', 'uncanny-automator' );
		}

		$args = array(
			// phpcs:ignore WordPress.WP.PostsPerPage.posts_per_page_posts_per_page
			'posts_per_page' => apply_filters( 'automator_select_all_posts_limit', 999, 'post' ),
			'orderby'        => 'title',
			'order'          => 'DESC',
			'post_type'      => 'post',
			'post_status'    => 'publish',
		);

		$all_posts = Automator()->helpers->recipe->options->wp_query( $args, $any_option, esc_attr_x( 'Any post', 'WordPress', 'uncanny-automator' ) );

		$option = array(
			'option_code'     => $option_code,
			'label'           => $label,
			'input_type'      => 'select',
			'required'        => true,
			'options'         => $all_posts,
			'relevant_tokens' => array(
				$option_code                         => esc_attr_x( 'Post title', 'WordPress', 'uncanny-automator' ),
				$option_code . '_ID'                 => esc_attr_x( 'Post ID', 'WordPress', 'uncanny-automator' ),
				$option_code . '_URL'                => esc_attr_x( 'Post URL', 'WordPress', 'uncanny-automator' ),
				$option_code . '_POSTNAME'           => esc_attr_x( 'Post slug', 'WordPress', 'uncanny-automator' ),
				$option_code . '_CONTENT'            => esc_attr_x( 'Post content (raw)', 'WordPress', 'uncanny-automator' ),
				$option_code . '_CONTENT_BEAUTIFIED' => esc_attr_x( 'Post content (formatted)', 'WordPress', 'uncanny-automator' ),
				$option_code . '_EXCERPT'            => esc_attr_x( 'Post excerpt', 'WordPress', 'uncanny-automator' ),
				$option_code . '_TYPE'               => esc_attr_x( 'Post type', 'WordPress', 'uncanny-automator' ),
				$option_code . '_THUMB_ID'           => esc_attr_x( 'Post featured image ID', 'WordPress', 'uncanny-automator' ),
				$option_code . '_THUMB_URL'          => esc_attr_x( 'Post featured image URL', 'WordPress', 'uncanny-automator' ),
				'POSTAUTHORFN'                       => esc_attr_x( 'Post author first name', 'WordPress', 'uncanny-automator' ),
				'POSTAUTHORLN'                       => esc_attr_x( 'Post author last name', 'WordPress', 'uncanny-automator' ),
				'POSTAUTHORDN'                       => esc_attr_x( 'Post author display name', 'WordPress', 'uncanny-automator' ),
				'POSTAUTHOREMAIL'                    => esc_attr_x( 'Post author email', 'WordPress', 'uncanny-automator' ),
				'POSTAUTHORURL'                      => esc_attr_x( 'Post author URL', 'WordPress', 'uncanny-automator' ),
			),
		);

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


Scroll to Top