Completed
Push — add/plugin-search-hints ( 43e333...e2b502 )
by
unknown
06:49
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
		add_shortcode( 'wordads', array( $this, 'wordads_shortcode' ) );
24
	}
25
26
	/**
27
	 * Our [wordads] shortcode.
28
	 * Prints a WordAds Ad.
29
	 *
30
	 * @param array  $atts    Array of shortcode attributes.
31
	 * @param string $content Post content.
32
	 *
33
	 * @return string HTML for WordAds shortcode.
34
	 */
35
	static function wordads_shortcode( $atts, $content = '' ) {
36
		$atts = shortcode_atts( array(), $atts, 'wordads' );
37
38
		return self::wordads_shortcode_html( $atts, $content );
39
	}
40
41
	/**
42
	 * The shortcode output
43
	 *
44
	 * @param array  $atts    Array of shortcode attributes.
45
	 * @param string $content Post content.
46
	 *
47
	 * @return string HTML output
48
	 */
49
	static function wordads_shortcode_html( $atts, $content = '' ) {
50
		global $wordads;
51
52
		if ( empty( $wordads ) ) {
53
			return '<div>' . __( 'The WordAds module is not active', 'jetpack' ) . '</div>';
54
		}
55
56
		$html = '<div class="jetpack-wordad" itemscope itemtype="https://schema.org/WPAdBlock">';
57
58
		$html .= '</div>';
59
60
		$html = $wordads->insert_inline_ad( $html );
61
62
		return $html;
63
	}
64
}
65
66
new Jetpack_WordAds_Shortcode();
67