Filter uncanny-automator

automator_all_wp_post_types_defaults

Filters default settings for all WordPress post types, allowing customization before they are processed.

add_filter( 'automator_all_wp_post_types_defaults', $callback, 10, 4 );

Description

Filters the default post type options used in Uncanny Automator. Developers can modify or add to these defaults before they are used to populate dropdowns or other input fields for post type selections, allowing for custom post type integrations.


Usage

add_filter( 'automator_all_wp_post_types_defaults', 'your_function_name', 10, 4 );

Parameters

$defaults (mixed)
This parameter is a mixed array containing default option codes and their corresponding user-friendly names for various WordPress post types.
$option_code (mixed)
This parameter contains the default values for the dynamic data options related to WordPress post types.
$args (mixed)
This parameter represents a unique code that identifies the specific option being generated, often used to construct unique keys for storing or referencing data.
$this (mixed)
This parameter is an array of arguments passed to the function, which can include configuration options or specific filters.

Return Value

The filtered value.


Examples

<?php
/**
 * Example of how to use the automator_all_wp_post_types_defaults filter.
 * This example adds a new default option to trigger when any post type is selected.
 *
 * @param array $defaults The default options array.
 * @param string $option_code The option code for the current post type.
 * @param array $args The arguments passed to the filter.
 * @param object $this The current instance of the Uncanny Automator WP Helper class.
 * @return array The modified defaults array.
 */
add_filter(
	'automator_all_wp_post_types_defaults',
	function ( $defaults, $option_code, $args, $this_instance ) {
		// Add a new default option for 'Any Post' if not already present.
		if ( ! isset( $defaults[ $option_code . '_ANY' ] ) ) {
			$defaults[ $option_code . '_ANY' ] = esc_html_x( 'Any post', 'WordPress', 'uncanny-automator' );
		}

		// Optionally, you could also modify existing defaults or add conditional logic.
		// For instance, if you wanted to ensure 'Any Post' is always an option regardless of the $args.
		// $defaults[ $option_code . '_ANY' ] = esc_html_x( 'Any post (Custom Label)', 'WordPress', 'uncanny-automator' );

		return $defaults;
	},
	10, // Priority
	4  // Accepted arguments
);
?>

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:704
uncanny-automator-pro/src/integrations/wp/helpers/wp-pro-helpers.php:103

$option_code . '_POSTNAME'  => esc_html_x( 'Post slug', 'WordPress', 'uncanny-automator' ),
				$option_code . '_THUMB_ID'  => esc_html_x( 'Post featured image ID', 'WordPress', 'uncanny-automator' ),
				$option_code . '_THUMB_URL' => esc_html_x( 'Post featured image URL', 'WordPress', 'uncanny-automator' ),
			);

		}

		$args = wp_parse_args( $args, apply_filters( 'automator_all_wp_post_types_defaults', $defaults, $option_code, $args, $this ) );

		$options = array();

		if ( true === $args['is_any'] ) {

			$zero_as_default = ( intval( '-1' ) !== intval( $args['use_zero_as_default'] ) ) ? 0 : intval( '-1' );

Scroll to Top