Completed
Push — remove/publicize-google-plus ( 287652...15e298 )
by Jeremy
14:15 queued 05:42
created

Jetpack_WordAds_Shortcode::gutenblock_render()   B

Complexity

Conditions 9
Paths 10

Size

Total Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
nc 10
nop 1
dl 0
loc 34
rs 8.0555
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Embed WordAds 'ad' in post
5
 */
6
class Jetpack_WordAds_Shortcode {
7
8
	private $scripts_and_style_included = false;
9
10
	function __construct() {
11
		add_action( 'init', array( $this, 'action_init' ) );
12
	}
13
14
	/**
15
	 * Register our shortcode and enqueue necessary files.
16
	 */
17
	function action_init() {
18
		global $wordads;
19
20
		if ( empty( $wordads ) ) {
21
			return null;
22
		}
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', 'jetpack' ) . '</div>';
55
		}
56
57
		$html = '<div class="jetpack-wordad" itemscope itemtype="https://schema.org/WPAdBlock"></div>';
58
		$html = $wordads->insert_inline_ad( $html );
59
60
		return $html;
61
	}
62
}
63
64
new Jetpack_WordAds_Shortcode();
65