PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 8.2
Jetpack – WP Security, Backup, Speed, & Growth v8.2
16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / modules / shortcodes / wordads.php

wordads.php in Jetpack – WP Security, Backup, Speed, & Growth 8.2, at modules/shortcodes/wordads.php

81 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2 /**
3 * Wordads shortcode.
4 *
5 * Examples:
6 * [wordads]
7 *
8 * @package Jetpack
9 */
10
11 /**
12 * Embed WordAds 'ad' in post
13 */
14 class Jetpack_WordAds_Shortcode {
15
16 /**
17 * Used to determine whether scripts and styles have been enqueued already.
18 *
19 * @var bool false Should we enqueue scripts and styles.
20 */
21 private $scripts_and_style_included = false;
22
23 /**
24 * Initialize.
25 */
26 public function __construct() {
27 add_action( 'init', array( $this, 'action_init' ) );
28 }
29
30 /**
31 * Register our shortcode and enqueue necessary files.
32 */
33 public function action_init() {
34 global $wordads;
35
36 if ( empty( $wordads ) ) {
37 return null;
38 }
39
40 add_shortcode( 'wordads', array( $this, 'wordads_shortcode' ) );
41 }
42
43 /**
44 * Our [wordads] shortcode.
45 * Prints a WordAds Ad.
46 *
47 * @param array $atts Array of shortcode attributes.
48 * @param string $content Post content.
49 *
50 * @return string HTML for WordAds shortcode.
51 */
52 public static function wordads_shortcode( $atts, $content = '' ) {
53 $atts = shortcode_atts( array(), $atts, 'wordads' );
54
55 return self::wordads_shortcode_html( $atts, $content );
56 }
57
58 /**
59 * The shortcode output
60 *
61 * @param array $atts Array of shortcode attributes.
62 * @param string $content Post content.
63 *
64 * @return string HTML output
65 */
66 private static function wordads_shortcode_html( $atts, $content = '' ) {
67 global $wordads;
68
69 if ( empty( $wordads ) ) {
70 return '<div>' . __( 'The WordAds module is not active', 'jetpack' ) . '</div>';
71 }
72
73 $html = '<div class="jetpack-wordad" itemscope itemtype="https://schema.org/WPAdBlock"></div>';
74 $html = $wordads->insert_inline_ad( $html );
75
76 return $html;
77 }
78 }
79
80 new Jetpack_WordAds_Shortcode();
81