ult_before_directory_actions
Fires before the directory actions are displayed, allowing modification of modules.
add_action( 'ult_before_directory_actions', $callback, 10, 1 );
Description
Fires before the directory actions section in the admin modules template. Developers can use this hook to add custom content or modify the layout before the default actions are rendered. The `$modules` parameter provides access to module data.
Usage
add_action( 'ult_before_directory_actions', 'your_function_name', 10, 1 );
Parameters
-
$modules(mixed) - This parameter contains an array of module data that will be displayed in the directory.
Examples
/**
* Example function to demonstrate the 'ult_before_directory_actions' hook.
* This function might modify or add to the $modules array before it's used
* to render the directory actions. For instance, it could add a custom module
* or conditionally remove an existing one.
*
* @param array $modules An array of module definitions for the directory.
*/
function my_custom_ult_directory_modules( $modules ) {
// Check if a specific module exists and perhaps add a new one
if ( isset( $modules['some_existing_module'] ) ) {
// Add a new custom module definition
$modules['my_custom_module'] = array(
'name' => __( 'My Custom Action', 'your-text-domain' ),
'description' => __( 'This is a custom action added via a hook.', 'your-text-domain' ),
'callback' => 'my_render_custom_module_action', // A function that renders the module's HTML
'icon' => 'dashicons-admin-tools',
);
// You could also modify an existing module, e.g., change its label
// $modules['some_existing_module']['name'] = __( 'Enhanced Existing Module', 'your-text-domain' );
}
// For demonstration purposes, let's ensure $modules is always an array,
// though the hook's type is action, so a return is not strictly required
// by the hook mechanism itself, but it's good practice if your function
// might modify the passed variable that's expected to be used later.
return $modules;
}
// Register the function to the 'ult_before_directory_actions' hook.
// We pass 1 because the function modifies the $modules variable, and we want
// to ensure the function receives the array with the correct argument count.
// The priority (10) is the default, meaning it runs with other default actions.
add_action( 'ult_before_directory_actions', 'my_custom_ult_directory_modules', 10, 1 );
/**
* Example callback function to render the HTML for the custom module.
* This function would be defined elsewhere in your plugin/theme.
*/
function my_render_custom_module_action() {
?>
<div class="ult-directory-filter">
<a href="#" class="button button-primary"><?php esc_html_e( 'Perform Custom Action', 'your-text-domain' ); ?></a>
</div>
<?php
}
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/templates/admin-modules.php:107
<div class="container">
<div class="ult">
<div class="ult-directory">
<?php do_action( 'ult_before_directory_actions', $modules ); ?>
<div class="ult-directory-actions uncannyowl-bg-lighter">
<div class="ult-directory-filters">
<div class="ult-directory-filter ult-directory-filter--version">
<div class="ult-form-element">
<div class="ult-form-element__field">