Completed
Push — add/gdpr-ads-compliance ( c52a1e...cda5c5 )
by
unknown
26:32 queued 14:46
created

Jetpack_WordAds_Shortcode   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 59
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A action_init() 0 8 2
A wordads_shortcode() 0 5 1
A wordads_shortcode_html() 0 15 2
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( 'wordads', array( $this, 'wordads_shortcode' ) );
25
	}
26
27
	/**
28
	 * Our [wordads] 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( array(), $atts, 'wordads');
38
39
		return self::wordads_shortcode_html( $atts, $content );
40
	}
41
42
	/**
43
	 * The shortcode output
44
	 *
45
	 * @param array  $atts    Array of shortcode attributes.
46
	 * @param string $content Post content.
47
	 *
48
	 * @return string HTML output
49
	 */
50
	static function wordads_shortcode_html( $atts, $content = '' ) {
51
		global $wordads;
52
53
		if ( empty( $wordads ) ) {
54
			return __( '<div>The WordAds module is not active</div>' );
55
		}
56
57
		$html = '<div class="jetpack-wordad" itemscope itemtype="https://schema.org/WPAdBlock">';
58
59
		$html .= '</div>';
60
61
		$html = $wordads->insert_inline_ad( $html );
62
63
		return $html;
64
	}
65
}
66
67
new Jetpack_WordAds_Shortcode();
68