Jetpack_Shortcode_Unavailable

Class Jetpack_Shortcode_Unavailable.

Defined (1)

The class is defined in the following location(s).

/modules/shortcodes/unavailable.php  
  1. class Jetpack_Shortcode_Unavailable { 
  2. /** 
  3. * Set up the actions and filters for the class to listen to. 
  4. * @param array $shortcodes An associative array of keys being the shortcodes that are unavailable, and a string explaining why. 
  5. */ 
  6. public function __construct( $shortcodes ) { 
  7. $this->shortcodes = $shortcodes; 
  8.  
  9. add_action( 'template_redirect', array( $this, 'add_shortcodes' ) ); 
  10.  
  11. /** 
  12. * For all of our defined unavailable shortcodes, if something else hasn't 
  13. * already claimed them, add a handler to nullify their output. 
  14. */ 
  15. public function add_shortcodes() { 
  16. foreach ( $this->shortcodes as $shortcode => $message ) { 
  17. if ( ! shortcode_exists( $shortcode ) ) { 
  18. add_shortcode( $shortcode, array( $this, 'stub_shortcode' ) ); 
  19.  
  20. /** 
  21. * Nullify the output of unavailable shortcodes. Includes a filter to make 
  22. * it easier to notify admins that a shortcode that they used is unavailable. 
  23. * @param $atts 
  24. * @param string $content 
  25. * @param string $shortcode 
  26. * @return mixed|void 
  27. */ 
  28. public function stub_shortcode( $atts, $content = '', $shortcode = '' ) { 
  29. $str = ''; 
  30. if ( current_user_can( 'edit_posts' ) && ! empty( $this->shortcodes[ $shortcode ] ) ) { 
  31. $str = sprintf( '<div><strong>%s</strong></div>', $this->shortcodes[ $shortcode ] ); 
  32. /** 
  33. * Filter the front-end output of unavailable shortcodes. 
  34. * @module shortcodes 
  35. * @since 4.5.0 
  36. * @param string $str The html displayed in lieu of the shortcode. 
  37. * @param array $atts The attributes (numeric or named) passed to the shortcode. 
  38. * @param string $content The content (if any) between the opening and closing tags. 
  39. * @param string $shortcode The shortcode tag used to invoke this. 
  40. */ 
  41. return apply_filters( 'jetpack_stub_shortcode', $str, $atts, $content, $shortcode );