1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Interface for WordPress core |
5
|
|
|
* |
6
|
|
|
* @package uix |
7
|
|
|
* @author David Cramer |
8
|
|
|
* @license GPL-2.0+ |
9
|
|
|
* @link |
10
|
|
|
* @copyright 2016 David Cramer |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace uix\ui\core; |
14
|
|
|
|
15
|
|
|
class core { |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* List of core object scripts ( common scripts ) |
19
|
|
|
* |
20
|
|
|
* @since 1.0.0 |
21
|
|
|
* @access protected |
22
|
|
|
* @var array |
23
|
|
|
*/ |
24
|
|
|
protected $scripts = []; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* List of core object styles ( common styles ) |
28
|
|
|
* |
29
|
|
|
* @since 1.0.0 |
30
|
|
|
* @access protected |
31
|
|
|
* @var array |
32
|
|
|
*/ |
33
|
|
|
protected $styles = []; |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* setup actions and hooks - override to add specific hooks. use |
38
|
|
|
* parent::actions() to keep admin head |
39
|
|
|
* |
40
|
|
|
* @since 1.0.0 |
41
|
|
|
* @access protected |
42
|
|
|
*/ |
43
|
|
|
protected function actions() { |
44
|
|
|
|
45
|
|
|
// init uix after loaded. |
46
|
|
|
add_action( 'init', [ $this, 'init' ] ); |
47
|
|
|
// set location. |
48
|
|
|
$location = 'wp_print_styles'; |
49
|
|
|
if ( is_admin() ) { |
50
|
|
|
$location = 'admin_enqueue_scripts'; |
51
|
|
|
} |
52
|
|
|
// init UIX headers. |
53
|
|
|
add_action( $location, [ $this, 'enqueue_core' ] ); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Define core UIX styles - override to register core ( common styles for |
59
|
|
|
* uix type ) |
60
|
|
|
* |
61
|
|
|
* @since 1.0.0 |
62
|
|
|
* @access public |
63
|
|
|
*/ |
64
|
|
|
public function set_assets() { |
65
|
|
|
if ( ! empty( $this->struct['style'] ) ) { |
66
|
|
|
$this->assets['style'] = array_merge( $this->assets['style'], $this->struct['style'] ); |
|
|
|
|
67
|
|
|
} |
68
|
|
|
if ( ! empty( $this->struct['script'] ) ) { |
69
|
|
|
$this->assets['script'] = array_merge( $this->assets['script'], $this->struct['script'] ); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* enqueue core assets |
75
|
|
|
* |
76
|
|
|
* @since 1.0.0 |
77
|
|
|
* @access public |
78
|
|
|
*/ |
79
|
|
|
public function enqueue_core() { |
80
|
|
|
|
81
|
|
|
// Register uix core asset. |
82
|
|
|
$this->core_assets(); |
83
|
|
|
$this->enqueue_actions(); |
84
|
|
|
// push assets to ui manager. |
85
|
|
|
uix()->set_assets( $this->assets ); |
86
|
|
|
// done enqueuing - dpo inline or manual enqueue. |
87
|
|
|
$this->set_active_styles(); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Do core enqueue actions. |
92
|
|
|
* |
93
|
|
|
* @since 3.0.0 |
94
|
|
|
* @access public |
95
|
|
|
*/ |
96
|
|
|
private function enqueue_actions() { |
97
|
|
|
/** |
98
|
|
|
* Do object initilisation. |
99
|
|
|
* |
100
|
|
|
* @param object current uix instance |
101
|
|
|
*/ |
102
|
|
|
do_action( 'uix_admin_enqueue_scripts_' . $this->type, $this ); |
|
|
|
|
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Do object initilisation for specific slug. |
106
|
|
|
* |
107
|
|
|
* @param object current uix instance |
108
|
|
|
*/ |
109
|
|
|
do_action( 'uix_admin_enqueue_scripts_' . $this->type . '_' . $this->slug, $this ); |
|
|
|
|
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Register UIX depend js and css and call set assets |
114
|
|
|
* |
115
|
|
|
* @since 1.0.0 |
116
|
|
|
* @access protected |
117
|
|
|
*/ |
118
|
|
|
protected function core_assets() { |
119
|
|
|
wp_register_script( 'uix', $this->url . 'assets/js/core' . UIX_ASSET_DEBUG . '.js' ); |
|
|
|
|
120
|
|
|
wp_register_style( 'uix', $this->url . 'assets/css/core' . UIX_ASSET_DEBUG . '.css', [ 'dashicons' ] ); |
121
|
|
|
wp_localize_script( 'uix', 'uixApi', [ |
122
|
|
|
'root' => esc_url_raw( rest_url() ), |
123
|
|
|
'nonce' => wp_create_nonce( 'wp_rest' ), |
124
|
|
|
] ); |
125
|
|
|
|
126
|
|
|
// set assets . methods at before this point can set assets, after this not so much. |
127
|
|
|
$this->set_assets(); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* runs after assets have been enqueued |
132
|
|
|
* |
133
|
|
|
* @since 1.0.0 |
134
|
|
|
* @access protected |
135
|
|
|
*/ |
136
|
|
|
protected function set_active_styles() { |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Base color helper |
141
|
|
|
* |
142
|
|
|
* @since 1.0.0 |
143
|
|
|
* @access public |
144
|
|
|
*/ |
145
|
|
|
protected function base_color() { |
146
|
|
|
$color = '#D84315'; |
147
|
|
|
if ( empty( $this->struct['base_color'] ) ) { |
148
|
|
|
if ( ! empty( $this->parent ) ) { |
149
|
|
|
$color = $this->parent->base_color(); |
|
|
|
|
150
|
|
|
} |
151
|
|
|
} else { |
152
|
|
|
$color = $this->struct['base_color']; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* do object initilisation for specific slug |
157
|
|
|
* |
158
|
|
|
* @param object current uix instance |
159
|
|
|
*/ |
160
|
|
|
return apply_filters( 'uix_base_color_' . $this->type . '_' . $this->slug, $color ); |
161
|
|
|
|
162
|
|
|
} |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: