Filter
uncanny-automator
uap_option_all_post_types
Filters the array of all available post types that can be selected for specific options.
add_filter( 'uap_option_all_post_types', $callback, 10, 4 );
Description
Filters the list of all available WordPress post types. Use this hook to modify the returned array of post types, for example, to exclude specific types or add custom ones, before they are used in plugin options or other integrations. The hook passes the post types array, the option code, and any arguments.
Usage
add_filter( 'uap_option_all_post_types', 'your_function_name', 10, 4 );
Parameters
-
$post_types(mixed) - This parameter contains an array of all available post types, which can be filtered or modified by the hook.
-
$option_code(mixed) - This parameter contains an array of all registered post types in WordPress.
-
$args(mixed) - This parameter represents a unique code used to identify the specific option being generated for post types.
-
$this(mixed) - This parameter is used to pass an array of arguments that can modify how post types are retrieved and filtered.
Return Value
The filtered value.
Examples
/**
* Filter the uap_option_all_post_types to exclude 'attachment' post type.
*
* This function hooks into the 'uap_option_all_post_types' filter to modify the
* list of available post types returned by the Ultimate Affiliate Program (UAP) plugin.
* It specifically removes the 'attachment' post type from the list, as it's
* generally not relevant for affiliate program settings.
*
* @param array $post_types The original array of post types.
* @param string $option_code The option code for the post types.
* @param array $args Additional arguments passed to the filter.
* @param object $plugin_instance The instance of the UAP plugin.
*
* @return array The modified array of post types, with 'attachment' removed.
*/
add_filter( 'uap_option_all_post_types', function ( $post_types, $option_code, $args, $plugin_instance ) {
// Check if the post_types is an array and if 'attachment' exists.
if ( is_array( $post_types ) && isset( $post_types['attachment'] ) ) {
// Unset the 'attachment' post type.
unset( $post_types['attachment'] );
}
// Return the modified post types array.
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:308
public function all_post_types( $label = null, $option_code = 'WPPOSTTYPES', $args = array() ) {
$apply_relevant_tokens = false;
$post_types = $this->get_post_types_options( $label, $option_code, $args, $apply_relevant_tokens );
return apply_filters( 'uap_option_all_post_types', $post_types, $option_code, $args, $this );
}