Hooks & Filters (PHP)

Extend Elephanta with PHP filters and actions for modules, Ajax Search, Social Connect, Super Slider and PDF Invoices, with code examples.

Developer 2 min read Updated
On this page

Use these hooks in a child theme's functions.php, a small custom plugin, or an Elephanta PHP snippet.

#Modules and dashboard

Hook Type Use it to
elephanta/modules/catalog filter Add or change dashboard cards, sidebar links and search keywords
elephanta/modules/toggleable filter Change which modules can be switched off
elephanta/modules/available filter Hide a module completely ($available, $id)
elephanta/modules/loaders filter Register your own module loader
elephanta/module_toggled action Run code when a module is switched on or off ($id, $enabled)
elephanta/module_enabled/{id} action Run code the first time a module loads after being enabled
elephanta/modules_booted action All modules have loaded
// Hide the Cursor Control module on this site.
add_filter( 'elephanta/modules/available', function ( $available, $id ) {
    return 'cursor' === $id ? false : $available;
}, 10, 2 );
add_filter( 'elephanta/ajax_search/query_args', function ( array $query_args, array $widget_config ): array {
    $query_args['post_status'] = 'publish';
    return $query_args;
}, 10, 2 );

#Social Connect

Hook Use it to
elephanta/social_connect/platforms Register more platform labels
elephanta/social_connect/fetch_account Supply normalized posts for a custom platform

#Super Slider

Hook Use it to
elephanta/super_slider/data Change a slider's data before it renders

#PDF Invoices

Hook Use it to
elephanta/invoices/block_types Register custom invoice elements
elephanta/invoices/block_html Change the HTML of an element
elephanta/invoices/data Change the order data passed to the invoice
elephanta/invoices/attach Decide whether a PDF is attached to an email
// Never attach invoices to emails for orders under 10.
// Arguments: bool $attach, string $email_id (WooCommerce email ID), mixed $object (usually the WC_Order).
add_filter( 'elephanta/invoices/attach', function ( $attach, $email_id, $object ) {
    if ( $object instanceof WC_Order && (float) $object->get_total() < 10 ) {
        return false;
    }
    return $attach;
}, 10, 3 );
Check arguments

Hook arguments can grow between versions. Use func_get_args() while developing to see exactly what a hook passes.