Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions classes/badges/class-monthly.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,19 @@ public static function get_instance_from_id( $badge_id ) {
/**
* Get an array of months.
*
* Year-specific names are supported. If no names are defined for the
* given year, the default (2025) names are returned as a fallback.
*
* @param int|null $year The year. Null returns the default names.
*
* @return array
*/
public static function get_months() {
public static function get_months( $year = null ) {
/*
* Indexed months, The array keys are prefixed with an "m"
* so that they are strings and not integers.
*/
$months = [
$default = [
'm1' => 'Jack January',
'm2' => 'Felix February',
'm3' => 'Mary March',
Expand All @@ -169,7 +174,29 @@ public static function get_months() {
'm11' => 'Noah November',
'm12' => 'Daisy December',
];
return $months;

$yearly = [
2026 => [
'm1' => 'Jamie January',
'm2' => 'Freya February',
'm3' => 'Milo March',
'm4' => 'Aida April',
'm5' => 'Maeve May',
'm6' => 'Jason June',
'm7' => 'Julia July',
'm8' => 'Ava August',
'm9' => 'Sophie September',
'm10' => 'Omar October',
'm11' => 'Nathan November',
'm12' => 'Daniel December',
],
];

if ( null !== $year && isset( $yearly[ $year ] ) ) {
return $yearly[ $year ];
}

return $default;
}

/**
Expand All @@ -179,7 +206,7 @@ public static function get_months() {
*/
public function get_name() {
return $this->id
? self::get_months()[ 'm' . $this->get_month() ]
? self::get_months( (int) $this->get_year() )[ 'm' . $this->get_month() ]
: '';
}

Expand Down Expand Up @@ -229,8 +256,8 @@ public function progress_callback( $args = [] ) {
return $saved_progress;
}

$month = self::get_months()[ 'm' . $this->get_month() ];
$year = $this->get_year();
$month = self::get_months( (int) $year )[ 'm' . $this->get_month() ];
$month_num = (int) $this->get_month();

$start_date = \DateTime::createFromFormat( 'Y-m-d', "{$year}-{$month_num}-01" );
Expand Down
Loading