Completed
Push — add/wordads-shortcode ( b9e431...86923f )
by
unknown
35:21 queued 19:18
created

Jetpack_WordAds_Shortcode::admin_head()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Embed WordAds 'ad' in post
5
 *
6
 */
7
class Jetpack_WordAds_Shortcode {
8
9
	private $scripts_and_style_included = false;
0 ignored issues
show
Unused Code introduced by
The property $scripts_and_style_included is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
10
11
	function __construct() {
12
		add_action( 'init', array( $this, 'action_init' ) );
13
	}
14
15
	/**
16
	 * Register our shortcode and enqueue necessary files.
17
	 */
18
	function action_init() {
19
		global $wordads;
20
21
		if ( empty( $wordads ) ) {
22
			return null;
23
		}
24
		add_shortcode( 'wordad', array( $this, 'wordads_shortcode' ) );
25
	}
26
27
	/**
28
	 * Our [wordad] shortcode.
29
	 * Prints a WordAds Ad.
30
	 *
31
	 * @param array  $atts    Array of shortcode attributes.
32
	 * @param string $content Post content.
33
	 *
34
	 * @return string HTML for WordAds shortcode.
35
	 */
36
	static function wordads_shortcode( $atts, $content = '' ) {
37
		$atts = shortcode_atts(
38
			array(
39
			), $atts, 'wordads'
40
		);
41
42
		return self::wordads_shortcode_html( $atts, $content );
43
	}
44
45
	/**
46
	 * The shortcode output
47
	 *
48
	 * @param array  $atts    Array of shortcode attributes.
49
	 * @param string $content Post content.
50
	 *
51
	 * @return string HTML output
52
	 */
53
	static function wordads_shortcode_html( $atts, $content = '' ) {
54
		global $wordads;
55
56
		if ( empty( $wordads ) ) {
57
			return __( '<div>The WordAds module is not active</div>' );
58
		}
59
60
		$html = '<div class="jetpack-wordad" itemscope itemtype="https://schema.org/WPAdBlock">';
61
62
		$html .= '</div>';
63
64
		$html = $wordads->insert_inline_ad( $html );
65
66
		return $html;
67
	}
68
}
69
70
new Jetpack_WordAds_Shortcode();
71