|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Admin Assets |
|
4
|
|
|
* |
|
5
|
|
|
* @package SimpleCalendar\Admin |
|
6
|
|
|
*/ |
|
7
|
|
|
namespace SimpleCalendar\Admin; |
|
8
|
|
|
|
|
9
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
|
10
|
|
|
exit; |
|
11
|
|
|
} |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Admin scripts and styles. |
|
15
|
|
|
* |
|
16
|
|
|
* Handles the plugin scripts and styles for back end dashboard pages. |
|
17
|
|
|
* |
|
18
|
|
|
* @since 3.0.0 |
|
19
|
|
|
*/ |
|
20
|
|
|
class Assets { |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Load minified assets. |
|
24
|
|
|
* |
|
25
|
|
|
* @access public |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
public $min = '.min'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Hook in tabs. |
|
32
|
|
|
* |
|
33
|
|
|
* @since 3.0.0 |
|
34
|
|
|
*/ |
|
35
|
|
|
public function __construct() { |
|
36
|
|
|
|
|
37
|
|
|
$this->min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG == true ) ? '' : '.min'; |
|
38
|
|
|
|
|
39
|
|
|
add_action( 'admin_enqueue_scripts', array( $this, 'load' ) ); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Enqueue scripts and styles. |
|
44
|
|
|
* |
|
45
|
|
|
* @since 3.0.0 |
|
46
|
|
|
*/ |
|
47
|
|
|
public function load() { |
|
48
|
|
|
|
|
49
|
|
|
$css_path = SIMPLE_CALENDAR_ASSETS . 'css/'; |
|
50
|
|
|
$css_path_vendor = $css_path . 'vendor/'; |
|
51
|
|
|
$js_path = SIMPLE_CALENDAR_ASSETS . 'js/'; |
|
52
|
|
|
$js_path_vendor = $js_path . 'vendor/'; |
|
53
|
|
|
|
|
54
|
|
|
/* ====================== * |
|
55
|
|
|
* Register Admin Scripts * |
|
56
|
|
|
* ====================== */ |
|
57
|
|
|
|
|
58
|
|
|
// TipTip uses ".minified.js" filename ending. |
|
59
|
|
|
wp_register_script( |
|
60
|
|
|
'simcal-tiptip', |
|
61
|
|
|
$js_path_vendor . 'jquery.tipTip' . ( ( $this->min !== '' ) ? '.minified' : '' ) . '.js', |
|
62
|
|
|
array( 'jquery' ), |
|
63
|
|
|
SIMPLE_CALENDAR_VERSION, |
|
64
|
|
|
true |
|
65
|
|
|
); |
|
66
|
|
|
wp_register_script( |
|
67
|
|
|
'simcal-select2', |
|
68
|
|
|
$js_path_vendor . 'select2' . $this->min . '.js', |
|
69
|
|
|
array(), |
|
70
|
|
|
SIMPLE_CALENDAR_VERSION, |
|
71
|
|
|
true |
|
72
|
|
|
); |
|
73
|
|
|
wp_register_script( |
|
74
|
|
|
'simcal-admin', |
|
75
|
|
|
$js_path . 'admin' . $this->min . '.js', |
|
76
|
|
|
array( |
|
77
|
|
|
'jquery', |
|
78
|
|
|
'jquery-ui-sortable', |
|
79
|
|
|
'jquery-ui-datepicker', |
|
80
|
|
|
'wp-color-picker', |
|
81
|
|
|
'simcal-tiptip', |
|
82
|
|
|
'simcal-select2', |
|
83
|
|
|
), |
|
84
|
|
|
SIMPLE_CALENDAR_VERSION, |
|
85
|
|
|
true |
|
86
|
|
|
); |
|
87
|
|
|
wp_register_script( |
|
88
|
|
|
'simcal-admin-add-calendar', |
|
89
|
|
|
$js_path . 'admin-add-calendar' . $this->min . '.js', |
|
90
|
|
|
array( 'simcal-select2' ), |
|
91
|
|
|
SIMPLE_CALENDAR_VERSION, |
|
92
|
|
|
true |
|
93
|
|
|
); |
|
94
|
|
|
|
|
95
|
|
|
/* ===================== * |
|
96
|
|
|
* Register Admin Styles * |
|
97
|
|
|
* ===================== */ |
|
98
|
|
|
|
|
99
|
|
|
wp_register_style( |
|
100
|
|
|
'simcal-select2', |
|
101
|
|
|
$css_path_vendor . 'select2' . $this->min . '.css', |
|
102
|
|
|
array(), |
|
103
|
|
|
SIMPLE_CALENDAR_VERSION |
|
104
|
|
|
); |
|
105
|
|
|
wp_register_style( |
|
106
|
|
|
'simcal-admin', |
|
107
|
|
|
$css_path . 'admin' . $this->min . '.css', |
|
108
|
|
|
array( |
|
109
|
|
|
'wp-color-picker', |
|
110
|
|
|
'simcal-select2', |
|
111
|
|
|
), |
|
112
|
|
|
SIMPLE_CALENDAR_VERSION |
|
113
|
|
|
); |
|
114
|
|
|
wp_register_style( |
|
115
|
|
|
'simcal-admin-add-calendar', |
|
116
|
|
|
$css_path . 'admin-add-calendar' . $this->min . '.css', |
|
117
|
|
|
array( 'simcal-select2' ), |
|
118
|
|
|
SIMPLE_CALENDAR_VERSION |
|
119
|
|
|
); |
|
120
|
|
|
|
|
121
|
|
|
if ( simcal_is_admin_screen() !== false ) { |
|
122
|
|
|
|
|
123
|
|
|
wp_enqueue_script( 'simcal-admin' ); |
|
124
|
|
|
wp_localize_script( |
|
125
|
|
|
'simcal-admin', |
|
126
|
|
|
'simcal_admin', |
|
127
|
|
|
simcal_common_scripts_variables() |
|
128
|
|
|
); |
|
129
|
|
|
|
|
130
|
|
|
wp_enqueue_style( 'simcal-admin' ); |
|
131
|
|
|
|
|
132
|
|
|
} else { |
|
133
|
|
|
|
|
134
|
|
|
global $post_type; |
|
|
|
|
|
|
135
|
|
|
$screen = get_current_screen(); |
|
136
|
|
|
|
|
137
|
|
|
$post_types = array(); |
|
138
|
|
|
$settings = get_option( 'simple-calendar_settings_calendars' ); |
|
139
|
|
|
if ( isset( $settings['general']['attach_calendars_posts'] ) ) { |
|
140
|
|
|
$post_types = $settings['general']['attach_calendars_posts']; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
$conditions = array( |
|
144
|
|
|
in_array( $post_type, (array) $post_types ), |
|
145
|
|
|
$screen->id == 'widgets', |
|
146
|
|
|
); |
|
147
|
|
|
|
|
148
|
|
|
if ( in_array( true, $conditions ) ) { |
|
149
|
|
|
|
|
150
|
|
|
wp_enqueue_script( 'simcal-admin-add-calendar' ); |
|
151
|
|
|
wp_localize_script( 'simcal-admin-add-calendar', 'simcal_admin', array( |
|
152
|
|
|
'locale' => get_locale(), |
|
153
|
|
|
'text_dir' => is_rtl() ? 'rtl' : 'ltr', |
|
154
|
|
|
) ); |
|
155
|
|
|
|
|
156
|
|
|
wp_enqueue_style( 'simcal-admin-add-calendar' ); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
} |
|
164
|
|
|
|
Instead of relying on
globalstate, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state