| 1 |
<?php |
| 2 |
/** |
| 3 |
* Wordads shortcode. |
| 4 |
* |
| 5 |
* Examples: |
| 6 |
* [wordads] |
| 7 |
* |
| 8 |
* @package automattic/jetpack |
| 9 |
*/ |
| 10 |
|
| 11 |
if ( ! defined( 'ABSPATH' ) ) { |
| 12 |
exit( 0 ); |
| 13 |
} |
| 14 |
|
| 15 |
/** |
| 16 |
* Class WordAds_Shortcode |
| 17 |
* |
| 18 |
* Handles the [wordads] shortcode. |
| 19 |
*/ |
| 20 |
class WordAds_Shortcode { |
| 21 |
|
| 22 |
/** |
| 23 |
* Register our shortcode and enqueue necessary files. |
| 24 |
*/ |
| 25 |
public static function init() { |
| 26 |
global $wordads; |
| 27 |
|
| 28 |
if ( empty( $wordads ) ) { |
| 29 |
return null; |
| 30 |
} |
| 31 |
|
| 32 |
add_shortcode( 'wordads', array( self::class, 'handle_wordads_shortcode' ) ); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Our [wordads] shortcode. |
| 37 |
* Prints a WordAds Ad. |
| 38 |
* |
| 39 |
* @return string HTML for WordAds shortcode. |
| 40 |
*/ |
| 41 |
public static function handle_wordads_shortcode() { |
| 42 |
global $wordads; |
| 43 |
|
| 44 |
if ( empty( $wordads ) ) { |
| 45 |
return '<div>' . __( 'The WordAds module is not active', 'jetpack' ) . '</div>'; |
| 46 |
} |
| 47 |
|
| 48 |
$html = '<div class="jetpack-wordad" itemscope itemtype="https://schema.org/WPAdBlock"></div>'; |
| 49 |
|
| 50 |
return $wordads->insert_inline_ad( $html ); |
| 51 |
} |
| 52 |
} |
| 53 |
|