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 4.7.6 4.7.7 4.7.8 4.7.9 4.8.0 4.9.0 4.9.1 5.0.1 5.0.2 5.1.1 5.1.2 5.1.3 5.2.0 5.2.1 5.3.2 5.3.3.1 5.3.4 5.3.5 5.3.6 5.3.7
woocommerce-multilingual / addons / wpml-dependencies / lib / classes / notices / class-wpml-notice.php
woocommerce-multilingual / addons / wpml-dependencies / lib / classes / notices Last commit date
pages 4 years ago DismissNotices.php 4 weeks ago class-wpml-notice-action.php 4 weeks ago class-wpml-notice-render.php 4 weeks ago class-wpml-notice.php 4 weeks ago class-wpml-notices.php 4 weeks ago
class-wpml-notice.php
282 lines
1 <?php
2
3 class WPML_Notice {
4 private $display_callbacks = array();
5 private $id;
6 private $text;
7 private $collapsed_text;
8 private $group = 'default';
9 private $restricted_to_user_ids = array();
10
11 private $actions = array();
12 private $css_class_types = array();
13 private $css_classes = array();
14 private $dismissible = false;
15 private $exclude_from_pages = array();
16 private $hideable = false;
17 private $collapsable = false;
18 private $restrict_to_pages = array();
19 private $restrict_to_page_prefixes = array();
20 private $restrict_to_screen_ids = array();
21 private $hide_if_notice_exists = null;
22 private $dismissible_for_different_text = true;
23
24 private $default_group_name = 'default';
25
26 private $capabilities = array();
27
28 private $dismiss_reset = false;
29
30 private $flash = false;
31
32 private $nonce_action;
33
34 private $text_only = false;
35
36 public function __construct( $id, $text, $group = 'default' ) {
37 $this->id = $id;
38 $this->text = $text;
39 $this->group = $group ? $group : $this->default_group_name;
40 }
41
42 public function add_action( WPML_Notice_Action $action ) {
43 $this->actions[] = $action;
44
45 if ( $action->can_dismiss() ) {
46 $this->dismissible = true;
47 }
48 if ( ! $action->can_dismiss_different_text() ) {
49 $this->dismissible_for_different_text = false;
50 }
51 if ( $action->can_hide() ) {
52 $this->hideable = true;
53 }
54 }
55
56 public function add_exclude_from_page( $page ) {
57 $this->exclude_from_pages[] = $page;
58 }
59
60 public function add_restrict_to_page( $page ) {
61 $this->restrict_to_pages[] = $page;
62 }
63
64 public function add_user_restriction( $user_id ) {
65 $user_id = (int) $user_id;
66 $this->restricted_to_user_ids[ $user_id ] = $user_id;
67 }
68
69 public function remove_user_restriction( $user_id ) {
70 unset( $this->restricted_to_user_ids[ (int) $user_id ] );
71 }
72
73 public function get_restricted_user_ids() {
74 return $this->restricted_to_user_ids;
75 }
76
77 public function is_user_restricted() {
78 return (bool) $this->restricted_to_user_ids;
79 }
80
81 public function is_for_current_user() {
82 return ! $this->restricted_to_user_ids
83 || array_key_exists( get_current_user_id(), $this->restricted_to_user_ids );
84 }
85
86 public function is_user_cap_allowed() {
87 $user_can = true;
88 foreach ( $this->capabilities as $cap ) {
89 $user_can = current_user_can( $cap );
90
91 if ( $user_can ) {
92 break;
93 }
94 }
95
96 return $user_can;
97 }
98
99 public function can_be_dismissed() {
100 return $this->dismissible;
101 }
102
103 public function can_be_dismissed_for_different_text() {
104 return $this->dismissible_for_different_text;
105 }
106
107 public function can_be_hidden() {
108 return $this->hideable;
109 }
110
111 public function can_be_collapsed() {
112 return $this->collapsable;
113 }
114
115 public function add_display_callback( $callback ) {
116 if ( ! is_callable( $callback ) ) {
117 throw new UnexpectedValueException( '\WPML_Notice::add_display_callback expects a callable', 1 );
118 }
119 $this->display_callbacks[] = $callback;
120 }
121
122 public function add_capability_check( array $cap ) {
123 $this->capabilities = $cap;
124 }
125
126 public function get_display_callbacks() {
127 $isNotIncompleteObject = function( $callback ) {
128 return ! ( isset( $callback[0] ) && $callback[0] instanceof __PHP_Incomplete_Class );
129 };
130
131 return array_filter( $this->display_callbacks, $isNotIncompleteObject );
132 }
133
134 public function get_actions() {
135 return $this->actions;
136 }
137
138 public function get_css_classes() {
139 return $this->css_classes;
140 }
141
142 public function set_css_classes( $css_classes ) {
143 if ( ! is_array( $css_classes ) ) {
144 $css_classes = explode( ' ', $css_classes );
145 }
146 $this->css_classes = $css_classes;
147 }
148
149 public function get_exclude_from_pages() {
150 return $this->exclude_from_pages;
151 }
152
153 public function get_group() {
154 return $this->group;
155 }
156
157 public function get_id() {
158 return $this->id;
159 }
160
161 public function set_restrict_to_page_prefixes( array $page_prefixes ) {
162 $this->restrict_to_page_prefixes = $page_prefixes;
163 }
164
165 public function get_restrict_to_page_prefixes() {
166 return $this->restrict_to_page_prefixes;
167 }
168
169 public function get_restrict_to_pages() {
170 return $this->restrict_to_pages;
171 }
172
173 public function set_restrict_to_screen_ids( array $screens ) {
174 $this->restrict_to_screen_ids = $screens;
175 }
176
177 public function get_restrict_to_screen_ids() {
178 return $this->restrict_to_screen_ids;
179 }
180
181 public function get_nonce_action() {
182 return $this->nonce_action;
183 }
184
185 public function get_text() {
186 $notice = array(
187 'id' => $this->get_id(),
188 'group' => $this->get_group(),
189 );
190 $this->text = apply_filters( 'wpml_notice_text', $this->text, $notice );
191
192 return $this->text;
193 }
194
195 public function get_css_class_types() {
196 return $this->css_class_types;
197 }
198
199 public function get_collapsed_text() {
200 return $this->collapsed_text;
201 }
202
203 public function set_css_class_types( $types ) {
204 $this->css_class_types = is_array( $types ) ? $types : explode( ' ', $types );
205
206 return $this;
207 }
208
209 public function set_dismissible( $dismissible ) {
210 $this->dismissible = $dismissible;
211 }
212
213 public function set_exclude_from_pages( array $pages ) {
214 $this->exclude_from_pages = $pages;
215 }
216
217 public function set_hide_if_notice_exists( $notice_id, $notice_group = null ) {
218 $this->hide_if_notice_exists = array(
219 'id' => $notice_id,
220 'group' => $notice_group,
221 );
222 }
223
224 public function get_hide_if_notice_exists() {
225 return $this->hide_if_notice_exists;
226 }
227
228 public function set_hideable( $hideable ) {
229 $this->hideable = $hideable;
230 }
231
232 public function set_collapsable( $collapsable ) {
233 $this->collapsable = $collapsable;
234 }
235
236 public function set_nonce_action( $action ) {
237 $this->nonce_action = $action;
238 }
239
240 public function set_collapsed_text( $collapsed_text ) {
241 $this->collapsed_text = $collapsed_text;
242 }
243
244 public function set_restrict_to_pages( array $pages ) {
245 $this->restrict_to_pages = $pages;
246 }
247
248 public function reset_dismiss() {
249 $this->dismiss_reset = true;
250 }
251
252 public function must_reset_dismiss() {
253 return $this->dismiss_reset;
254 }
255
256 public function is_different( WPML_Notice $other_notice ) {
257 return serialize( $this ) !== serialize( $other_notice );
258 }
259
260 public function set_flash( $flash = true ) {
261 $this->flash = (bool) $flash;
262
263 return $this;
264 }
265
266 public function is_flash() {
267 return $this->flash;
268 }
269
270 public function should_be_text_only() {
271 return $this->text_only;
272 }
273
274 public function set_text_only( $text_only ) {
275 $this->text_only = $text_only;
276 }
277
278 public static function make( $id, $text, $group = 'default' ) {
279 return new WPML_Notice( $id, $text, $group );
280 }
281 }
282