-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunbox-copyright.php
66 lines (58 loc) · 2.15 KB
/
unbox-copyright.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: Unbox Copyright
* Description: WordPress Block that sets up a copyright line with auto updating year and site name pulled from Settings -> General
* Requires at least: 5.9
* Requires PHP: 7.0
* Version: 1.3.4
* Author: Bridget Wessel
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: unbox
* GitHub Plugin URI: bridgetwes/unbox-copyright
* GitHub Branch: main
*
* @package create-block
*/
// Exit if accessed directly
if (!defined('ABSPATH')) {
exit;
}
require_once plugin_dir_path( __FILE__ ) . 'plugin-update-checker.php';
/**
* Renders the `unbox-copyright` on the server.
*
* @link https://developer.wordpress.org/reference/functions/current_datetime/
* @param array $attributes Block attributes.
* @param string $content Block default content.
* @param WP_Block $block Block instance.
* @return string Returns the content replacing [current year] and [site title] wrapped in a <p> tag.
*/
if ( ! function_exists( 'unbox_copyright_render_block_dynamic_year_block' ) ) {
function unbox_copyright_render_block_dynamic_year_block( $block_attributes, $content, $block ) {
//Replace what is saved in the page with the current year.
// Get the current year.
$current_date = current_datetime();
$dynamic_year = $current_date->format('Y');
$sitename = get_bloginfo('name');
$output = str_replace("[current year]", $dynamic_year, $content);
$output = str_replace("[site title]", $sitename, $output);
return $output;
}
}
/**
* Registers the block using the metadata loaded from the `block.json` file.
* Behind the scenes, it registers also all assets so they can be enqueued
* through the block editor in the corresponding context.
*
* @see https://developer.wordpress.org/reference/functions/register_block_type/
*/
function create_block_unbox_copyright_block_init() {
register_block_type(
__DIR__ . '/build',
array(
'render_callback' => 'unbox_copyright_render_block_dynamic_year_block',
)
);
}
add_action( 'init', 'create_block_unbox_copyright_block_init' );