-
Notifications
You must be signed in to change notification settings - Fork 5
/
shortcode-for-current-date.php
executable file
·141 lines (115 loc) · 3.45 KB
/
shortcode-for-current-date.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
/**
* Plugin Name: Shortcode For Current Date
* Plugin URI: http://wordpress.org/plugins/shortcode-for-current-date
* Description: Insert current Date, Month or Year anywhere with a simple shortcode.
* Version: 2.1.9
* Author: Imtiaz Rayhan
* Author URI: http://dotcamp.com/
* License: GPLv2 or later
* Text Domain: sfcd
* @package sfcd_plugin
* @author Imtiaz Rayhan
*/
// If accessed directly, exit
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'Shortcode_For_Current_Date' ) ) {
/**
* Class Shortcode_For_Current_Date. Contains everything.
*
* @since 1.0
*/
class Shortcode_For_Current_Date {
/**
* Shortcode_For_Current_Date constructor.
* Adds filters to execute shortcodes in necessary places.
*
* @since 1.0
*/
public function __construct() {
add_shortcode( 'current_date', array( $this, 'sfcd_date_shortcode' ) );
}
/**
* Month Shortcode build.
*
* @since 1.0
*/
public function sfcd_date_shortcode( $atts ) {
/**
* Shortcode attributes.
*
* @since 1.0
*/
$atts = shortcode_atts(
array(
'format' => '',
'size' => '',
'color' => ''
), $atts
);
if ( ! empty( $atts['format'] ) ) {
$dateFormat = sanitize_text_field( $atts['format'] );
} else {
$dateFormat = 'jS F Y';
}
/* Changed [return date( $dateFormat );]
* to the following line in order to retrieve
* WP time as opposed to server time.
*
* @author UN_Rick
*/
if ( ! empty( $atts['size'] ) || ! empty( $atts['color'] ) ) {
$size_attr = esc_attr( $atts['size'] );
$color_attr = esc_attr( $atts['color'] );
if ( $dateFormat == 'z' ) {
return "<p class='sfcd-date' style='font-size:" . $size_attr . "; color: " . $color_attr . ";'>" . ( date_i18n( $dateFormat ) + 1 ) . "</p>";
} else {
return "<p class='sfcd-date' style='font-size:" . $size_attr . "; color: " . $color_attr . ";'>" . date_i18n( $dateFormat ) . "</p>";
}
} else {
if ( $dateFormat == 'z' ) {
return date_i18n( $dateFormat ) + 1;
} else {
return date_i18n( $dateFormat );
}
}
}
}
}
/* Block Registration */
function Shortcode_For_Current_Date_Block_Register() {
wp_register_script(
'shortcode-for-current-date-editor-script',
plugins_url( 'dist/editor.js', __FILE__ ),
array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor', 'wp-components', 'wp-date' )
);
wp_register_script(
'shortcode-for-current-date-script',
plugins_url( 'dist/script.js', __FILE__ ),
array()
);
if ( function_exists( 'register_block_type' ) ) {
register_block_type( 'shortcode-for-current-date/block',
array_merge(
array(
'editor_script' => 'shortcode-for-current-date-editor-script',
'script' => 'shortcode-for-current-date-script'
)
)
);
}
}
/* END Block Registration */
new Shortcode_For_Current_Date();
require_once plugin_dir_path( __FILE__ ) . '/includes/sfcd-welcome-page.php';
require_once plugin_dir_path( __FILE__ ) . '/includes/sfcd-menu-page.php';
require_once plugin_dir_path( __FILE__ ) . '/includes/sfcd-admin-notices.php';
SFCD_Welcome_Page::init();
SFCD_Menu_Page::init();
SFCD_Admin_Notices::init();
register_activation_hook( __FILE__, array( 'SFCD_Welcome_Page', 'sfcd_welcome_activate' ) );
register_deactivation_hook( __FILE__, array( 'SFCD_Welcome_Page', 'sfcd_welcome_deactivate' ) );
add_filter( 'the_title', 'do_shortcode' );
add_action( 'init', 'Shortcode_For_Current_Date_Block_Register' );