-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer_plugin.php
83 lines (73 loc) · 2.5 KB
/
timer_plugin.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
<?php
/*
Plugin Name: Task timer
Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
Description: Test task
Version: 0.2
Author: Okhmat Aleksey
Author URI: http://URI_Of_The_Plugin_Author
License: none
*/
define( 'WP_Timer_PLUGIN', __FILE__ );
define( 'WP_Timer_PLUGIN_DIR', untrailingslashit( dirname( WP_Timer_PLUGIN ) ) );
define( 'WP_Timer_THEME_TEMPLATE_DIR', (get_stylesheet_directory() . '/' . 'countdown/layout.php') );
class Countdown_Timer extends WP_Widget {
public function Countdown_Timer()
{
$widget_ops = array('classname' => 'Countdown_Timer', 'description' => 'Timer for the test task' );
$this->WP_Widget('Countdown_Timer', 'Timer', $widget_ops);
}
public function form($instance) {
if( $instance) {
$title = esc_attr($instance['title']);
$descr=$instance['descr'];
$date = esc_attr($instance['date']);
$hour = esc_attr($instance['hour']);
$minute = esc_attr($instance['minute']);
} else {
$title = '';
$date = '';
$hour = '';
$descr='';
$minute = '';
}
require_once WP_Timer_PLUGIN_DIR . '/admin/templates/admin-template.php';
}
public function update($new_instance, $old_instance) {
$instance = $old_instance;
$rand = (int)$new_instance['the_random_number'];
$instance['descr'] =$new_instance[ 'wp_editor_' . $rand ];
$instance['title'] = strip_tags($new_instance['title']);
$instance['date'] = strip_tags($new_instance['date']);
$instance['hour'] = strip_tags($new_instance['hour']);
$instance['minute'] = strip_tags($new_instance['minute']);
return $instance;
}
public function widget($args, $instance) {
$temp_date = explode("/", $instance['date']);
$instance['date'] = $temp_date[2] . "/" . $temp_date[0] . "/" . $temp_date[1];
extract($args);
$title = apply_filters('widget_title', $instance['title']);
echo $args['before_widget'];
if (file_exists( WP_Timer_THEME_TEMPLATE_DIR)) {
include WP_Timer_THEME_TEMPLATE_DIR;
} else {
if (!empty($title)){
?>
<div class="tp-title">
<?php
echo $before_title . $title . $after_title;
}
?>
</div>
<p class="clockTitle">Description:</p>
<p><?php echo $instance['descr']; ?></p>
<?php
echo do_shortcode('[tp_shortcode date="' . $instance['date'] . '" time="'. $instance['hour'] . ':' . $instance['minute'] . '"]');
}
echo $after_widget;
}
}
require_once WP_Timer_PLUGIN_DIR . '/includes/shortcodes.php';
require_once WP_Timer_PLUGIN_DIR . '/includes/functions.php';
?>