Filter
uncanny-automator
automator_post_options
Filter the final options array. Filters the final options array before it is used, allowing modification based on parsed parameters.
add_filter( 'automator_post_options', $callback, 10, 2 );
Description
Filters the array of value/text pairs for post options before they are returned. Developers can use this to modify, add, or remove available post selections in the Automator plugin's core functionalities. The `$params` array provides context about how the options were generated.
Usage
add_filter( 'automator_post_options', 'your_function_name', 10, 2 );
Parameters
-
$options(array) - Value/text pairs.
-
$params(array) - Parsed parameters.
Return Value
The filtered value.
Examples
// Add a custom option to the automator post options if the post type is 'post'
add_filter( 'automator_post_options', function( $options, $params ) {
// Check if the current post type being processed is a standard 'post'
if ( isset( $params['post_type'] ) && 'post' === $params['post_type'] ) {
// Add a new option for selecting the author of the post
$options[] = array(
'value' => 'post_author',
'text' => __( 'Post Author', 'your-text-domain' ),
);
}
return $options;
}, 10, 2 );
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/core/classes/class-automator-wp-query.php:64
public function post_options( array $params = array(), string $format = 'modern' ) {
$this->deprecate_removed_filters();
$params = $this->parse_params( $params );
$args = $this->build_query_args( $params );
$posts = $this->fetch_posts( $args );
$options = $this->format_options( $posts );
$options = $this->prepend_sentinels( $options, $params );
/**
* Filter the final options array.
*
* @param array $options Value/text pairs.
* @param array $params Parsed parameters.
*/
$options = apply_filters( 'automator_post_options', $options, $params );
if ( 'legacy' === $format ) {
return array_column( $options, 'text', 'value' );
}
return $options;
}