This looks like a good idea. I’ll do it!
Let me know if you want me to send you the code that I had written. Looking forward to any improvements you make. 🙂
This plugin is perfect! Just what I was looking for.
But I do have what I hope is a simple request. I’ll give you an example.
I want to show my current age in years, so let’s say I was born on June 29, 1991. If I put the magic code for 1991, it’ll say that I’m 21. But it’s April of 2012, and I’m not 21 until June. So it should say 20 and then switch to 21 on my birthday.
I figure maybe your plugin could just look at the format of the date, like this:
[magicdate]1991[/magicdate] = current behavior
[magicdate]1991-06-29[/magicdate] = proper age calculation
Thanks!
I just whipped up a small change to accomplish my previous request. Seems to work great. In magic_dates.php, replace this:
$magic_date = $current_year - $content;
with this:
if (preg_match("/^(\d{4})-(\d{2})-(\d{2})$/", $content, $matches)) {
$yyyy = $matches[1];
$mmdd = $matches[2] . $matches[3];
$current_mmdd = date('md');
$magic_date = $current_year - $yyyy;
if ($current_mmdd < $mmdd) $magic_date--;
} else {
$magic_date = $current_year - $content;
}
So now you can be more specific with the date like this:
[magicdate]1991-06-29[/magicdate]
Though it’s still backward compatible.
I’m excited to see this.. though I get an error when trying to activate the changes:
Plugin could not be activated because it triggered a fatal error.
Parse error: syntax error, unexpected ‘;’, expecting T_PAAMAYIM_NEKUDOTAYIM in /home/oclesson/public_html/missmandy/wp-content/plugins/magic-dates/magic_dates.php on line 14
🙂
midsummermagic1111: are you getting the syntax error after applying my enhancement? If so, I’m not sure what it could be, except maybe a typo or something. All I can say is that it’s working great on my site. Here’s a link to a copy of my plugin file for your reference:
http://www.crevier.us/magic_dates.txt
I changed this filename to “txt” so it’ll display fine in your browser. Maybe you could just download it, rename it, and see if it works.
Here’s a live page where I’m using Magic Dates 4 times on one page. I’m using my new full date syntax 3 times, and just the year once:
http://www.crevier.us/bio/
As you can see, the page says “have been married 24 years; we’ve lived in De Pere for 14 years”. For both of those, I used a specific date. And I’ve tested by changing the dates to various values and it works well.
Sorry I can’t offer any other suggestions.