Completed
Push — branch-4.5 ( 908d6d...78ee70 )
by
unknown
08:16
created

Upcoming_Events_Shortcode::shortcode()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 1
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Most of the heavy lifting done in iCalendarReader class
5
 */
6
class Upcoming_Events_Shortcode {
7
8
	public static function init() {
9
		add_shortcode( 'upcomingevents', array( __CLASS__, 'shortcode' ) );
10
	}
11
12
	public static function shortcode( $atts = array() ) {
13
		jetpack_require_lib( 'icalendar-reader' );
14
		$atts   = shortcode_atts( array( 'url' => '', 'number' => 0 ), $atts, 'upcomingevents' );
15
		$args   = array(
16
			'context' => 'shortcode',
17
			'number'  => absint( $atts['number'] ),
18
		);
19
		$events = icalendar_render_events( $atts['url'], $args );
20
21
		if ( ! $events ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $events of type false|string is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
22
			$events = sprintf( '<p>%s</p>', __( 'No upcoming events', 'jetpack' ) );
23
		}
24
25
		return $events;
26
	}
27
}
28
29
add_action( 'plugins_loaded', array( 'Upcoming_Events_Shortcode', 'init' ), 101 );
30