As of v2.3.1 it is possible to filter the global data available to overview cards. This means there is an easy way to add dynamic data to be used in your custom overview cards.

Prerequisites

Adding a custom card to the overview page

add_filter("uip_filter_data_object", 'my_custom_data_filter', 1, 2);

The above will fire when the overview page loads and every time the data range is changed.

A function used with this will receive two variables:

$dataObject - This is the main data object that contains all of the data required for the overview cards. It is also the object that we will be pushing data to.

$dateObject - This contains the current dates of the overview page as an object. The four keys included are 'endDate', 'startDate', 'endDate_comparison' and 'startDate_comparison'.

In the below example we will return the current PHP version to the object.

function my_custom_data_filter($dataObject, $dateObject) {

///CHECK THE OBJECT IS AN ARRAY
if (!is_array($dataObject)) {
$dataObject = [];
}

$dataObject["phpVersion"] = phpversion();

return $dataObject;
}

Now every card on the overview page will receive the PHP version in the dataObject. Accessing this data in the card using javascript would look like this:

this.overviewData.globalDataObject.data.phpVersion;

Did this answer your question?