Filter
uncanny-automator
automator_post_type_recipe_args
Filters the arguments used to retrieve post types for recipes, allowing modification before fetching.
add_filter( 'automator_post_type_recipe_args', $callback, 10, 1 );
Description
Filters the arguments used to register the 'recipe' post type. Use this hook to modify capabilities, labels, or other registration settings before the post type is registered. This is essential for customizing how recipes are handled within the Automator system.
Usage
add_filter( 'automator_post_type_recipe_args', 'your_function_name', 10, 1 );
Parameters
-
$args(mixed) - This parameter contains an array of arguments used to register the 'recipe' custom post type.
Return Value
The filtered value.
Examples
<?php
/**
* Example of modifying the arguments for the 'recipe' post type.
*
* This filter allows you to alter the arguments passed to register_post_type for the 'recipe' post type.
* In this example, we'll add a custom capability to the post type arguments.
*
* @param array $args The current arguments for the 'recipe' post type.
* @return array The modified arguments for the 'recipe' post type.
*/
add_filter( 'automator_post_type_recipe_args', function( $args ) {
// Add a custom capability for managing recipes if it doesn't exist.
// This assumes 'automator_get_capability()' returns a valid capability name.
if ( ! isset( $args['capabilities'] ) || ! is_array( $args['capabilities'] ) ) {
$args['capabilities'] = array();
}
// Example: Add 'manage_recipes' capability.
// In a real scenario, you'd likely have a function that generates a capability name.
// For this example, let's assume automator_get_capability() is used for all default ones,
// and we might want to add a more specific one.
$custom_capability = 'manage_specific_recipes'; // Replace with your actual custom capability.
// Ensure automator_get_capability() is defined and accessible, or replace with a placeholder if needed for the example.
// If automator_get_capability() is a global function, you can call it directly.
// For demonstration, let's assume it returns a string like 'edit_posts'.
$capability_to_assign = function_exists('automator_get_capability') ? automator_get_capability() : 'edit_posts';
$args['capabilities']['manage_recipes'] = $capability_to_assign; // Assigning a base capability, or you could use $custom_capability
$args['capabilities']['edit_recipes'] = $capability_to_assign; // Assigning a base capability
$args['capabilities']['delete_recipes'] = $capability_to_assign; // Assigning a base capability
// You could also modify other arguments like 'supports', 'rewrite', 'labels', etc.
// For example, to add excerpt support:
if ( ! in_array( 'excerpt', $args['supports'] ) ) {
$args['supports'][] = 'excerpt';
}
// Return the modified arguments.
return $args;
}, 10, 1 ); // Priority 10, 1 accepted 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-recipe/class-recipe-post-type.php:151
public function automator_post_type() {
if ( ! post_type_exists( AUTOMATOR_POST_TYPE_RECIPE ) ) {
$icon_url = 'data:image/svg+xml;base64,' . base64_encode( '<?xml version="1.0" encoding="UTF-8"?><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><path d="m42.63 28.37c-0.27 2.32-0.27 4.67 0 6.99 0.4 3.44 6.7 3.44 7.27 0 0.37-2.31 0.37-4.65 0-6.96-0.56-3.44-6.9-3.44-7.27-0.03z" fill="#a7aaad"/><path d="m14.04 28.41c-0.37 2.31-0.37 4.65 0 6.96 0.57 3.44 6.88 3.44 7.28 0 0.27-2.32 0.27-4.67 0-6.99-0.37-3.42-6.67-3.42-7.28 0.03z" fill="#a7aaad"/><path d="m37.07 39.61c-3.13 0.82-6.41 0.82-9.54 0 0.29 5.9 9.25 5.9 9.54 0z" fill="#a7aaad"/><path d="m63.5 19.04c-0.34-3.07-2.25-4.75-5.15-5.4-8.67-1.82-17.51-2.69-26.38-2.58-8.84-0.08-17.66 0.78-26.32 2.58-2.96 0.65-4.86 2.33-5.2 5.4-0.39 4-0.53 8.01-0.4 12.02 0.09 4.27 0.61 8.52 1.56 12.69 0.65 2.73 3.6 4.49 6.05 5.52 11.5 4.91 37.1 4.91 48.65 0 2.45-1.04 5.36-2.79 6.05-5.52 0.96-4.16 1.5-8.42 1.6-12.69 0.13-4.01-0.02-8.03-0.46-12.02zm-5.42 23.64c-0.25 0.99-2.75 2.24-3.52 2.53-10.4 4.48-34.86 4.48-45.25 0-0.78-0.32-3.24-1.51-3.52-2.53-1.46-6.05-1.84-15.43-1.01-23.2 0.12-1.19 0.82-1.36 1.73-1.56 5.08-1.18 10.25-1.89 15.46-2.16 0.18-0.01 0.36 0.06 0.5 0.18 0.13 0.12 0.21 0.29 0.24 0.47 0.37 2.86 0.99 5.67 1.84 8.43 0.62 1.23 4.58 1.76 7.42 1.76 2.87 0 6.84-0.53 7.36-1.76 0.85-2.75 1.48-5.57 1.85-8.43 0.02-0.18 0.11-0.35 0.25-0.47 0.13-0.11 0.31-0.18 0.49-0.18 5.2 0.24 10.35 0.96 15.42 2.16 0.94 0.2 1.64 0.37 1.76 1.56 0.82 7.74 0.45 17.11-1.02 23.2z" fill="#a7aaad"/></svg>' );
$labels = array(
'name' => esc_attr__( 'Recipes', 'uncanny-automator' ),
'singular_name' => esc_attr__( 'Recipe', 'uncanny-automator' ),
'menu_name' => 'Automator',
/* translators: 1. Trademarked term */
'name_admin_bar' => sprintf( esc_attr__( '%1$s recipe', 'uncanny-automator' ), 'Automator' ),
'archives' => 'Recipe Archives',
'attributes' => 'Recipe Attributes',
'parent_item_colon' => 'Parent Recipe:',
'all_items' => esc_attr__( 'All recipes', 'uncanny-automator' ),
/* translators: Non-personal infinitive verb */
'add_new_item' => esc_attr__( 'Add new recipe', 'uncanny-automator' ),
/* translators: Non-personal infinitive verb */
'add_new' => esc_attr_x( 'Add New', 'Recipe', 'uncanny-automator' ),
'new_item' => esc_attr__( 'New recipe', 'uncanny-automator' ),
/* translators: Non-personal infinitive verb */
'edit_item' => esc_attr__( 'Edit recipe', 'uncanny-automator' ),
/* translators: Non-personal infinitive verb */
'update_item' => esc_attr__( 'Update recipe', 'uncanny-automator' ),
/* translators: Non-personal infinitive verb */
'view_item' => esc_attr__( 'View recipe', 'uncanny-automator' ),
/* translators: Non-personal infinitive verb */
'view_items' => esc_attr__( 'View recipes', 'uncanny-automator' ),
/* translators: Non-personal infinitive verb */
'search_items' => esc_attr__( 'Search recipes', 'uncanny-automator' ),
'not_found' => esc_attr_x( 'Not found', 'Recipe', 'uncanny-automator' ),
'not_found_in_trash' => esc_attr_x( 'Not found in trash', 'Recipe', 'uncanny-automator' ),
'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 the Recipe',
'uploaded_to_this_item' => 'Uploaded to This Recipe',
'items_list' => 'Recipes List',
'items_list_navigation' => 'Recipes List Navigation',
'filter_items_list' => 'Filter Recipes List',
);
$args = array(
'label' => esc_attr__( 'Recipe', 'uncanny-automator' ),
'description' => 'Uncanny WordPress Automation',
'labels' => $labels,
'supports' => array( 'title', 'author' ),
'hierarchical' => false,
'public' => false,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 40,
'menu_icon' => $icon_url,
'show_in_admin_bar' => true,
'show_in_nav_menus' => false,
'can_export' => true,
'taxonomies' => array( 'recipe_category', 'recipe_tag' ),
'has_archive' => false,
'exclude_from_search' => true,
'publicly_queryable' => true,
'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_RECIPE, apply_filters( 'automator_post_type_recipe_args', $args ) );
}
}