Hook & Filter Registry
Hook & Filter Registry
This repository introduces a series of custom WordPress hooks and filters designed to allow developers to extend and modify the core functionality of the MVP framework without altering the source code.
Filters
Filters allow you to intercept and modify data before it is processed or rendered by the system.
ua_wp_modify_api_response
Modifies the data structure returned by custom REST API endpoints defined in this package.
- Input:
array $data- The original response data. - Output:
array- The modified response data.
add_filter('ua_wp_modify_api_response', function($data) {
// Add custom metadata to the API output
$data['timestamp'] = time();
return $data;
});
ua_wp_post_type_args
Adjusts the registration arguments for the custom post types (CPTs) introduced in this repository.
- Input:
array $args,string $post_type - Output:
array- The filtered registration arguments.
add_filter('ua_wp_post_type_args', function($args, $post_type) {
if ($post_type === 'ua_contribution') {
$args['show_in_rest'] = true;
}
return $args;
}, 10, 2);
ua_wp_template_path
Overrides the default directory used to locate component templates.
- Input:
string $path- The absolute path to the template directory. - Output:
string- The new path to the template directory.
add_filter('ua_wp_template_path', function($path) {
return get_stylesheet_directory() . '/custom-templates/';
});
Actions
Actions allow you to trigger custom code at specific execution points within the lifecycle of the components.
ua_wp_before_contribution_render
Fires immediately before the contribution list component is rendered to the DOM. Useful for injecting analytics or loading specific assets.
- Parameters:
int $user_id- The ID of the current contributor.
add_action('ua_wp_before_contribution_render', function($user_id) {
// Log view or enqueue specific styles
wp_enqueue_style('ua-contribution-overrides');
});
ua_wp_on_submission_success
Fires after a successful data submission via the internal forms handler.
- Parameters:
array $form_data,int $entry_id
add_action('ua_wp_on_submission_success', function($form_data, $entry_id) {
// Trigger third-party webhook or notification
Remote_API::notify('New submission: ' . $entry_id);
}, 10, 2);
ua_wp_init_module (Internal)
Internal Use Only. This action is triggered when the core module initializes. While public, it is intended for internal service registration. Modifying this may lead to instability if dependencies are not resolved.
Implementation Guidelines
- Priority: When using filters that modify data structures (like
ua_wp_modify_api_response), always return the variable even if no changes are made to prevent breaking the execution chain. - Naming Conventions: All custom hooks are prefixed with
ua_wp_to prevent collisions with WordPress Core or other third-party plugins. - Type Safety: Ensure that your callback functions strictly adhere to the input types documented above to maintain system stability.