-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunthings-current-year-shortcode.php
66 lines (60 loc) · 1.82 KB
/
runthings-current-year-shortcode.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/*
Plugin Name: Current Year Shortcode
Plugin URI: https://runthings.dev
Description: Add a shortcode for displaying the current year as a range, usage: [year from="2024"]
Version: 1.3.0
Author: Matthew Harris, runthings.dev
Author URI: https://runthings.dev/
License: GPLv3 or later
License URI: http://www.gnu.org/licenses/gpl-3.0.html
Copyright 2022-2024 Matthew Harris
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
if (!defined('WPINC')) {
die;
}
/**
* Shortcode to display current year in a copyright statement.
*
* Set "from" to apply a range, after "from" year has passed.
*
* @example
* // assuming current year is 2024
* [year] = 2024
* @example
* // assuming current year is 2024
* [year from="2024"] = 2024
* @example
* // assuming current year is 2024
* [year from="1983"] = 1983-2024
*
* @return {string} the current year or year range specified
*/
function rtp_copyright_year($atts)
{
$atts = shortcode_atts(
array(
'from' => null,
),
$atts,
'year'
);
$year = date('Y');
$from = $atts['from'];
if ($from != null && $from < $year) {
return "$from-$year";
}
return $year;
}
add_shortcode('year', 'rtp_copyright_year');
// END shortcode to add current year feature