Filter uncanny-automator

automator_post_type_action_args

Filters the arguments used when performing a post type action, allowing modification before execution.

add_filter( 'automator_post_type_action_args', $callback, 10, 1 );

Description

Filters the arguments used when registering the 'uo-action' custom post type. Developers can modify capabilities, labels, and other registration parameters to customize how actions are handled within the plugin. This hook fires before the `register_post_type` function.


Usage

add_filter( 'automator_post_type_action_args', 'your_function_name', 10, 1 );

Return Value

The filtered value.


Examples

<?php
/**
 * Example of modifying the capabilities for the 'automator_post_type_action_args' filter.
 *
 * This example demonstrates how to add or modify the capabilities associated with the
 * custom post type registered by the Automator plugin. In this specific case,
 * we're ensuring that a custom role, 'automator_manager', has full editing and deletion
 * capabilities for these action posts, in addition to the default capabilities.
 */
add_filter( 'automator_post_type_action_args', 'my_custom_automator_action_capabilities', 10, 1 );

function my_custom_automator_action_capabilities( $args ) {
	// Check if the $args is an array and contains the 'capabilities' key.
	if ( is_array( $args ) && isset( $args['capabilities'] ) && is_array( $args['capabilities'] ) ) {

		// Assign a specific capability to a custom role, for example.
		// In a real-world scenario, you might check for current user roles or specific conditions.
		// For demonstration, we're just directly adding 'automator_manager' role capabilities.
		$args['capabilities']['edit_others_posts'] = 'automator_manager';
		$args['capabilities']['delete_others_posts'] = 'automator_manager';
		$args['capabilities']['read_private_posts']  = 'automator_manager';
		$args['capabilities']['edit_post']           = 'automator_manager';
		$args['capabilities']['delete_post']         = 'automator_manager';

		// You could also add new capabilities or modify existing ones based on logic.
		// For instance, if you wanted to disable deletion for certain users:
		// unset( $args['capabilities']['delete_post'] );
	}

	// Always return the modified (or original) arguments.
	return $args;
}

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-action/class-actions-post-type.php:86

public function uo_automator_actions() {

		$labels = array(
			'name'                  => 'Automator Actions',
			'singular_name'         => 'Automator Action',
			'menu_name'             => 'Actions',
			'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 Action',
			'description'         => 'Action 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_ACTION, apply_filters( 'automator_post_type_action_args', $args ) );
	}

Scroll to Top