wordads.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * Embed WordAds 'ad' in post
  4. *
  5. */
  6. class Jetpack_WordAds_Shortcode {
  7. private $scripts_and_style_included = false;
  8. function __construct() {
  9. add_action( 'init', array( $this, 'action_init' ) );
  10. }
  11. /**
  12. * Register our shortcode and enqueue necessary files.
  13. */
  14. function action_init() {
  15. global $wordads;
  16. if ( empty( $wordads ) ) {
  17. return null;
  18. }
  19. add_shortcode( 'wordads', array( $this, 'wordads_shortcode' ) );
  20. }
  21. /**
  22. * Our [wordads] shortcode.
  23. * Prints a WordAds Ad.
  24. *
  25. * @param array $atts Array of shortcode attributes.
  26. * @param string $content Post content.
  27. *
  28. * @return string HTML for WordAds shortcode.
  29. */
  30. static function wordads_shortcode( $atts, $content = '' ) {
  31. $atts = shortcode_atts( array(), $atts, 'wordads');
  32. return self::wordads_shortcode_html( $atts, $content );
  33. }
  34. /**
  35. * The shortcode output
  36. *
  37. * @param array $atts Array of shortcode attributes.
  38. * @param string $content Post content.
  39. *
  40. * @return string HTML output
  41. */
  42. static function wordads_shortcode_html( $atts, $content = '' ) {
  43. global $wordads;
  44. if ( empty( $wordads ) ) {
  45. return '<div>' . __( 'The WordAds module is not active', 'jetpack' ) . '</div>';
  46. }
  47. $html = '<div class="jetpack-wordad" itemscope itemtype="https://schema.org/WPAdBlock">';
  48. $html .= '</div>';
  49. $html = $wordads->insert_inline_ad( $html );
  50. return $html;
  51. }
  52. }
  53. new Jetpack_WordAds_Shortcode();