Filter
uncanny-automator
uap_option_all_wp_post_types
Filters all available WordPress post types before they are listed in plugin options.
add_filter( 'uap_option_all_wp_post_types', $callback, 10, 4 );
Description
Filters the array of available WordPress post types for use in Uncanny Automator. Developers can use this hook to include or exclude specific post types from being selectable in automations, or to modify their labels. The `$post_types` parameter contains the array of post types.
Usage
add_filter( 'uap_option_all_wp_post_types', 'your_function_name', 10, 4 );
Parameters
-
$post_types(mixed) - This parameter contains an array of WordPress post types that are currently registered and available.
-
$option_code(mixed) - This parameter contains an array of registered WordPress post types.
-
$args(mixed) - This parameter represents the unique code used to identify the option for retrieving WordPress post types.
-
$this(mixed) - This parameter is used to pass additional arguments that can modify how the post types are retrieved.
Return Value
The filtered value.
Examples
add_filter(
'uap_option_all_wp_post_types',
function ( $post_types, $option_code, $args, $self ) {
// Example: Remove 'attachment' post type from the list.
if ( isset( $post_types['attachment'] ) ) {
unset( $post_types['attachment'] );
}
// Example: Add a custom label for 'post' if it exists.
if ( isset( $post_types['post'] ) && is_array( $post_types['post'] ) ) {
$post_types['post']['label'] = __( 'Blog Articles', 'your-text-domain' );
}
// Example: Filter by a specific post type slug if $args contains 'filter_by_slug'.
if ( ! empty( $args['filter_by_slug'] ) && is_array( $args['filter_by_slug'] ) ) {
$filtered_post_types = array();
foreach ( $post_types as $slug => $type_data ) {
if ( in_array( $slug, $args['filter_by_slug'], true ) ) {
$filtered_post_types[ $slug ] = $type_data;
}
}
$post_types = $filtered_post_types;
}
return $post_types;
},
10,
4
);
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:661
src/integrations/wp/helpers/wp-helpers.php:762
uncanny-automator-pro/src/integrations/wp/helpers/wp-pro-helpers.php:157
public function all_wp_post_types( $label = null, $option_code = 'WPPOSTTYPES', $args = array() ) {
$apply_relevant_tokens = true;
$post_types = $this->get_post_types_options( $label, $option_code, $args, $apply_relevant_tokens );
return apply_filters( 'uap_option_all_wp_post_types', $post_types, $option_code, $args, $this );
}