Filter
uncanny-automator
automator_post_type_trigger_args
Filters post type arguments for Automator triggers to allow modification before they are registered.
add_filter( 'automator_post_type_trigger_args', $callback, 10, 1 );
Description
This filter allows developers to modify the arguments used when registering the custom post type for triggers. It fires before the `register_post_type` function is called, providing full control over post type capabilities, labels, and other registration parameters. Use this to customize trigger post type behavior or add custom capabilities.
Usage
add_filter( 'automator_post_type_trigger_args', 'your_function_name', 10, 1 );
Parameters
-
$args(mixed) - This parameter contains an array of arguments used to register a custom post type for automator triggers, which can be filtered by plugins or themes.
Return Value
The filtered value.
Examples
<?php
/**
* Example of modifying the capabilities for the 'Trigger' post type.
* This example demonstrates how to add or remove specific capabilities
* for users interacting with the 'Trigger' post type registered by the automator plugin.
*/
add_filter( 'automator_post_type_trigger_args', function( $args ) {
// For demonstration purposes, let's assume we want to grant
// 'edit_posts' capability to all users for this specific post type,
// which is more permissive than the default.
// In a real-world scenario, you might check user roles or other conditions.
if ( isset( $args['capabilities'] ) && is_array( $args['capabilities'] ) ) {
// Add a new capability or modify an existing one.
// Here, we'll add 'edit_posts' if it doesn't exist.
if ( ! isset( $args['capabilities']['edit_posts'] ) ) {
$args['capabilities']['edit_posts'] = automator_get_capability(); // Or a custom capability check
}
// Optionally, remove a capability if needed.
// For example, if you wanted to prevent deletion for certain roles.
// unset( $args['capabilities']['delete_post'] );
// You could also override existing ones with custom logic.
// For example:
// $args['capabilities']['edit_post'] = 'my_custom_edit_trigger_cap';
}
// Ensure all arguments are returned
return $args;
}, 10, 1 ); // Priority 10, accepts 1 argument
?>
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/automator-post-types/uo-trigger/class-triggers-post-type.php:84
public function uo_automator_triggers() {
$labels = array(
'name' => 'Automator Triggers',
'singular_name' => 'Automator Trigger',
'menu_name' => 'Triggers',
'name_admin_bar' => 'Post Type',
'archives' => 'Item Archives',
'attributes' => 'Item Attributes',
'parent_item_colon' => 'Parent Item:',
'all_items' => 'All Items',
'add_new_item' => 'Add New Item',
'add_new' => 'Add New',
'new_item' => 'New Item',
'edit_item' => 'Edit Item',
'update_item' => 'Update Item',
'view_item' => 'View Item',
'view_items' => 'View Items',
'search_items' => 'Search Item',
'not_found' => 'Not found',
'not_found_in_trash' => 'Not found in Trash',
'featured_image' => 'Featured Image',
'set_featured_image' => 'Set featured image',
'remove_featured_image' => 'Remove featured image',
'use_featured_image' => 'Use as featured image',
'insert_into_item' => 'Insert into item',
'uploaded_to_this_item' => 'Uploaded to this item',
'items_list' => 'Items list',
'items_list_navigation' => 'Items list navigation',
'filter_items_list' => 'Filter items list',
);
$args = array(
'label' => 'Automator Trigger',
'description' => 'Trigger for an Uncanny WordPress Automation',
'labels' => $labels,
'supports' => array( 'title' ),
'hierarchical' => false,
'public' => false,
'show_ui' => false,
'show_in_menu' => false,
'menu_position' => 5,
'show_in_admin_bar' => false,
'show_in_nav_menus' => false,
'can_export' => false,
'has_archive' => false,
'exclude_from_search' => true,
'publicly_queryable' => false,
'capabilities' => array(
'publish_posts' => automator_get_capability(),
'edit_posts' => automator_get_capability(),
'edit_others_posts' => automator_get_capability(),
'delete_posts' => automator_get_capability(),
'delete_others_posts' => automator_get_capability(),
'read_private_posts' => automator_get_capability(),
'edit_post' => automator_get_capability(),
'delete_post' => automator_get_capability(),
),
);
register_post_type( AUTOMATOR_POST_TYPE_TRIGGER, apply_filters( 'automator_post_type_trigger_args', $args ) );
}