Completed
Push — update/remove-disconnect-link ( 4b6a2c )
by
unknown
73:18 queued 63:47
created

Upcoming_Events_Shortcode   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 3 1
A shortcode() 0 15 2
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