Docs / / Hummingbird API Docs

2. Hummingbird API Docs

Written by Anton Vanyukov | Last updated: April 30, 2019
Actions
Advanced Tools – Database Cleanup
/core/modules/class-module-advanced.php
Performance Test – Reporting
/core/modules/class-module-performance.php
Caching – Page Cache
/core/modules/class-module-page-cache.php
REST API
Module status endpoint
Clear cache endpoint

2.1 Action: wphb_delete_db_data

Link to chapter 1

Description

Can be used to run certain actions or configure notifications for database cleanup actions. Will fire after the database cleanup task in Advanced Tools – Database Cleanup.

Usage

add_action( ‘wphb_delete_db_data’, ‘database_cleanup’, 10, 2 );

Parameters

$type
String
Data type that was cleared from the database. Can return following values: all, revisions, drafts, trash, spam, trash_comment, expired_transients, transients.
$items
Integer
Number of items that was cleared from the database for the selected data type.

Example

add_action( ‘wphb_delete_db_data’, ‘database_cleanup’, 10, 2 );
function database_cleanup( $type, $items ) {
echo ”Purged data type: {$type}, cleared out {$items} entries”;
}

2.2 Action: wphb_get_performance_report

Link to chapter 2

Description

Will fire after Hummingbird fetches the latest Performance report.

Usage

add_action( ‘wphb_get_performance_report’, ‘performance_report’ );

Parameters

$report
Object
Report data object. Contains id, time, url, score, score_class, title, response_code, page_stats and rule_result objects from the Page Speed report (see https://developers.google.com/speed/docs/insights/v4/reference/pagespeedapi/runpagespeed for a better description about the report format).

Example

add_action( ‘wphb_get_performance_report’, ‘performance_report’ );
function performance_report( $report ) {
echo ”Received performance report for {$report->url} with a score of {$report->score}”;
}

2.3 Action: wphb_clear_page_cache

Link to chapter 3

Description

Allows to clear the page cache.

Usage

do_action( ‘wphb_clear_page_cache’, $page_id );

Parameters

$page_id
Integer
Optional parameter. ID of the page/post to clear the cache for. If not set, will clear all the cache.

Example

// Clear the cache for post ID = 12
do_action( ‘wphb_clear_page_cache’, 12 );

// Clear all the cache
do_action( ‘wphb_clear_page_cache’ );

2.4 Filter: wp_hummingbird_is_active_module_minify', '__return_false

Link to chapter 4

Description

Disables minification when Hummingbird is active.

Example

For example, if you want to disable minification for a post page with an ID=24, you can add the following to the functions.php file:
if ( is_page( 24 ) ) {
add_filter( 'wp_hummingbird_is_active_module_minify', '__return_false' );
}

2.5 Filter: wphb_page_cache_custom_terms

Link to chapter 5

Description

Allows to clear custom terms on page/post update

Example

For example, this filter can be used to clear product categories in WooCommerce, when a product is updated:
add_filter( 'wphb_page_cache_custom_terms', 'page_cache_custom_terms' );
function page_cache_custom_terms( $terms ) {
$terms[] = 'product_cat';
return $terms;
}

2.6 Endpoint: /status/(?P[\\w-]+)

Link to chapter 6

Description

Allows to fetch the status of Gzip compression and Browser caching modules.

Usage

Query
http://example.com/wp-json/hummingbird/v1/status/gzip

Return
{
“module_active”: true,
“data”: {
“HTML”: true,
“JavaScript”: true,
“CSS”: true
}
}

Query
http://example.com/wp-json/hummingbird/v1/status/caching

Return
{
“module_active”: true,
“data”: {
“javascript”: false,
“css”: false,
“media”: false,
“images”: false
}
}

2.7 Endpoint: /clear_cache/(?P[\\w-]+)

Link to chapter 7

Description

Allow to clear the cache for various Hummingbird modules.

Usage

Query
http://example.com/wp-json/hummingbird/v1/clear_cache/

List of module names:

  • page_cache
  • performance
  • gravatar
  • minify
  • cloudflare