This repository has been archived by the owner on Mar 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatetime-now-button.php
70 lines (63 loc) · 2.43 KB
/
datetime-now-button.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
<?php
/*
Author: radiok
Plugin Name: Date/Time Now Button
Author URI: http://radiok.info/
Plugin URI: http://radiok.info/blog/category/datetime-now-button/
Description: Adds a Now button to the right of date and time fields.
Version: 0.2.2
Text Domain: datetime-now-button
Domain Path: /languages
*/
if ( !class_exists( 'DateTimeNowButtonPlugin' ) ) {
class DateTimeNowButtonPlugin {
function __construct() {
add_action( 'init', array( $this, 'InitI18n' ), 10, 1 );
add_action( 'admin_head', array($this, 'AddNowButton' ), 10, 1 );
}
function InitI18n() {
// Place your language file in the languages subfolder and name it "datetime-now-button-{language}.mo" replace {language} with your language value from wp-config.php
load_plugin_textdomain( 'datetime-now-button', FALSE, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
function AddNowButton() {
?>
<script type="text/javascript">
jQuery(document).ready(function() {
if (jQuery('#timestampdiv').length > 0) {
jQuery('#timestampdiv').find('div')
.append(' ')
.append(jQuery('<a>')
.attr('class', 'now button')
.append('<?php _e( 'Now', 'datetime-now-button' ); ?>')
);
}
if (jQuery('.inline-edit-date').length > 0) {
jQuery('.inline-edit-date').find('div')
.append(' ')
.append(jQuery('<a>')
.attr('class', 'now button')
.append('<?php _e( 'Now', 'datetime-now-button' ); ?>')
);
}
jQuery('.now.button').bind('click', function() {
<?php
$time_adj = current_time('timestamp');
$cur_mm = gmdate( 'm', $time_adj );
$cur_jj = gmdate( 'd', $time_adj );
$cur_aa = gmdate( 'Y', $time_adj );
$cur_hh = gmdate( 'H', $time_adj );
$cur_mn = gmdate( 'i', $time_adj );
?>
if (jQuery('select[name="mm"]').length > 0) jQuery('select[name="mm"]').val('<?php echo $cur_mm; ?>');
if (jQuery('input[name="jj"]').length > 0) jQuery('input[name="jj"]').val('<?php echo $cur_jj; ?>');
if (jQuery('input[name="aa"]').length > 0) jQuery('input[name="aa"]').val('<?php echo $cur_aa; ?>');
if (jQuery('input[name="hh"]').length > 0) jQuery('input[name="hh"]').val('<?php echo $cur_hh; ?>');
if (jQuery('input[name="mn"]').length > 0) jQuery('input[name="mn"]').val('<?php echo $cur_mn; ?>');
});
});
</script>
<?php
}
}
}
if ( class_exists( 'DateTimeNowButtonPlugin' ) ) $date_time_now_button = new DateTimeNowButtonPlugin();