Marko Dimitrijević

Chaising bugs from the future

Chasing bugs from the future

Alright fellow WordPress enthusiasts! Let’s talk about a silent killer in our codebases: the ticking time bomb of unaddressed issues. You might not call it anything fancy, but it’s a fundamental truth in software development: code left unreviewed, untested, or incompletely implemented is a future bug waiting to happen. These aren’t just theoretical gremlins; they manifest as real-world headaches – syntax errors, logic flaws, and unexpected functional breakdowns.

Take this real-world scenario I encountered while wrangling updates on some legacy WordPress products. Digging through the update documentation, I stumbled upon a “feature” to check year ranges in a countdown shortcode. Surprise! It was a known bug because, well, hardcoding years range for a countdown in a plugin used by who knows how many sites is… optimistic at best. 🤦‍♂️

<?php
/* Option for configuring countdown shortcode.
Clearly it won work since we are in 2025, ooops. */
array(
	'type'        => 'dropdown',
	'param_name'  => 'year',
	'heading'     => esc_html__( 'Year', 'text-domain' ),
	'value'       => array(
		'2019' => '2019',
		'2020' => '2020',
		'2021' => '2021',
		'2022' => '2022',
		'2023' => '2023',
		'2024' => '2024'
	),
	'admin_label' => true,
    'save_always' => true
),

How does this even happen? The usual suspects:

  • Copy-paste without thinking: “It worked somewhere else, right?” 🤔
  • Short-sighted “fixes”: Slapping a band-aid on a bigger problem.
  • The “we’ll refactor it later” black hole: Easy to say, even easier to forget.
  • The classic: Code slipped through the cracks – unreviewed. 🙈

The “fix” I found? Simply update the year and maybe add a few more for good measure. A fix, sure, but a leaky one. That bug will rear its ugly head again in a few years, triggering a fresh wave of support requests.

Think about the ripple effect: support teams spending time on a recurring issue, developers pulled away for “minor” fixes, and a constant drain on company time and resources. It’s an endless loop fueled by overlooking seemingly small details.

The takeaway? Don’t underestimate the seemingly insignificant. In our fast-paced world, it’s tough to be meticulous with every line, but as developers, a little proactive thinking can save a mountain of trouble down the line. Sometimes, just not being passive in our work is enough.

The elegant solution in this case? A small helper function to dynamically generate the year range based on the current year, adding a buffer for future-proofing. Simple, effective, and prevents the recurring bug.

<?php
/**
 * Function that return range of years.
 *
 * @param $range int number of years to add before and after current year
 * @return array of range of years
 */
function get_countdown_years_range( $range = 6 ) {
	$current_year = date( 'Y' );

	$years_array = array(
		$current_year => $current_year
	);

	// prepend years.
	for ($i = 1; $i <= $range; $i++) {
		array_unshift( $years_array , $current_year - $i );
	}

	// append years.
	for ($i = 1; $i <= $range; $i++) {
		array_push( $years_array , $current_year + $i );
	}

	return $years_array;
}

And then simply call that function:

<?php
array(
	'type'        => 'dropdown',
	'param_name'  => 'year',
	'heading'     => esc_html__( 'Year', 'text-domain' ),
	'value'       => get_countdown_years_range(),
	'admin_label' => true,
    'save_always' => true
),

What are some “future bugs” you’ve encountered in legacy WordPress code?

Leave a Reply

Your email address will not be published. Required fields are marked *