Skip to content
Docs
Get RestroPress

Filter

rpress_stats_predefined_dates

Updated
On this page

Filters the predefined date periods accepted by the stats classes.

Returned by RPRESS_Stats::get_predefined_dates() and consulted whenever a date is converted, including by classes that extend RPRESS_Stats. Keys are slugs such as today, this_week, last_month and this_year, and values are labels. Adding a key adds a recognised period name, but convert_date() only knows how to compute the built-in slugs.

Parameters#

ParameterTypeDescription
$predefinedarrayPeriod slugs mapped to labels.

Return value#

array. The predefined periods.

Example#

function my_stats_predefined_dates( $predefined ) {
	// Relabel an existing period.
	$predefined['this_week'] = __( 'Current week', 'my-textdomain' );
	return $predefined;
}
add_filter( 'rpress_stats_predefined_dates', 'my_stats_predefined_dates' );

Notes#

A new slug passes the recognition check but matches no case in the date calculation, so it resolves to the start of the current month instead of a custom range.

Source#

Applied in:

  • includes/class-rpress-stats.php (line 80), in RPRESS_Stats::get_predefined_dates()

See also#

Was this page helpful?