@@ -14,38 +14,38 @@ discard block |
||
14 | 14 | */ |
15 | 15 | |
16 | 16 | // Exit if accessed directly. |
17 | -if ( ! defined( 'ABSPATH' ) ) { |
|
17 | +if ( ! defined('ABSPATH')) { |
|
18 | 18 | exit; |
19 | 19 | } |
20 | 20 | |
21 | 21 | // Composer fallback for PHP < 5.3.0. |
22 | -if ( version_compare( PHP_VERSION, '5.3.0' ) === -1 ) { |
|
22 | +if (version_compare(PHP_VERSION, '5.3.0') === -1) { |
|
23 | 23 | include_once 'vendor/autoload_52.php'; |
24 | 24 | } else { |
25 | 25 | include_once 'vendor/autoload.php'; |
26 | 26 | } |
27 | 27 | |
28 | 28 | // Plugin constants. |
29 | -$this_plugin_path = trailingslashit( dirname( __FILE__ ) ); |
|
30 | -$this_plugin_dir = plugin_dir_url( __FILE__ ); |
|
29 | +$this_plugin_path = trailingslashit(dirname(__FILE__)); |
|
30 | +$this_plugin_dir = plugin_dir_url(__FILE__); |
|
31 | 31 | $this_plugin_constants = array( |
32 | 32 | 'SIMPLE_CALENDAR_VERSION' => '3.0.6', |
33 | 33 | 'SIMPLE_CALENDAR_MAIN_FILE' => __FILE__, |
34 | 34 | 'SIMPLE_CALENDAR_URL' => $this_plugin_dir, |
35 | - 'SIMPLE_CALENDAR_ASSETS' => $this_plugin_dir . 'assets/', |
|
35 | + 'SIMPLE_CALENDAR_ASSETS' => $this_plugin_dir.'assets/', |
|
36 | 36 | 'SIMPLE_CALENDAR_PATH' => $this_plugin_path, |
37 | - 'SIMPLE_CALENDAR_INC' => $this_plugin_path . 'includes/', |
|
37 | + 'SIMPLE_CALENDAR_INC' => $this_plugin_path.'includes/', |
|
38 | 38 | ); |
39 | -foreach ( $this_plugin_constants as $constant => $value ) { |
|
40 | - if ( ! defined( $constant ) ) { |
|
41 | - define( $constant, $value ); |
|
39 | +foreach ($this_plugin_constants as $constant => $value) { |
|
40 | + if ( ! defined($constant)) { |
|
41 | + define($constant, $value); |
|
42 | 42 | } |
43 | 43 | } |
44 | 44 | |
45 | 45 | // Check plugin requirements before loading plugin. |
46 | 46 | $this_plugin_checks = new WP_Requirements( |
47 | 47 | 'Simple Calendar', |
48 | - plugin_basename( __FILE__ ), |
|
48 | + plugin_basename(__FILE__), |
|
49 | 49 | array( |
50 | 50 | 'PHP' => '5.3.0', |
51 | 51 | 'WordPress' => '4.0.0', |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | ) |
56 | 56 | ) |
57 | 57 | ); |
58 | -if ( $this_plugin_checks->pass() === false ) { |
|
58 | +if ($this_plugin_checks->pass() === false) { |
|
59 | 59 | $this_plugin_checks->halt(); |
60 | 60 | return; |
61 | 61 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | */ |
7 | 7 | namespace SimpleCalendar\Abstracts; |
8 | 8 | |
9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
9 | +if ( ! defined('ABSPATH')) { |
|
10 | 10 | exit; |
11 | 11 | } |
12 | 12 | |
@@ -84,27 +84,27 @@ discard block |
||
84 | 84 | |
85 | 85 | $settings = array(); |
86 | 86 | |
87 | - $settings[ $this->id ] = array( |
|
87 | + $settings[$this->id] = array( |
|
88 | 88 | 'label' => $this->label, |
89 | 89 | 'description' => $this->description, |
90 | 90 | ); |
91 | 91 | |
92 | - if ( ! empty( $this->sections ) && is_array( $this->sections ) ) { |
|
92 | + if ( ! empty($this->sections) && is_array($this->sections)) { |
|
93 | 93 | |
94 | - foreach ( $this->sections as $section => $content ) { |
|
94 | + foreach ($this->sections as $section => $content) { |
|
95 | 95 | |
96 | - $settings[ $this->id ]['sections'][ $section ] = array( |
|
97 | - 'title' => isset( $content['title'] ) ? $content['title'] : '', |
|
98 | - 'description' => isset( $content['description'] ) ? $content['description'] : '', |
|
99 | - 'callback' => array( $this, 'add_settings_section_callback' ), |
|
100 | - 'fields' => isset( $this->fields[ $section ] ) ? $this->fields[ $section ] : '', |
|
96 | + $settings[$this->id]['sections'][$section] = array( |
|
97 | + 'title' => isset($content['title']) ? $content['title'] : '', |
|
98 | + 'description' => isset($content['description']) ? $content['description'] : '', |
|
99 | + 'callback' => array($this, 'add_settings_section_callback'), |
|
100 | + 'fields' => isset($this->fields[$section]) ? $this->fields[$section] : '', |
|
101 | 101 | ); |
102 | 102 | |
103 | 103 | } |
104 | 104 | |
105 | 105 | } |
106 | 106 | |
107 | - return apply_filters( 'simcal_get_' . $this->option_group . '_' . $this->id , $settings ); |
|
107 | + return apply_filters('simcal_get_'.$this->option_group.'_'.$this->id, $settings); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
@@ -118,12 +118,12 @@ discard block |
||
118 | 118 | * |
119 | 119 | * @return string |
120 | 120 | */ |
121 | - protected function get_option_value( $section, $setting ) { |
|
121 | + protected function get_option_value($section, $setting) { |
|
122 | 122 | |
123 | 123 | $option = $this->values; |
124 | 124 | |
125 | - if ( ! empty( $option ) && is_array( $option ) ) { |
|
126 | - return isset( $option[ $section ][ $setting ] ) ? $option[ $section ][ $setting ] : ''; |
|
125 | + if ( ! empty($option) && is_array($option)) { |
|
126 | + return isset($option[$section][$setting]) ? $option[$section][$setting] : ''; |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | return ''; |
@@ -156,14 +156,14 @@ discard block |
||
156 | 156 | * |
157 | 157 | * @return string |
158 | 158 | */ |
159 | - public function add_settings_section_callback( $section ) { |
|
159 | + public function add_settings_section_callback($section) { |
|
160 | 160 | |
161 | - $callback = isset( $section['callback'][0] ) ? $section['callback'][0] : ''; |
|
162 | - $sections = isset( $callback->sections ) ? $callback->sections : ''; |
|
163 | - $description = isset( $sections[ $section['id'] ]['description'] ) ? $sections[ $section['id'] ]['description'] : ''; |
|
164 | - $default = $description ? '<p>' . $description . '</p>' : ''; |
|
161 | + $callback = isset($section['callback'][0]) ? $section['callback'][0] : ''; |
|
162 | + $sections = isset($callback->sections) ? $callback->sections : ''; |
|
163 | + $description = isset($sections[$section['id']]['description']) ? $sections[$section['id']]['description'] : ''; |
|
164 | + $default = $description ? '<p>'.$description.'</p>' : ''; |
|
165 | 165 | |
166 | - echo apply_filters( 'simcal_' . $this->option_group . '_' . $this->id . '_sections_callback', $default ); |
|
166 | + echo apply_filters('simcal_'.$this->option_group.'_'.$this->id.'_sections_callback', $default); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
@@ -177,16 +177,16 @@ discard block |
||
177 | 177 | * |
178 | 178 | * @return array Sanitized settings. |
179 | 179 | */ |
180 | - public function validate( $settings ) { |
|
180 | + public function validate($settings) { |
|
181 | 181 | |
182 | 182 | $sanitized = ''; |
183 | 183 | |
184 | - if ( is_array( $settings ) ) { |
|
185 | - foreach ( $settings as $k => $v ) { |
|
186 | - $sanitized[ $k ] = simcal_sanitize_input( $v ); |
|
184 | + if (is_array($settings)) { |
|
185 | + foreach ($settings as $k => $v) { |
|
186 | + $sanitized[$k] = simcal_sanitize_input($v); |
|
187 | 187 | } |
188 | 188 | } else { |
189 | - $sanitized = simcal_sanitize_input( $settings ); |
|
189 | + $sanitized = simcal_sanitize_input($settings); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | return $sanitized; |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | */ |
7 | 7 | namespace SimpleCalendar\Abstracts; |
8 | 8 | |
9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
9 | +if ( ! defined('ABSPATH')) { |
|
10 | 10 | exit; |
11 | 11 | } |
12 | 12 | |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * |
27 | 27 | * @param mixed $args |
28 | 28 | */ |
29 | - public function __construct( $args = '' ); |
|
29 | + public function __construct($args = ''); |
|
30 | 30 | |
31 | 31 | /** |
32 | 32 | * Return the parent calendar type. |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | * |
76 | 76 | * @return array |
77 | 77 | */ |
78 | - public function scripts( $min = '' ); |
|
78 | + public function scripts($min = ''); |
|
79 | 79 | |
80 | 80 | /** |
81 | 81 | * Styles. |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | * |
89 | 89 | * @return array |
90 | 90 | */ |
91 | - public function styles( $min = '' ); |
|
91 | + public function styles($min = ''); |
|
92 | 92 | |
93 | 93 | /** |
94 | 94 | * Print HTML. |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | use SimpleCalendar\Events\Event_Builder; |
12 | 12 | use SimpleCalendar\Events\Events; |
13 | 13 | |
14 | -if ( ! defined( 'ABSPATH' ) ) { |
|
14 | +if ( ! defined('ABSPATH')) { |
|
15 | 15 | exit; |
16 | 16 | } |
17 | 17 | |
@@ -234,12 +234,12 @@ discard block |
||
234 | 234 | * @param int|object|\WP_Post|Calendar $calendar |
235 | 235 | * @param string $view |
236 | 236 | */ |
237 | - public function __construct( $calendar, $view = '' ) { |
|
237 | + public function __construct($calendar, $view = '') { |
|
238 | 238 | |
239 | 239 | // Set the post object. |
240 | - $this->set_post_object( $calendar ); |
|
240 | + $this->set_post_object($calendar); |
|
241 | 241 | |
242 | - if ( ! is_null( $this->post ) ) { |
|
242 | + if ( ! is_null($this->post)) { |
|
243 | 243 | |
244 | 244 | // Set calendar type and events source. |
245 | 245 | $this->set_taxonomies(); |
@@ -256,23 +256,23 @@ discard block |
||
256 | 256 | $this->set_events_template(); |
257 | 257 | |
258 | 258 | // Get events source data. |
259 | - $feed = simcal_get_feed( $this ); |
|
260 | - if ( $feed instanceof Feed ) { |
|
261 | - if ( ! empty( $feed->events ) ) { |
|
262 | - if ( is_array( $feed->events ) ) { |
|
263 | - $this->set_events( $feed->events ); |
|
264 | - if ( 'use_calendar' == get_post_meta( $this->id, '_feed_timezone_setting', true ) ) { |
|
259 | + $feed = simcal_get_feed($this); |
|
260 | + if ($feed instanceof Feed) { |
|
261 | + if ( ! empty($feed->events)) { |
|
262 | + if (is_array($feed->events)) { |
|
263 | + $this->set_events($feed->events); |
|
264 | + if ('use_calendar' == get_post_meta($this->id, '_feed_timezone_setting', true)) { |
|
265 | 265 | $this->timezone = $feed->timezone; |
266 | - $this->set_start( $feed->timezone ); |
|
266 | + $this->set_start($feed->timezone); |
|
267 | 267 | } |
268 | - } elseif ( is_string( $feed->events ) ) { |
|
268 | + } elseif (is_string($feed->events)) { |
|
269 | 269 | $this->errors[] = $feed->events; |
270 | 270 | } |
271 | 271 | } |
272 | 272 | } |
273 | 273 | |
274 | 274 | // Set general purpose timestamps. |
275 | - $now = Carbon::now( $this->timezone ); |
|
275 | + $now = Carbon::now($this->timezone); |
|
276 | 276 | $this->now = $now->getTimestamp(); |
277 | 277 | $this->today = $now->startOfDay()->getTimestamp(); |
278 | 278 | $this->offset = $now->getOffset(); |
@@ -283,26 +283,26 @@ discard block |
||
283 | 283 | $this->set_datetime_separator(); |
284 | 284 | |
285 | 285 | // Set earliest and latest event timestamps. |
286 | - if ( $this->events && is_array( $this->events ) ) { |
|
287 | - $this->earliest_event = intval( current( array_keys( $this->events ) ) ); |
|
288 | - $this->latest_event = intval( key( array_slice( $this->events, -1, 1, true ) ) ); |
|
286 | + if ($this->events && is_array($this->events)) { |
|
287 | + $this->earliest_event = intval(current(array_keys($this->events))); |
|
288 | + $this->latest_event = intval(key(array_slice($this->events, -1, 1, true))); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | // Set calendar end. |
292 | 292 | $this->set_end(); |
293 | 293 | |
294 | 294 | // Set view. |
295 | - if ( ! $view ) { |
|
295 | + if ( ! $view) { |
|
296 | 296 | |
297 | - $calendar_view = get_post_meta( $this->id, '_calendar_view', true ); |
|
298 | - $calendar_view = isset( $calendar_view[ $this->type ] ) ? $calendar_view[ $this->type ] : ''; |
|
297 | + $calendar_view = get_post_meta($this->id, '_calendar_view', true); |
|
298 | + $calendar_view = isset($calendar_view[$this->type]) ? $calendar_view[$this->type] : ''; |
|
299 | 299 | |
300 | - $view = esc_attr( $calendar_view ); |
|
300 | + $view = esc_attr($calendar_view); |
|
301 | 301 | } |
302 | 302 | } |
303 | 303 | |
304 | 304 | // Get view. |
305 | - $this->view = $this->get_view( $view ); |
|
305 | + $this->view = $this->get_view($view); |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | /** |
@@ -314,8 +314,8 @@ discard block |
||
314 | 314 | * |
315 | 315 | * @return bool |
316 | 316 | */ |
317 | - public function __isset( $key ) { |
|
318 | - return metadata_exists( 'post', $this->id, '_' . $key ); |
|
317 | + public function __isset($key) { |
|
318 | + return metadata_exists('post', $this->id, '_'.$key); |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | /** |
@@ -327,9 +327,9 @@ discard block |
||
327 | 327 | * |
328 | 328 | * @return mixed |
329 | 329 | */ |
330 | - public function __get( $key ) { |
|
331 | - $value = get_post_meta( $this->id, '_' . $key, true ); |
|
332 | - if ( ! empty( $value ) ) { |
|
330 | + public function __get($key) { |
|
331 | + $value = get_post_meta($this->id, '_'.$key, true); |
|
332 | + if ( ! empty($value)) { |
|
333 | 333 | $this->$key = $value; |
334 | 334 | } |
335 | 335 | return $value; |
@@ -342,17 +342,17 @@ discard block |
||
342 | 342 | * |
343 | 343 | * @param int|object|\WP_Post|Calendar $calendar |
344 | 344 | */ |
345 | - public function set_post_object( $calendar ) { |
|
346 | - if ( is_numeric( $calendar ) ) { |
|
347 | - $this->id = absint( $calendar ); |
|
348 | - $this->post = get_post( $this->id ); |
|
349 | - } elseif ( $calendar instanceof Calendar ) { |
|
350 | - $this->id = absint( $calendar->id ); |
|
345 | + public function set_post_object($calendar) { |
|
346 | + if (is_numeric($calendar)) { |
|
347 | + $this->id = absint($calendar); |
|
348 | + $this->post = get_post($this->id); |
|
349 | + } elseif ($calendar instanceof Calendar) { |
|
350 | + $this->id = absint($calendar->id); |
|
351 | 351 | $this->post = $calendar->post; |
352 | - } elseif ( $calendar instanceof \WP_Post ) { |
|
353 | - $this->id = absint( $calendar->ID ); |
|
352 | + } elseif ($calendar instanceof \WP_Post) { |
|
353 | + $this->id = absint($calendar->ID); |
|
354 | 354 | $this->post = $calendar; |
355 | - } elseif ( isset( $calendar->id ) && isset( $calendar->post ) ) { |
|
355 | + } elseif (isset($calendar->id) && isset($calendar->post)) { |
|
356 | 356 | $this->id = $calendar->id; |
357 | 357 | $this->post = $calendar->post; |
358 | 358 | } |
@@ -366,8 +366,8 @@ discard block |
||
366 | 366 | * @return string |
367 | 367 | */ |
368 | 368 | public function get_title() { |
369 | - $title = isset( $this->post->post_title ) ? $this->post->post_title : ''; |
|
370 | - return apply_filters( 'simcal_calendar_title', $title ); |
|
369 | + $title = isset($this->post->post_title) ? $this->post->post_title : ''; |
|
370 | + return apply_filters('simcal_calendar_title', $title); |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | /** |
@@ -389,16 +389,16 @@ discard block |
||
389 | 389 | */ |
390 | 390 | protected function set_taxonomies() { |
391 | 391 | // Set calendar type. |
392 | - if ( $type = wp_get_object_terms( $this->id, 'calendar_type' ) ) { |
|
393 | - $this->type = sanitize_title( current( $type )->name ); |
|
392 | + if ($type = wp_get_object_terms($this->id, 'calendar_type')) { |
|
393 | + $this->type = sanitize_title(current($type)->name); |
|
394 | 394 | } else { |
395 | - $this->type = apply_filters( 'simcal_calendar_default_type', 'default-calendar' ); |
|
395 | + $this->type = apply_filters('simcal_calendar_default_type', 'default-calendar'); |
|
396 | 396 | } |
397 | 397 | // Set feed type. |
398 | - if ( $feed_type = wp_get_object_terms( $this->id, 'calendar_feed' ) ) { |
|
399 | - $this->feed = sanitize_title( current( $feed_type )->name ); |
|
398 | + if ($feed_type = wp_get_object_terms($this->id, 'calendar_feed')) { |
|
399 | + $this->feed = sanitize_title(current($feed_type)->name); |
|
400 | 400 | } else { |
401 | - $this->feed = apply_filters( 'simcal_calendar_default_feed', 'google' ); |
|
401 | + $this->feed = apply_filters('simcal_calendar_default_feed', 'google'); |
|
402 | 402 | } |
403 | 403 | } |
404 | 404 | |
@@ -410,7 +410,7 @@ discard block |
||
410 | 410 | * @return Events |
411 | 411 | */ |
412 | 412 | public function get_events() { |
413 | - return new Events( $this->events, $this->timezone ); |
|
413 | + return new Events($this->events, $this->timezone); |
|
414 | 414 | } |
415 | 415 | |
416 | 416 | /** |
@@ -420,14 +420,14 @@ discard block |
||
420 | 420 | * |
421 | 421 | * @param array $array |
422 | 422 | */ |
423 | - public function set_events( array $array ) { |
|
423 | + public function set_events(array $array) { |
|
424 | 424 | |
425 | 425 | $events = array(); |
426 | 426 | |
427 | - if ( ! empty( $array ) ) { |
|
428 | - foreach ( $array as $tz => $e ) { |
|
429 | - foreach ( $e as $event ) { |
|
430 | - $events[ $tz ][] = $event instanceof Event ? $event : new Event( $event ); |
|
427 | + if ( ! empty($array)) { |
|
428 | + foreach ($array as $tz => $e) { |
|
429 | + foreach ($e as $event) { |
|
430 | + $events[$tz][] = $event instanceof Event ? $event : new Event($event); |
|
431 | 431 | } |
432 | 432 | } |
433 | 433 | } |
@@ -444,11 +444,11 @@ discard block |
||
444 | 444 | * |
445 | 445 | * @return string |
446 | 446 | */ |
447 | - public function set_events_template( $template = '' ) { |
|
448 | - if ( empty( $template ) ) { |
|
449 | - $template = isset( $this->post->post_content ) ? $this->post->post_content : ''; |
|
447 | + public function set_events_template($template = '') { |
|
448 | + if (empty($template)) { |
|
449 | + $template = isset($this->post->post_content) ? $this->post->post_content : ''; |
|
450 | 450 | } |
451 | - $this->events_template = wpautop( wp_kses_post( trim( $template ) ) ); |
|
451 | + $this->events_template = wpautop(wp_kses_post(trim($template))); |
|
452 | 452 | } |
453 | 453 | |
454 | 454 | /** |
@@ -458,32 +458,32 @@ discard block |
||
458 | 458 | * |
459 | 459 | * @param string $tz Timezone. |
460 | 460 | */ |
461 | - public function set_timezone( $tz = '' ) { |
|
461 | + public function set_timezone($tz = '') { |
|
462 | 462 | |
463 | - $site_tz = esc_attr( simcal_get_wp_timezone() ); |
|
463 | + $site_tz = esc_attr(simcal_get_wp_timezone()); |
|
464 | 464 | |
465 | - if ( empty( $tz ) ) { |
|
465 | + if (empty($tz)) { |
|
466 | 466 | |
467 | - $timezone_setting = get_post_meta( $this->id, '_feed_timezone_setting', true ); |
|
467 | + $timezone_setting = get_post_meta($this->id, '_feed_timezone_setting', true); |
|
468 | 468 | |
469 | - if ( 'use_site' == $timezone_setting ) { |
|
469 | + if ('use_site' == $timezone_setting) { |
|
470 | 470 | $tz = $site_tz; |
471 | - } elseif ( 'use_custom' == $timezone_setting ) { |
|
472 | - $custom_timezone = esc_attr( get_post_meta( $this->id, '_feed_timezone', true ) ); |
|
471 | + } elseif ('use_custom' == $timezone_setting) { |
|
472 | + $custom_timezone = esc_attr(get_post_meta($this->id, '_feed_timezone', true)); |
|
473 | 473 | // One may be using a non standard timezone in GMT (UTC) offset format. |
474 | - if ( ( strpos( $custom_timezone, 'UTC+' ) === 0 ) || ( strpos( $custom_timezone, 'UTC-' ) === 0 ) ) { |
|
475 | - $tz = simcal_get_timezone_from_gmt_offset( substr( $custom_timezone, 3 ) ); |
|
474 | + if ((strpos($custom_timezone, 'UTC+') === 0) || (strpos($custom_timezone, 'UTC-') === 0)) { |
|
475 | + $tz = simcal_get_timezone_from_gmt_offset(substr($custom_timezone, 3)); |
|
476 | 476 | } else { |
477 | - $tz = ! empty( $custom_timezone ) ? $custom_timezone : 'UTC'; |
|
477 | + $tz = ! empty($custom_timezone) ? $custom_timezone : 'UTC'; |
|
478 | 478 | } |
479 | 479 | } |
480 | 480 | |
481 | - $this->timezone = empty( $tz ) ? 'UTC' : $tz; |
|
481 | + $this->timezone = empty($tz) ? 'UTC' : $tz; |
|
482 | 482 | return; |
483 | 483 | } |
484 | 484 | |
485 | 485 | $this->site_timezone = $site_tz; |
486 | - $this->timezone = simcal_esc_timezone( $tz, $this->timezone ); |
|
486 | + $this->timezone = simcal_esc_timezone($tz, $this->timezone); |
|
487 | 487 | } |
488 | 488 | |
489 | 489 | /** |
@@ -493,20 +493,20 @@ discard block |
||
493 | 493 | * |
494 | 494 | * @param string $format PHP datetime format. |
495 | 495 | */ |
496 | - public function set_date_format( $format = '' ) { |
|
496 | + public function set_date_format($format = '') { |
|
497 | 497 | |
498 | 498 | $date_format_custom = $date_format_default = $format; |
499 | 499 | |
500 | - if ( empty( $date_format_custom ) ) { |
|
500 | + if (empty($date_format_custom)) { |
|
501 | 501 | |
502 | - $date_format_option = esc_attr( get_post_meta( $this->id, '_calendar_date_format_setting', true ) ); |
|
503 | - $date_format_default = esc_attr( get_option( 'date_format' ) ); |
|
502 | + $date_format_option = esc_attr(get_post_meta($this->id, '_calendar_date_format_setting', true)); |
|
503 | + $date_format_default = esc_attr(get_option('date_format')); |
|
504 | 504 | $date_format_custom = ''; |
505 | 505 | |
506 | - if ( 'use_custom' == $date_format_option ) { |
|
507 | - $date_format_custom = esc_attr( get_post_meta( $this->id, '_calendar_date_format', true ) ); |
|
508 | - } elseif ( 'use_custom_php' ) { |
|
509 | - $date_format_custom = esc_attr( get_post_meta( $this->id, '_calendar_date_format_php', true ) ); |
|
506 | + if ('use_custom' == $date_format_option) { |
|
507 | + $date_format_custom = esc_attr(get_post_meta($this->id, '_calendar_date_format', true)); |
|
508 | + } elseif ('use_custom_php') { |
|
509 | + $date_format_custom = esc_attr(get_post_meta($this->id, '_calendar_date_format_php', true)); |
|
510 | 510 | } |
511 | 511 | } |
512 | 512 | |
@@ -520,20 +520,20 @@ discard block |
||
520 | 520 | * |
521 | 521 | * @param string $format PHP datetime format. |
522 | 522 | */ |
523 | - public function set_time_format( $format = '' ) { |
|
523 | + public function set_time_format($format = '') { |
|
524 | 524 | |
525 | 525 | $time_format_custom = $time_format_default = $format; |
526 | 526 | |
527 | - if ( empty( $time_format_custom ) ) { |
|
527 | + if (empty($time_format_custom)) { |
|
528 | 528 | |
529 | - $time_format_option = esc_attr( get_post_meta( $this->id, '_calendar_time_format_setting', true ) ); |
|
530 | - $time_format_default = esc_attr( get_option( 'time_format' ) ); |
|
529 | + $time_format_option = esc_attr(get_post_meta($this->id, '_calendar_time_format_setting', true)); |
|
530 | + $time_format_default = esc_attr(get_option('time_format')); |
|
531 | 531 | $time_format_custom = ''; |
532 | 532 | |
533 | - if ( 'use_custom' == $time_format_option ) { |
|
534 | - $time_format_custom = esc_attr( get_post_meta( $this->id, '_calendar_time_format', true ) ); |
|
535 | - } elseif ( 'use_custom_php' ) { |
|
536 | - $time_format_custom = esc_attr( get_post_meta( $this->id, '_calendar_time_format_php', true ) ); |
|
533 | + if ('use_custom' == $time_format_option) { |
|
534 | + $time_format_custom = esc_attr(get_post_meta($this->id, '_calendar_time_format', true)); |
|
535 | + } elseif ('use_custom_php') { |
|
536 | + $time_format_custom = esc_attr(get_post_meta($this->id, '_calendar_time_format_php', true)); |
|
537 | 537 | } |
538 | 538 | } |
539 | 539 | |
@@ -547,13 +547,13 @@ discard block |
||
547 | 547 | * |
548 | 548 | * @param string $separator A UTF8 character used as separator. |
549 | 549 | */ |
550 | - public function set_datetime_separator( $separator = '' ) { |
|
550 | + public function set_datetime_separator($separator = '') { |
|
551 | 551 | |
552 | - if ( empty( $separator ) ) { |
|
553 | - $separator = get_post_meta( $this->id, '_calendar_datetime_separator', true ); |
|
552 | + if (empty($separator)) { |
|
553 | + $separator = get_post_meta($this->id, '_calendar_datetime_separator', true); |
|
554 | 554 | } |
555 | 555 | |
556 | - $this->datetime_separator = esc_attr( $separator ); |
|
556 | + $this->datetime_separator = esc_attr($separator); |
|
557 | 557 | } |
558 | 558 | |
559 | 559 | /** |
@@ -563,18 +563,18 @@ discard block |
||
563 | 563 | * |
564 | 564 | * @param int $weekday From 0 (Sunday) to 6 (Friday). |
565 | 565 | */ |
566 | - public function set_start_of_week( $weekday = -1 ) { |
|
566 | + public function set_start_of_week($weekday = -1) { |
|
567 | 567 | |
568 | - $week_starts = is_int( $weekday ) ? $weekday : -1; |
|
568 | + $week_starts = is_int($weekday) ? $weekday : -1; |
|
569 | 569 | |
570 | - if ( $week_starts < 0 || $week_starts > 6 ) { |
|
570 | + if ($week_starts < 0 || $week_starts > 6) { |
|
571 | 571 | |
572 | - $week_starts_setting = get_post_meta( $this->id, '_calendar_week_starts_on_setting', true ); |
|
573 | - $week_starts = intval( get_option( 'start_of_week' ) ); |
|
572 | + $week_starts_setting = get_post_meta($this->id, '_calendar_week_starts_on_setting', true); |
|
573 | + $week_starts = intval(get_option('start_of_week')); |
|
574 | 574 | |
575 | - if ( 'use_custom' == $week_starts_setting ) { |
|
576 | - $week_starts_on = get_post_meta( $this->id, '_calendar_week_starts_on', true ); |
|
577 | - $week_starts = is_numeric( $week_starts_on ) ? intval( $week_starts_on ) : $week_starts; |
|
575 | + if ('use_custom' == $week_starts_setting) { |
|
576 | + $week_starts_on = get_post_meta($this->id, '_calendar_week_starts_on', true); |
|
577 | + $week_starts = is_numeric($week_starts_on) ? intval($week_starts_on) : $week_starts; |
|
578 | 578 | } |
579 | 579 | } |
580 | 580 | |
@@ -588,51 +588,51 @@ discard block |
||
588 | 588 | * |
589 | 589 | * @param int $timestamp |
590 | 590 | */ |
591 | - public function set_start( $timestamp = 0 ) { |
|
591 | + public function set_start($timestamp = 0) { |
|
592 | 592 | |
593 | - if ( is_int( $timestamp ) && $timestamp !== 0 ) { |
|
593 | + if (is_int($timestamp) && $timestamp !== 0) { |
|
594 | 594 | $this->start = $timestamp; |
595 | 595 | return; |
596 | 596 | } |
597 | 597 | |
598 | - $this->start = Carbon::now( $this->timezone )->getTimestamp(); |
|
598 | + $this->start = Carbon::now($this->timezone)->getTimestamp(); |
|
599 | 599 | |
600 | - $calendar_begins = esc_attr( get_post_meta( $this->id, '_calendar_begins', true ) ); |
|
601 | - $nth = max( absint( get_post_meta( $this->id, '_calendar_begins_nth' ) ), 1 ); |
|
600 | + $calendar_begins = esc_attr(get_post_meta($this->id, '_calendar_begins', true)); |
|
601 | + $nth = max(absint(get_post_meta($this->id, '_calendar_begins_nth')), 1); |
|
602 | 602 | |
603 | - if ( 'today' == $calendar_begins ) { |
|
604 | - $this->start = Carbon::today( $this->timezone )->getTimestamp(); |
|
605 | - } elseif ( 'days_before' == $calendar_begins ) { |
|
606 | - $this->start = Carbon::today( $this->timezone )->subDays( $nth )->getTimestamp(); |
|
607 | - } elseif ( 'days_after' == $calendar_begins ) { |
|
608 | - $this->start = Carbon::today( $this->timezone )->addDays( $nth )->getTimestamp(); |
|
609 | - } elseif ( 'this_week' == $calendar_begins ) { |
|
610 | - $week = new Carbon( 'now', $this->timezone ); |
|
611 | - $week->setWeekStartsAt( $this->week_starts ); |
|
603 | + if ('today' == $calendar_begins) { |
|
604 | + $this->start = Carbon::today($this->timezone)->getTimestamp(); |
|
605 | + } elseif ('days_before' == $calendar_begins) { |
|
606 | + $this->start = Carbon::today($this->timezone)->subDays($nth)->getTimestamp(); |
|
607 | + } elseif ('days_after' == $calendar_begins) { |
|
608 | + $this->start = Carbon::today($this->timezone)->addDays($nth)->getTimestamp(); |
|
609 | + } elseif ('this_week' == $calendar_begins) { |
|
610 | + $week = new Carbon('now', $this->timezone); |
|
611 | + $week->setWeekStartsAt($this->week_starts); |
|
612 | 612 | $this->start = $week->startOfWeek()->getTimestamp(); |
613 | - } elseif ( 'weeks_before' == $calendar_begins ) { |
|
614 | - $week = new Carbon( 'now', $this->timezone ); |
|
615 | - $week->setWeekStartsAt( $this->week_starts ); |
|
616 | - $this->start = $week->startOfWeek()->subWeeks( $nth )->getTimestamp(); |
|
617 | - } elseif ( 'weeks_after' == $calendar_begins ) { |
|
618 | - $week = new Carbon( 'now', $this->timezone ); |
|
619 | - $week->setWeekStartsAt( $this->week_starts ); |
|
620 | - $this->start = $week->startOfWeek()->addWeeks( $nth )->getTimestamp(); |
|
621 | - } elseif ( 'this_month' == $calendar_begins ) { |
|
622 | - $this->start = Carbon::today( $this->timezone )->startOfMonth()->getTimeStamp(); |
|
623 | - } elseif ( 'months_before' == $calendar_begins ) { |
|
624 | - $this->start = Carbon::today( $this->timezone )->subMonths( $nth )->startOfMonth()->getTimeStamp(); |
|
625 | - } elseif ( 'months_after' == $calendar_begins ) { |
|
626 | - $this->start = Carbon::today( $this->timezone )->addMonths( $nth )->startOfMonth()->getTimeStamp(); |
|
627 | - } elseif ( 'this_year' == $calendar_begins ) { |
|
628 | - $this->start = Carbon::today( $this->timezone )->startOfYear()->getTimestamp(); |
|
629 | - } elseif ( 'years_before' == $calendar_begins ) { |
|
630 | - $this->start = Carbon::today( $this->timezone )->subYears( $nth )->startOfYear()->getTimeStamp(); |
|
631 | - } elseif ( 'years_after' == $calendar_begins ) { |
|
632 | - $this->start = Carbon::today( $this->timezone )->addYears( $nth )->startOfYear()->getTimeStamp(); |
|
633 | - } elseif ( 'custom_date' == $calendar_begins ) { |
|
634 | - if ( $date = get_post_meta( $this->id, '_calendar_begins_custom_date', true ) ) { |
|
635 | - $this->start = Carbon::createFromFormat( 'Y-m-d', esc_attr( $date ) )->setTimezone( $this->timezone )->getTimestamp(); |
|
613 | + } elseif ('weeks_before' == $calendar_begins) { |
|
614 | + $week = new Carbon('now', $this->timezone); |
|
615 | + $week->setWeekStartsAt($this->week_starts); |
|
616 | + $this->start = $week->startOfWeek()->subWeeks($nth)->getTimestamp(); |
|
617 | + } elseif ('weeks_after' == $calendar_begins) { |
|
618 | + $week = new Carbon('now', $this->timezone); |
|
619 | + $week->setWeekStartsAt($this->week_starts); |
|
620 | + $this->start = $week->startOfWeek()->addWeeks($nth)->getTimestamp(); |
|
621 | + } elseif ('this_month' == $calendar_begins) { |
|
622 | + $this->start = Carbon::today($this->timezone)->startOfMonth()->getTimeStamp(); |
|
623 | + } elseif ('months_before' == $calendar_begins) { |
|
624 | + $this->start = Carbon::today($this->timezone)->subMonths($nth)->startOfMonth()->getTimeStamp(); |
|
625 | + } elseif ('months_after' == $calendar_begins) { |
|
626 | + $this->start = Carbon::today($this->timezone)->addMonths($nth)->startOfMonth()->getTimeStamp(); |
|
627 | + } elseif ('this_year' == $calendar_begins) { |
|
628 | + $this->start = Carbon::today($this->timezone)->startOfYear()->getTimestamp(); |
|
629 | + } elseif ('years_before' == $calendar_begins) { |
|
630 | + $this->start = Carbon::today($this->timezone)->subYears($nth)->startOfYear()->getTimeStamp(); |
|
631 | + } elseif ('years_after' == $calendar_begins) { |
|
632 | + $this->start = Carbon::today($this->timezone)->addYears($nth)->startOfYear()->getTimeStamp(); |
|
633 | + } elseif ('custom_date' == $calendar_begins) { |
|
634 | + if ($date = get_post_meta($this->id, '_calendar_begins_custom_date', true)) { |
|
635 | + $this->start = Carbon::createFromFormat('Y-m-d', esc_attr($date))->setTimezone($this->timezone)->getTimestamp(); |
|
636 | 636 | } |
637 | 637 | } |
638 | 638 | } |
@@ -644,8 +644,8 @@ discard block |
||
644 | 644 | * |
645 | 645 | * @param int $timestamp |
646 | 646 | */ |
647 | - public function set_end( $timestamp = 0 ) { |
|
648 | - $latest = is_int( $timestamp ) && $timestamp !== 0 ? $timestamp : $this->latest_event; |
|
647 | + public function set_end($timestamp = 0) { |
|
648 | + $latest = is_int($timestamp) && $timestamp !== 0 ? $timestamp : $this->latest_event; |
|
649 | 649 | $this->end = $latest > $this->start ? $latest : $this->start; |
650 | 650 | } |
651 | 651 | |
@@ -656,14 +656,14 @@ discard block |
||
656 | 656 | * |
657 | 657 | * @param string|bool $static |
658 | 658 | */ |
659 | - public function set_static( $static = '' ) { |
|
659 | + public function set_static($static = '') { |
|
660 | 660 | |
661 | - if ( ! empty( $static ) && is_bool( $static ) ) { |
|
661 | + if ( ! empty($static) && is_bool($static)) { |
|
662 | 662 | $this->static = $static; |
663 | 663 | return; |
664 | 664 | } |
665 | 665 | |
666 | - if ( 'yes' == get_post_meta( $this->id, '_calendar_is_static', true ) ) { |
|
666 | + if ('yes' == get_post_meta($this->id, '_calendar_is_static', true)) { |
|
667 | 667 | $this->static = true; |
668 | 668 | return; |
669 | 669 | } |
@@ -691,7 +691,7 @@ discard block |
||
691 | 691 | * |
692 | 692 | * @return Calendar_View |
693 | 693 | */ |
694 | - abstract public function get_view( $view = '' ); |
|
694 | + abstract public function get_view($view = ''); |
|
695 | 695 | |
696 | 696 | /** |
697 | 697 | * Get event HTML parsed by template. |
@@ -703,11 +703,11 @@ discard block |
||
703 | 703 | * |
704 | 704 | * @return string |
705 | 705 | */ |
706 | - public function get_event_html( Event $event, $template = '' ) { |
|
707 | - $event_builder = new Event_Builder( $event, $this ); |
|
706 | + public function get_event_html(Event $event, $template = '') { |
|
707 | + $event_builder = new Event_Builder($event, $this); |
|
708 | 708 | // Use the event template to parse tags; if empty, fallback to calendar post content. |
709 | - $template = empty( $template ) ? ( empty( $event->template ) ? $this->events_template : $event->template ) : $template; |
|
710 | - return $event_builder->parse_event_template_tags( $template ); |
|
709 | + $template = empty($template) ? (empty($event->template) ? $this->events_template : $event->template) : $template; |
|
710 | + return $event_builder->parse_event_template_tags($template); |
|
711 | 711 | } |
712 | 712 | |
713 | 713 | /** |
@@ -717,57 +717,57 @@ discard block |
||
717 | 717 | * |
718 | 718 | * @param string $view The calendar view to display. |
719 | 719 | */ |
720 | - public function html( $view = '' ) { |
|
720 | + public function html($view = '') { |
|
721 | 721 | |
722 | - $view = empty( $view ) ? $this->view : $this->get_view( $view ); |
|
722 | + $view = empty($view) ? $this->view : $this->get_view($view); |
|
723 | 723 | |
724 | - if ( $view instanceof Calendar_View ) { |
|
724 | + if ($view instanceof Calendar_View) { |
|
725 | 725 | |
726 | - if ( ! empty( $this->errors ) ) { |
|
726 | + if ( ! empty($this->errors)) { |
|
727 | 727 | |
728 | - if ( current_user_can( 'manage_options' ) ) { |
|
728 | + if (current_user_can('manage_options')) { |
|
729 | 729 | echo '<pre><code>'; |
730 | - foreach ( $this->errors as $error ) { echo $error; } |
|
730 | + foreach ($this->errors as $error) { echo $error; } |
|
731 | 731 | echo '</code></pre>'; |
732 | 732 | } |
733 | 733 | |
734 | 734 | } else { |
735 | 735 | |
736 | 736 | // Get a CSS class from the class name of the calendar view (minus namespace part). |
737 | - $view_name = implode( '-', array_map( 'lcfirst', explode( '_', strtolower( get_class( $view ) ) ) ) ); |
|
738 | - $view_class = substr( $view_name, strrpos( $view_name, '\\' ) + 1 ); |
|
737 | + $view_name = implode('-', array_map('lcfirst', explode('_', strtolower(get_class($view))))); |
|
738 | + $view_class = substr($view_name, strrpos($view_name, '\\') + 1); |
|
739 | 739 | |
740 | - $calendar_class = trim( implode( ' simcal-', apply_filters( 'simcal_calendar_class', array( |
|
740 | + $calendar_class = trim(implode(' simcal-', apply_filters('simcal_calendar_class', array( |
|
741 | 741 | 'simcal-calendar', |
742 | 742 | $this->type, |
743 | 743 | $view_class, |
744 | - ), $this->id ) ) ); |
|
745 | - |
|
746 | - echo '<div class="' . $calendar_class . '" ' |
|
747 | - . 'data-calendar-id="' . $this->id . '" ' |
|
748 | - . 'data-timezone="' . $this->timezone . '" ' |
|
749 | - . 'data-offset="' . $this->offset . '" ' |
|
750 | - . 'data-week-start="' . $this->week_starts . '" ' |
|
751 | - . 'data-calendar-start="' . $this->start .'" ' |
|
752 | - . 'data-calendar-end="' . $this->end . '" ' |
|
753 | - . 'data-events-first="' . $this->earliest_event .'" ' |
|
754 | - . 'data-events-last="' . $this->latest_event . '"' |
|
744 | + ), $this->id))); |
|
745 | + |
|
746 | + echo '<div class="'.$calendar_class.'" ' |
|
747 | + . 'data-calendar-id="'.$this->id.'" ' |
|
748 | + . 'data-timezone="'.$this->timezone.'" ' |
|
749 | + . 'data-offset="'.$this->offset.'" ' |
|
750 | + . 'data-week-start="'.$this->week_starts.'" ' |
|
751 | + . 'data-calendar-start="'.$this->start.'" ' |
|
752 | + . 'data-calendar-end="'.$this->end.'" ' |
|
753 | + . 'data-events-first="'.$this->earliest_event.'" ' |
|
754 | + . 'data-events-last="'.$this->latest_event.'"' |
|
755 | 755 | . '>'; |
756 | 756 | |
757 | - date_default_timezone_set( $this->timezone ); |
|
758 | - do_action( 'simcal_calendar_html_before', $this->id ); |
|
757 | + date_default_timezone_set($this->timezone); |
|
758 | + do_action('simcal_calendar_html_before', $this->id); |
|
759 | 759 | |
760 | 760 | $view->html(); |
761 | 761 | |
762 | - do_action( 'simcal_calendar_html_after', $this->id ); |
|
763 | - date_default_timezone_set( $this->site_timezone ); |
|
762 | + do_action('simcal_calendar_html_after', $this->id); |
|
763 | + date_default_timezone_set($this->site_timezone); |
|
764 | 764 | |
765 | - $settings = get_option( 'simple-calendar_settings_calendars' ); |
|
766 | - $poweredby = isset( $settings['poweredby']['opt_in'] ) ? $settings['poweredby']['opt_in'] : ''; |
|
765 | + $settings = get_option('simple-calendar_settings_calendars'); |
|
766 | + $poweredby = isset($settings['poweredby']['opt_in']) ? $settings['poweredby']['opt_in'] : ''; |
|
767 | 767 | |
768 | - if ( 'yes' == $poweredby ) { |
|
768 | + if ('yes' == $poweredby) { |
|
769 | 769 | $align = is_rtl() ? 'left' : 'right'; |
770 | - echo '<small class="simcal-powered simcal-align-' . $align .'">Powered by <a href="https://simplecalendar.io" target="_blank">Simple Calendar</a></small>'; |
|
770 | + echo '<small class="simcal-powered simcal-align-'.$align.'">Powered by <a href="https://simplecalendar.io" target="_blank">Simple Calendar</a></small>'; |
|
771 | 771 | } |
772 | 772 | |
773 | 773 | echo '</div>'; |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | |
9 | 9 | use Carbon\Carbon; |
10 | 10 | |
11 | -if ( ! defined( 'ABSPATH' ) ) { |
|
11 | +if ( ! defined('ABSPATH')) { |
|
12 | 12 | exit; |
13 | 13 | } |
14 | 14 | |
@@ -132,22 +132,22 @@ discard block |
||
132 | 132 | * |
133 | 133 | * @param string|Calendar $calendar |
134 | 134 | */ |
135 | - public function __construct( $calendar = '' ) { |
|
135 | + public function __construct($calendar = '') { |
|
136 | 136 | |
137 | - if ( $calendar instanceof Calendar ) { |
|
137 | + if ($calendar instanceof Calendar) { |
|
138 | 138 | |
139 | - if ( isset( $calendar->id ) ) { |
|
139 | + if (isset($calendar->id)) { |
|
140 | 140 | $this->post_id = $calendar->id; |
141 | 141 | } |
142 | - if ( isset( $calendar->start ) ) { |
|
142 | + if (isset($calendar->start)) { |
|
143 | 143 | $this->calendar_start = $calendar->start; |
144 | 144 | } |
145 | - $this->week_starts = isset( $calendar->week_starts ) ? $calendar->week_starts : get_option( 'start_of_week' ); |
|
146 | - $this->events_template = ! empty( $calendar->events_template ) ? $calendar->events_template : simcal_default_event_template(); |
|
145 | + $this->week_starts = isset($calendar->week_starts) ? $calendar->week_starts : get_option('start_of_week'); |
|
146 | + $this->events_template = ! empty($calendar->events_template) ? $calendar->events_template : simcal_default_event_template(); |
|
147 | 147 | |
148 | - if ( $this->post_id > 0 ) { |
|
148 | + if ($this->post_id > 0) { |
|
149 | 149 | $this->set_cache(); |
150 | - $this->timezone_setting = get_post_meta( $this->post_id, '_feed_timezone_setting', true ); |
|
150 | + $this->timezone_setting = get_post_meta($this->post_id, '_feed_timezone_setting', true); |
|
151 | 151 | $this->timezone = $calendar->timezone; |
152 | 152 | $this->set_earliest_event(); |
153 | 153 | $this->set_latest_event(); |
@@ -173,25 +173,25 @@ discard block |
||
173 | 173 | * |
174 | 174 | * @param int $timestamp |
175 | 175 | */ |
176 | - public function set_earliest_event( $timestamp = 0 ) { |
|
176 | + public function set_earliest_event($timestamp = 0) { |
|
177 | 177 | |
178 | - $earliest = intval( $timestamp ); |
|
178 | + $earliest = intval($timestamp); |
|
179 | 179 | |
180 | - if ( $earliest === 0 ) { |
|
180 | + if ($earliest === 0) { |
|
181 | 181 | |
182 | - $start = Carbon::createFromTimestamp( $this->calendar_start, $this->timezone ); |
|
182 | + $start = Carbon::createFromTimestamp($this->calendar_start, $this->timezone); |
|
183 | 183 | |
184 | - $earliest_date = esc_attr( get_post_meta( $this->post_id, '_feed_earliest_event_date', true ) ); |
|
185 | - $earliest_range = max( absint( get_post_meta( $this->post_id, '_feed_earliest_event_date_range', true ) ), 1 ); |
|
184 | + $earliest_date = esc_attr(get_post_meta($this->post_id, '_feed_earliest_event_date', true)); |
|
185 | + $earliest_range = max(absint(get_post_meta($this->post_id, '_feed_earliest_event_date_range', true)), 1); |
|
186 | 186 | |
187 | - if ( 'days_before' == $earliest_date ) { |
|
188 | - $earliest = $start->subDays( $earliest_range )->getTimestamp(); |
|
189 | - } elseif ( 'weeks_before' == $earliest_date ) { |
|
190 | - $earliest = $start->subWeeks( $earliest_range )->addDay()->getTimestamp(); |
|
191 | - } elseif ( 'months_before' == $earliest_date ) { |
|
192 | - $earliest = $start->subMonths( $earliest_range )->addDay()->getTimestamp(); |
|
193 | - } elseif ( 'years_before' == $earliest_date ) { |
|
194 | - $earliest = $start->subYears( $earliest_range )->addDay()->getTimestamp(); |
|
187 | + if ('days_before' == $earliest_date) { |
|
188 | + $earliest = $start->subDays($earliest_range)->getTimestamp(); |
|
189 | + } elseif ('weeks_before' == $earliest_date) { |
|
190 | + $earliest = $start->subWeeks($earliest_range)->addDay()->getTimestamp(); |
|
191 | + } elseif ('months_before' == $earliest_date) { |
|
192 | + $earliest = $start->subMonths($earliest_range)->addDay()->getTimestamp(); |
|
193 | + } elseif ('years_before' == $earliest_date) { |
|
194 | + $earliest = $start->subYears($earliest_range)->addDay()->getTimestamp(); |
|
195 | 195 | } else { |
196 | 196 | $earliest = $start->getTimestamp(); |
197 | 197 | } |
@@ -207,25 +207,25 @@ discard block |
||
207 | 207 | * |
208 | 208 | * @param int $timestamp |
209 | 209 | */ |
210 | - public function set_latest_event( $timestamp = 0 ) { |
|
210 | + public function set_latest_event($timestamp = 0) { |
|
211 | 211 | |
212 | - $latest = intval( $timestamp ); |
|
212 | + $latest = intval($timestamp); |
|
213 | 213 | |
214 | - if ( $latest === 0 ) { |
|
214 | + if ($latest === 0) { |
|
215 | 215 | |
216 | - $start = Carbon::createFromTimestamp( $this->calendar_start, $this->timezone )->endOfDay(); |
|
216 | + $start = Carbon::createFromTimestamp($this->calendar_start, $this->timezone)->endOfDay(); |
|
217 | 217 | |
218 | - $latest_date = esc_attr( get_post_meta( $this->post_id, '_feed_latest_event_date', true ) ); |
|
219 | - $latest_range = max( absint( get_post_meta( $this->post_id, '_feed_latest_event_date_range', true ) ), 1 ); |
|
218 | + $latest_date = esc_attr(get_post_meta($this->post_id, '_feed_latest_event_date', true)); |
|
219 | + $latest_range = max(absint(get_post_meta($this->post_id, '_feed_latest_event_date_range', true)), 1); |
|
220 | 220 | |
221 | - if ( 'days_after' == $latest_date ) { |
|
222 | - $latest = $start->addDays( $latest_range )->getTimestamp(); |
|
223 | - } elseif ( 'weeks_after' == $latest_date ) { |
|
224 | - $latest = $start->addWeeks( $latest_range )->subDay()->getTimestamp(); |
|
225 | - } elseif ( 'months_after' == $latest_date ) { |
|
226 | - $latest = $start->addMonths( $latest_range )->subDay()->getTimestamp(); |
|
227 | - } elseif ( 'years_after' == $latest_date ) { |
|
228 | - $latest = $start->addYears( $latest_range )->subDay()->getTimestamp(); |
|
221 | + if ('days_after' == $latest_date) { |
|
222 | + $latest = $start->addDays($latest_range)->getTimestamp(); |
|
223 | + } elseif ('weeks_after' == $latest_date) { |
|
224 | + $latest = $start->addWeeks($latest_range)->subDay()->getTimestamp(); |
|
225 | + } elseif ('months_after' == $latest_date) { |
|
226 | + $latest = $start->addMonths($latest_range)->subDay()->getTimestamp(); |
|
227 | + } elseif ('years_after' == $latest_date) { |
|
228 | + $latest = $start->addYears($latest_range)->subDay()->getTimestamp(); |
|
229 | 229 | } else { |
230 | 230 | $latest = $start->getTimestamp(); |
231 | 231 | } |
@@ -242,12 +242,12 @@ discard block |
||
242 | 242 | * |
243 | 243 | * @param int $time |
244 | 244 | */ |
245 | - public function set_cache( $time = 0 ) { |
|
246 | - if ( $time === 0 || ! is_numeric( $time ) ) { |
|
247 | - $cache = get_post_meta( $this->post_id, '_feed_cache', true ); |
|
248 | - $time = is_numeric( $cache ) && $cache > 0 ? absint( $cache ) : $this->cache; |
|
245 | + public function set_cache($time = 0) { |
|
246 | + if ($time === 0 || ! is_numeric($time)) { |
|
247 | + $cache = get_post_meta($this->post_id, '_feed_cache', true); |
|
248 | + $time = is_numeric($cache) && $cache > 0 ? absint($cache) : $this->cache; |
|
249 | 249 | } |
250 | - $this->cache = absint( $time ); |
|
250 | + $this->cache = absint($time); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | /** |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | */ |
7 | 7 | namespace SimpleCalendar\Abstracts; |
8 | 8 | |
9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
9 | +if ( ! defined('ABSPATH')) { |
|
10 | 10 | exit; |
11 | 11 | } |
12 | 12 | |
@@ -148,68 +148,68 @@ discard block |
||
148 | 148 | * |
149 | 149 | * @param array $field Field data. |
150 | 150 | */ |
151 | - public function __construct( $field ) { |
|
151 | + public function __construct($field) { |
|
152 | 152 | |
153 | 153 | // Field properties. |
154 | - if ( isset( $field['title'] ) ) { |
|
155 | - $this->title = esc_attr( $field['title'] ); |
|
154 | + if (isset($field['title'])) { |
|
155 | + $this->title = esc_attr($field['title']); |
|
156 | 156 | } |
157 | - if ( isset( $field['description'] ) ) { |
|
158 | - $this->description = wp_kses_post( $field['description'] ); |
|
157 | + if (isset($field['description'])) { |
|
158 | + $this->description = wp_kses_post($field['description']); |
|
159 | 159 | } |
160 | - if ( isset( $field['type'] ) ) { |
|
161 | - $this->type = esc_attr( $field['type'] ); |
|
160 | + if (isset($field['type'])) { |
|
161 | + $this->type = esc_attr($field['type']); |
|
162 | 162 | } |
163 | - if ( isset( $field['name'] ) ) { |
|
164 | - $this->name = esc_attr( $field['name'] ); |
|
163 | + if (isset($field['name'])) { |
|
164 | + $this->name = esc_attr($field['name']); |
|
165 | 165 | } |
166 | - if ( isset( $field['id'] ) ) { |
|
167 | - $this->id = esc_attr( $field['id'] ); |
|
166 | + if (isset($field['id'])) { |
|
167 | + $this->id = esc_attr($field['id']); |
|
168 | 168 | } |
169 | - if ( isset( $field['placeholder'] ) ) { |
|
170 | - $this->placeholder = esc_attr( $field['placeholder'] ); |
|
169 | + if (isset($field['placeholder'])) { |
|
170 | + $this->placeholder = esc_attr($field['placeholder']); |
|
171 | 171 | } |
172 | - if ( isset( $field['options'] ) && is_array( $field['options'] ) ) { |
|
173 | - $this->options = array_map( 'esc_attr', $field['options'] ); |
|
172 | + if (isset($field['options']) && is_array($field['options'])) { |
|
173 | + $this->options = array_map('esc_attr', $field['options']); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | // Escaping. |
177 | - if ( ! empty( $field['escaping'] ) && ( is_string( $field['escaping'] ) || is_array( $field['escaping'] ) ) ) { |
|
178 | - if ( isset( $field['default'] ) ) { |
|
179 | - $this->default = $this->escape_callback( $field['escaping'], $field['default'] ); |
|
177 | + if ( ! empty($field['escaping']) && (is_string($field['escaping']) || is_array($field['escaping']))) { |
|
178 | + if (isset($field['default'])) { |
|
179 | + $this->default = $this->escape_callback($field['escaping'], $field['default']); |
|
180 | 180 | } |
181 | - if ( isset( $field['value'] ) ) { |
|
182 | - $this->value = $this->escape_callback( $field['escaping'], $field['value'] ); |
|
181 | + if (isset($field['value'])) { |
|
182 | + $this->value = $this->escape_callback($field['escaping'], $field['value']); |
|
183 | 183 | } |
184 | 184 | } else { |
185 | - if ( isset( $field['default'] ) ) { |
|
186 | - $this->default = $this->escape( $field['default'] ); |
|
185 | + if (isset($field['default'])) { |
|
186 | + $this->default = $this->escape($field['default']); |
|
187 | 187 | } |
188 | - if ( isset( $field['value'] ) ) { |
|
189 | - $this->value = $this->escape( $field['value'] ); |
|
188 | + if (isset($field['value'])) { |
|
189 | + $this->value = $this->escape($field['value']); |
|
190 | 190 | } |
191 | 191 | } |
192 | 192 | |
193 | 193 | // Validation. |
194 | - if ( ! empty( $field['validation'] ) ) { |
|
195 | - $this->validation = $this->validate( $field['validation'], $this->value ); |
|
194 | + if ( ! empty($field['validation'])) { |
|
195 | + $this->validation = $this->validate($field['validation'], $this->value); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | // CSS classes and styles. |
199 | - $classes = isset( $field['class'] ) ? $field['class'] : ''; |
|
200 | - $this->set_class( $classes ); |
|
201 | - if ( isset( $field['style'] ) ) { |
|
202 | - $this->set_style( $field['style'] ); |
|
199 | + $classes = isset($field['class']) ? $field['class'] : ''; |
|
200 | + $this->set_class($classes); |
|
201 | + if (isset($field['style'])) { |
|
202 | + $this->set_style($field['style']); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | // Custom attributes. |
206 | - if ( isset( $field['attributes'] ) ) { |
|
207 | - $this->set_attributes( $field['attributes'] ); |
|
206 | + if (isset($field['attributes'])) { |
|
207 | + $this->set_attributes($field['attributes']); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | // Tooltip markup. |
211 | - if ( isset( $field['tooltip'] ) ) { |
|
212 | - $this->tooltip = ' <i class="simcal-icon-help simcal-help-tip" data-tip="' . esc_attr( $field['tooltip'] ) . '"></i> ' ; |
|
211 | + if (isset($field['tooltip'])) { |
|
212 | + $this->tooltip = ' <i class="simcal-icon-help simcal-help-tip" data-tip="'.esc_attr($field['tooltip']).'"></i> '; |
|
213 | 213 | } |
214 | 214 | } |
215 | 215 | |
@@ -222,13 +222,13 @@ discard block |
||
222 | 222 | * |
223 | 223 | * @return void |
224 | 224 | */ |
225 | - public function set_attributes( $attributes ) { |
|
225 | + public function set_attributes($attributes) { |
|
226 | 226 | |
227 | 227 | $attr = ''; |
228 | 228 | |
229 | - if ( ! empty( $attributes ) && is_array( $attributes ) ) { |
|
230 | - foreach ( $attributes as $k => $v ) { |
|
231 | - $attr .= esc_attr( $k ) . '="' . esc_attr( $v ) . '" '; |
|
229 | + if ( ! empty($attributes) && is_array($attributes)) { |
|
230 | + foreach ($attributes as $k => $v) { |
|
231 | + $attr .= esc_attr($k).'="'.esc_attr($v).'" '; |
|
232 | 232 | } |
233 | 233 | } |
234 | 234 | |
@@ -244,13 +244,13 @@ discard block |
||
244 | 244 | * |
245 | 245 | * @return void |
246 | 246 | */ |
247 | - public function set_style( $css ) { |
|
247 | + public function set_style($css) { |
|
248 | 248 | |
249 | 249 | $styles = ''; |
250 | 250 | |
251 | - if ( ! empty( $css ) && is_array( $css ) ) { |
|
252 | - foreach ( $css as $k => $v ) { |
|
253 | - $styles .= esc_attr( $k ) . ': ' . esc_attr( $v ) . '; '; |
|
251 | + if ( ! empty($css) && is_array($css)) { |
|
252 | + foreach ($css as $k => $v) { |
|
253 | + $styles .= esc_attr($k).': '.esc_attr($v).'; '; |
|
254 | 254 | } |
255 | 255 | } |
256 | 256 | |
@@ -266,23 +266,23 @@ discard block |
||
266 | 266 | * |
267 | 267 | * @return void |
268 | 268 | */ |
269 | - public function set_class( $class ) { |
|
269 | + public function set_class($class) { |
|
270 | 270 | |
271 | 271 | $classes = ''; |
272 | 272 | $type_class = ''; |
273 | 273 | $error = ''; |
274 | 274 | |
275 | - if ( ! empty( $class ) && is_array( $class ) ) { |
|
276 | - $classes = implode( ' ', array_map( 'esc_attr', $class ) ); |
|
275 | + if ( ! empty($class) && is_array($class)) { |
|
276 | + $classes = implode(' ', array_map('esc_attr', $class)); |
|
277 | 277 | } |
278 | - if ( ! empty( $this->type_class ) ) { |
|
279 | - $type_class = esc_attr( $this->type_class ); |
|
278 | + if ( ! empty($this->type_class)) { |
|
279 | + $type_class = esc_attr($this->type_class); |
|
280 | 280 | } |
281 | - if ( true !== $this->validation && ! empty( $this->validation ) ) { |
|
281 | + if (true !== $this->validation && ! empty($this->validation)) { |
|
282 | 282 | $error = 'simcal-field-error '; |
283 | 283 | } |
284 | 284 | |
285 | - $this->class = trim( $error . 'simcal-field ' . $type_class . ' ' . $classes ); |
|
285 | + $this->class = trim($error.'simcal-field '.$type_class.' '.$classes); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | /** |
@@ -297,8 +297,8 @@ discard block |
||
297 | 297 | * |
298 | 298 | * @return array|string |
299 | 299 | */ |
300 | - protected function escape( $value ) { |
|
301 | - return ! empty( $value ) ? ( is_array( $value ) ? array_map( 'esc_attr', $value ) : esc_attr( $value ) ) : ''; |
|
300 | + protected function escape($value) { |
|
301 | + return ! empty($value) ? (is_array($value) ? array_map('esc_attr', $value) : esc_attr($value)) : ''; |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | /** |
@@ -314,11 +314,11 @@ discard block |
||
314 | 314 | * |
315 | 315 | * @return mixed |
316 | 316 | */ |
317 | - protected function escape_callback( $callback, $value ) { |
|
318 | - if ( $callback && ( is_string( $callback ) || is_array( $callback ) ) ) { |
|
319 | - return call_user_func( $callback, $value ); |
|
317 | + protected function escape_callback($callback, $value) { |
|
318 | + if ($callback && (is_string($callback) || is_array($callback))) { |
|
319 | + return call_user_func($callback, $value); |
|
320 | 320 | } |
321 | - return esc_attr( $value ); |
|
321 | + return esc_attr($value); |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | /** |
@@ -334,10 +334,10 @@ discard block |
||
334 | 334 | * |
335 | 335 | * @return true|string Expected to return bool (true) if passes, message string if not. |
336 | 336 | */ |
337 | - protected function validate( $callback, $value ) { |
|
338 | - if ( $callback && ( is_string( $callback ) || is_array( $callback ) ) ) { |
|
339 | - $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : ''; |
|
340 | - return call_user_func( $callback, $value, $screen ); |
|
337 | + protected function validate($callback, $value) { |
|
338 | + if ($callback && (is_string($callback) || is_array($callback))) { |
|
339 | + $screen = function_exists('get_current_screen') ? get_current_screen() : ''; |
|
340 | + return call_user_func($callback, $value, $screen); |
|
341 | 341 | } |
342 | 342 | return true; |
343 | 343 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | */ |
7 | 7 | namespace SimpleCalendar\Abstracts; |
8 | 8 | |
9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
9 | +if ( ! defined('ABSPATH')) { |
|
10 | 10 | exit; |
11 | 11 | } |
12 | 12 | |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | * |
29 | 29 | * @return void |
30 | 30 | */ |
31 | - public static function html( $post ); |
|
31 | + public static function html($post); |
|
32 | 32 | |
33 | 33 | /** |
34 | 34 | * Validate and save the meta box fields. |
@@ -40,6 +40,6 @@ discard block |
||
40 | 40 | * |
41 | 41 | * @return void |
42 | 42 | */ |
43 | - public static function save( $post_id, $post ); |
|
43 | + public static function save($post_id, $post); |
|
44 | 44 | |
45 | 45 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | */ |
7 | 7 | namespace SimpleCalendar\Abstracts; |
8 | 8 | |
9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
9 | +if ( ! defined('ABSPATH')) { |
|
10 | 10 | exit; |
11 | 11 | } |
12 | 12 | |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | * |
37 | 37 | * @return void |
38 | 38 | */ |
39 | - public function widget( $args, $instance ); |
|
39 | + public function widget($args, $instance); |
|
40 | 40 | |
41 | 41 | /** |
42 | 42 | * Update a particular instance of the widget. |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * |
53 | 53 | * @return array Settings to save or bool false to cancel saving. |
54 | 54 | */ |
55 | - public function update( $new_instance, $old_instance ); |
|
55 | + public function update($new_instance, $old_instance); |
|
56 | 56 | |
57 | 57 | /** |
58 | 58 | * Print the settings update form. |
@@ -63,6 +63,6 @@ discard block |
||
63 | 63 | * |
64 | 64 | * @return string |
65 | 65 | */ |
66 | - public function form( $instance ); |
|
66 | + public function form($instance); |
|
67 | 67 | |
68 | 68 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | */ |
7 | 7 | namespace SimpleCalendar\Admin; |
8 | 8 | |
9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
9 | +if ( ! defined('ABSPATH')) { |
|
10 | 10 | exit; |
11 | 11 | } |
12 | 12 | |
@@ -25,19 +25,19 @@ discard block |
||
25 | 25 | public function __construct() { |
26 | 26 | |
27 | 27 | // Set an option if the user rated the plugin. |
28 | - add_action( 'wp_ajax_simcal_rated', array( $this, 'rate_plugin' ) ); |
|
28 | + add_action('wp_ajax_simcal_rated', array($this, 'rate_plugin')); |
|
29 | 29 | |
30 | 30 | // Set an option if the user rated the plugin. |
31 | - add_action( 'wp_ajax_simcal_clear_cache', array( $this, 'clear_cache' ) ); |
|
31 | + add_action('wp_ajax_simcal_clear_cache', array($this, 'clear_cache')); |
|
32 | 32 | |
33 | 33 | // Convert a datetime format. |
34 | - add_action( 'wp_ajax_simcal_date_i18n_input_preview', array( $this, 'date_i18n' ) ); |
|
34 | + add_action('wp_ajax_simcal_date_i18n_input_preview', array($this, 'date_i18n')); |
|
35 | 35 | |
36 | 36 | // Manage an add-on license activation or deactivation. |
37 | - add_action( 'wp_ajax_simcal_manage_add_on_license', array( $this, 'manage_add_on_license' ) ); |
|
37 | + add_action('wp_ajax_simcal_manage_add_on_license', array($this, 'manage_add_on_license')); |
|
38 | 38 | |
39 | 39 | // Reset add-ons licenses. |
40 | - add_action( 'wp_ajax_simcal_reset_add_ons_licenses', array( $this, 'reset_licenses' ) ); |
|
40 | + add_action('wp_ajax_simcal_reset_add_ons_licenses', array($this, 'reset_licenses')); |
|
41 | 41 | |
42 | 42 | } |
43 | 43 | |
@@ -48,10 +48,10 @@ discard block |
||
48 | 48 | */ |
49 | 49 | public function clear_cache() { |
50 | 50 | |
51 | - $id = isset( $_POST['id'] ) ? ( is_array( $_POST['id'] ) ? array_map( 'intval', $_POST['id'] ) : intval( $_POST['id'] ) ) : ''; |
|
51 | + $id = isset($_POST['id']) ? (is_array($_POST['id']) ? array_map('intval', $_POST['id']) : intval($_POST['id'])) : ''; |
|
52 | 52 | |
53 | - if ( ! empty( $id ) ) { |
|
54 | - simcal_delete_feed_transients( $id ); |
|
53 | + if ( ! empty($id)) { |
|
54 | + simcal_delete_feed_transients($id); |
|
55 | 55 | } |
56 | 56 | } |
57 | 57 | |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | * @since 3.0.0 |
62 | 62 | */ |
63 | 63 | public function rate_plugin() { |
64 | - update_option( 'simple-calendar_admin_footer_text_rated', date( 'Y-m-d', time() ) ); |
|
64 | + update_option('simple-calendar_admin_footer_text_rated', date('Y-m-d', time())); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -71,10 +71,10 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function date_i18n() { |
73 | 73 | |
74 | - $value = isset( $_POST['value'] ) ? sanitize_text_field( $_POST['value'] ) : ' '; |
|
75 | - $timestamp = isset( $_POST['timestamp'] ) ? absint( $_POST['timestamp'] ) : time(); |
|
74 | + $value = isset($_POST['value']) ? sanitize_text_field($_POST['value']) : ' '; |
|
75 | + $timestamp = isset($_POST['timestamp']) ? absint($_POST['timestamp']) : time(); |
|
76 | 76 | |
77 | - wp_send_json_success( date_i18n( $value, $timestamp ) ); |
|
77 | + wp_send_json_success(date_i18n($value, $timestamp)); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -86,35 +86,35 @@ discard block |
||
86 | 86 | */ |
87 | 87 | public function manage_add_on_license() { |
88 | 88 | |
89 | - $addon = isset( $_POST['add_on'] ) ? sanitize_key( $_POST['add_on'] ) : false; |
|
90 | - $action = isset( $_POST['license_action'] ) ? esc_attr( $_POST['license_action'] ) : false; |
|
91 | - $key = isset( $_POST['license_key'] ) ? esc_attr( $_POST['license_key'] ) : ''; |
|
92 | - $nonce = isset( $_POST['nonce'] ) ? esc_attr( $_POST['nonce'] ) : ''; |
|
89 | + $addon = isset($_POST['add_on']) ? sanitize_key($_POST['add_on']) : false; |
|
90 | + $action = isset($_POST['license_action']) ? esc_attr($_POST['license_action']) : false; |
|
91 | + $key = isset($_POST['license_key']) ? esc_attr($_POST['license_key']) : ''; |
|
92 | + $nonce = isset($_POST['nonce']) ? esc_attr($_POST['nonce']) : ''; |
|
93 | 93 | |
94 | 94 | // Verify that there are valid variables to process. |
95 | - if ( false === $addon || ! in_array( $action, array( 'activate_license', 'deactivate_license' ) ) ) { |
|
96 | - wp_send_json_error( __( 'Add-on unspecified or invalid action.', 'google-calendar-events' ) ); |
|
95 | + if (false === $addon || ! in_array($action, array('activate_license', 'deactivate_license'))) { |
|
96 | + wp_send_json_error(__('Add-on unspecified or invalid action.', 'google-calendar-events')); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | // Verify this request comes from the add-ons licenses activation settings page. |
100 | - if ( ! wp_verify_nonce( $nonce, 'simcal_license_manager' ) ) { |
|
101 | - wp_send_json_error( sprintf( __( 'An error occurred: %s', 'google-calendar-events' ), 'Nonce verification failed.' ) ); |
|
100 | + if ( ! wp_verify_nonce($nonce, 'simcal_license_manager')) { |
|
101 | + wp_send_json_error(sprintf(__('An error occurred: %s', 'google-calendar-events'), 'Nonce verification failed.')); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | // Removes the prefix and converts simcal_{id_no} to {id_no}. |
105 | - $id = intval( substr( $addon, 7 ) ); |
|
105 | + $id = intval(substr($addon, 7)); |
|
106 | 106 | |
107 | 107 | // Data to send in API request. |
108 | 108 | $api_request = array( |
109 | 109 | 'edd_action' => $action, |
110 | 110 | 'license' => $key, |
111 | - 'item_id' => urlencode( $id ), |
|
111 | + 'item_id' => urlencode($id), |
|
112 | 112 | 'url' => home_url() |
113 | 113 | ); |
114 | 114 | |
115 | 115 | // Call the custom API. |
116 | 116 | $response = wp_remote_post( |
117 | - defined( 'SIMPLE_CALENDAR_STORE_URL' ) ? SIMPLE_CALENDAR_STORE_URL : simcal_get_url( 'home' ), |
|
117 | + defined('SIMPLE_CALENDAR_STORE_URL') ? SIMPLE_CALENDAR_STORE_URL : simcal_get_url('home'), |
|
118 | 118 | array( |
119 | 119 | 'timeout' => 15, |
120 | 120 | 'sslverify' => false, |
@@ -123,29 +123,29 @@ discard block |
||
123 | 123 | ); |
124 | 124 | |
125 | 125 | // Update license in db. |
126 | - $keys = get_option( 'simple-calendar_settings_licenses', array() ); |
|
127 | - $new_keys = array_merge( (array) $keys, array( 'keys' => array( $addon => $key ) ) ); |
|
128 | - update_option( 'simple-calendar_settings_licenses', $new_keys ); |
|
126 | + $keys = get_option('simple-calendar_settings_licenses', array()); |
|
127 | + $new_keys = array_merge((array) $keys, array('keys' => array($addon => $key))); |
|
128 | + update_option('simple-calendar_settings_licenses', $new_keys); |
|
129 | 129 | |
130 | 130 | // Make sure there is a response. |
131 | - if ( is_wp_error( $response ) ) { |
|
132 | - wp_send_json_error( sprintf( __( 'There was an error processing your request: %s', 'google-calendar-events' ), $response->get_error_message() ) ); |
|
131 | + if (is_wp_error($response)) { |
|
132 | + wp_send_json_error(sprintf(__('There was an error processing your request: %s', 'google-calendar-events'), $response->get_error_message())); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | // Decode the license data and save. |
136 | - $license_data = json_decode( wp_remote_retrieve_body( $response ) ); |
|
136 | + $license_data = json_decode(wp_remote_retrieve_body($response)); |
|
137 | 137 | $status = simcal_get_license_status(); |
138 | - if ( 'deactivated' == $license_data->license ) { |
|
139 | - unset( $status[ $addon ] ); |
|
140 | - update_option( 'simple-calendar_licenses_status', $status ); |
|
141 | - wp_send_json_success( $license_data->license ); |
|
142 | - } elseif ( in_array( $license_data->license, array( 'valid', 'invalid' ) ) ) { |
|
143 | - $status[ $addon ] = $license_data->license; |
|
144 | - update_option( 'simple-calendar_licenses_status', $status ); |
|
145 | - $message = 'valid' == $license_data->license ? 'valid' : __( 'License key is invalid.', 'google-calendar-events' ); |
|
146 | - wp_send_json_success( $message ); |
|
138 | + if ('deactivated' == $license_data->license) { |
|
139 | + unset($status[$addon]); |
|
140 | + update_option('simple-calendar_licenses_status', $status); |
|
141 | + wp_send_json_success($license_data->license); |
|
142 | + } elseif (in_array($license_data->license, array('valid', 'invalid'))) { |
|
143 | + $status[$addon] = $license_data->license; |
|
144 | + update_option('simple-calendar_licenses_status', $status); |
|
145 | + $message = 'valid' == $license_data->license ? 'valid' : __('License key is invalid.', 'google-calendar-events'); |
|
146 | + wp_send_json_success($message); |
|
147 | 147 | } else { |
148 | - wp_send_json_error( '' ); |
|
148 | + wp_send_json_error(''); |
|
149 | 149 | } |
150 | 150 | } |
151 | 151 | |
@@ -156,17 +156,17 @@ discard block |
||
156 | 156 | */ |
157 | 157 | public function reset_licenses() { |
158 | 158 | |
159 | - $nonce = isset( $_POST['nonce'] ) ? esc_attr( $_POST['nonce'] ) : ''; |
|
159 | + $nonce = isset($_POST['nonce']) ? esc_attr($_POST['nonce']) : ''; |
|
160 | 160 | |
161 | 161 | // Verify this request comes from the add-ons licenses activation settings page. |
162 | - if ( empty ( $nonce ) || ! wp_verify_nonce( $nonce, 'simcal_license_manager' ) ) { |
|
163 | - wp_send_json_error( sprintf( __( 'An error occurred: %s', 'google-calendar-events' ), 'Nonce verification failed.' ) ); |
|
162 | + if (empty ($nonce) || ! wp_verify_nonce($nonce, 'simcal_license_manager')) { |
|
163 | + wp_send_json_error(sprintf(__('An error occurred: %s', 'google-calendar-events'), 'Nonce verification failed.')); |
|
164 | 164 | } |
165 | 165 | |
166 | - delete_option( 'simple-calendar_settings_licenses' ); |
|
167 | - delete_option( 'simple-calendar_licenses_status' ); |
|
166 | + delete_option('simple-calendar_settings_licenses'); |
|
167 | + delete_option('simple-calendar_licenses_status'); |
|
168 | 168 | |
169 | - wp_send_json_success( 'success' ); |
|
169 | + wp_send_json_success('success'); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | } |