Repository navigation
Actions and Filters
This plugin includes the following action and filter hooks, which developers can utilize in a theme or other plugin to override specific markup or functionality.
ucf_document_label_defaultsucf_document_labelsucf_document_taxonomiesucf_document_argsucf_document_fieldsucf_document_append_post_meta
Filters the default labels used to build the specific labels used when registering the document custom post type.
-
$defaults{array}
The $defaults array holds the default label pieces which includes the following values:
-
$defaults['singular']: The singular name of the post type. Default: 'Document' -
$defaults['plural']: The plural name of the post type. Default: 'Documents' -
$defaults['text_domain']: The text domain used for translation functions. Default:ucf_document.
Adjusting these values can effect a large number of arrays. For example, if the plural value was updated to "Files", the search_items label would be updated to "Search Files" and the filter_items_list label would be updated to "Filter files list".
Note: An array containing all 3 indexes originally passed in must always be returned.
function update_document_label_defaults( $defaults ) {
$defaults['plural'] = 'Files';
return $defaults;
}
add_filter( 'ucf_document_label_defaults', 'update_document_label_defaults', 10, 1 );
This filter allows for specific labels to be overridden, instead of overriding the templating scheme as is done in the above filter. For example, the specific label search_items could be updated to any value.
-
$labels{array} The array of labels.
This will include all the labels in this list. To override a specific label, just update the specific index:
function update_document_labels( $labels ) {
$labels['not_found'] = 'The Document was not found.';
return $labels;
}
add_filter( 'ucf_document_labels', 'update_document_labels' , 10, 1 );
Note: An array with the original indexes must always be returned.
This filter controls which registered taxonomies will be assigned to the document custom post type.
-
$taxonomies{array} The array of taxonomies.
For example, post categories could be added using the following:
function update_document_taxonomies( $taxonomies ) {
$taxonomies[] = 'category';
return $taxonomies;
}
add_filter( 'ucf_document_taxonomies', 'update_document_taxonomies', 10, 1 );
Note: An array must always be returned by this filter. The array can be empty.
Allows for the modification of any of the args passed into the register_post_type function.
-
$args{array} The array of arguments.
For more information on the arguments that can be overridden, see the $args parameter in the register_post_type documentation.
For example, to move the menu position of documents higher in the sidebar menu in wp-admin, you could to the following:
function update_document_args( $args ) {
$args['menu_position'] = 4;
return $args;
}
add_filter( 'ucf_document_args', 'update_document_args', 10, 1 );
Note: This function must always return the original array to avoid creating problems with the post type registering.
Allows for the modification of the ACF fields included by default with this plugin.
-
$fields{array} The array of ACF Field values
For example, to add a usage description field for documents, you could do the following:
function updated_document_fields( $fields ) {
$fields[] = array(
'key' => 'document_usage_description',
'label' => 'Usage Description',
'name => 'document_usage_description',
'type' => 'textarea',
'required' => 0,
'instructions' => 'Describe the allowed usage of this document.'
);
return $fields;
}
add_filter( 'ucf_document_fields', 'update_document_fields', 10, 1 );
For more information on registering ACF fields, see how to Register fields via PHP on the ACF website.
Note: The original $fields array must be returned by the function to keep the included fields.
This plugin automatically appends the meta data for each document onto the $post object when the object is queried. Additional meta fields can be added using this hook.
-
$meta{array} The array of meta added by default -
$post_id{int} The ID of the post
For example, to add the document_usage_description field we added above to the meta array, we could add the following:
function update_append_post_meta( $meta, $post_id ) {
$meta['usage_description'] = get_field( 'document_usage_description', $post_id );
return $meta;
}
add_filter( 'ucf_document_append_post_meta', 'update_append_post_meta', 10, 2 );
Note: The original $meta array must always be returned in order to have access to the default meta that is attached.
Much like the ucf_document_label_defaults hook above, this hook allows for the template parts that are used to generate the directory taxonomy labels to be modified.
-
$labels{array} The labels array to be modified.