forked from relu/contact-form-7-datepicker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
contact-form-7-datepicker.php
executable file
·156 lines (128 loc) · 4.44 KB
/
contact-form-7-datepicker.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
/**
Plugin Name: Contact Form 7 Datepicker
Plugin URI: https://github.com/relu/contact-form-7-datepicker/
Description: Easily add a date field using jQuery UI's datepicker to your CF7 forms. This plugin depends on Contact Form 7.
Author: Aurel Canciu
Version: 2.5.1
Author URI: https://github.com/relu/
*/
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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
*/
?>
<?php
class ContactForm7Datepicker {
const JQUERYUI_VERSION = '1.11.4';
function __construct() {
add_action('plugins_loaded', array($this, 'load_modules'), 50);
add_action('wpcf7_enqueue_scripts', array(__CLASS__, 'enqueue_js'));
add_action('wpcf7_enqueue_styles', array(__CLASS__, 'enqueue_css'));
register_activation_hook(__FILE__, array($this, 'activate'));
if (is_admin()) {
require_once dirname(__FILE__) . '/admin.php';
}
}
function load_modules() {
require_once dirname(__FILE__) . '/datetimepicker.php';
require_once dirname(__FILE__) . '/modules/datetime.php';
require_once dirname(__FILE__) . '/modules/date.php';
require_once dirname(__FILE__) . '/modules/time.php';
}
function activate() {
if (! get_option('cf7dp_ui_theme'))
add_option('cf7dp_ui_theme', 'smoothness');
}
public static function enqueue_js() {
$regional = CF7_DateTimePicker::get_regional_match();
$proto = is_ssl() ? 'https' : 'http';
if (! empty($regional)) {
wp_enqueue_script(
'jquery-ui-' . $regional,
$proto . '://ajax.googleapis.com/ajax/libs/jqueryui/' . self::JQUERYUI_VERSION . '/i18n/datepicker-' . $regional . '.min.js',
array('jquery-ui-datepicker'),
self::JQUERYUI_VERSION,
true
);
wp_enqueue_script(
'jquery-ui-timepicker-' . $regional,
plugins_url('js/jquery-ui-timepicker/i18n/jquery-ui-timepicker-' . $regional . '.js', __FILE__),
array('jquery-ui-timepicker'),
'',
true
);
}
wp_enqueue_script('jquery-ui-datepicker');
wp_enqueue_script(
'jquery-ui-timepicker',
plugins_url('js/jquery-ui-timepicker/jquery-ui-timepicker-addon.min.js', __FILE__),
array('jquery-ui-datepicker'),
'',
true
);
wp_enqueue_script('jquery-ui-slider');
wp_enqueue_script(
'jquery-ui-slider-access',
plugins_url('js/jquery-ui-sliderAccess.js', __FILE__),
array('jquery-ui-slider', 'jquery-ui-button'),
'',
true
);
wp_register_script(
'jquery-ui-effect-core',
plugins_url('js/jquery.ui.effect.min.js', __FILE__),
array('jquery-ui-datepicker'),
self::JQUERYUI_VERSION,
true
);
foreach (CF7_DateTimePicker::$effects as $effect) {
wp_register_script(
'jquery-ui-effect-' . $effect,
plugins_url('js/jquery.ui.effect-' . $effect . '.min.js', __FILE__),
array('jquery-ui-effect-core'),
self::JQUERYUI_VERSION,
true
);
}
}
public static function enqueue_css() {
wp_enqueue_style(
'jquery-ui-theme',
self::get_theme_uri(),
'',
self::JQUERYUI_VERSION,
'all'
);
wp_enqueue_style(
'jquery-ui-timepicker',
plugins_url('js/jquery-ui-timepicker/jquery-ui-timepicker-addon.min.css', __FILE__)
);
}
public static function get_theme_uri() {
$theme = apply_filters('cf7dp_ui_theme', get_option('cf7dp_ui_theme'));
if (! is_admin() && $theme == 'disabled')
return;
$proto = is_ssl() ? 'https' : 'http';
$custom_themes = (array)apply_filters('cf7dp_custom_ui_themes', array());
if (! is_admin() && ! empty($custom_themes) && array_key_exists($theme, $custom_themes)) {
$theme_css_uri = $custom_themes[$theme];
$uri = get_stylesheet_directory_uri() . '/' . ltrim($theme_css_uri, '/');
} else {
$uri = $proto . '://ajax.googleapis.com/ajax/libs/jqueryui/' . self::JQUERYUI_VERSION . '/themes/' . $theme . '/jquery-ui.min.css';
}
return $uri;
}
}
new ContactForm7Datepicker;