Whip_WPMessagePresenter

A message presenter to show a WordPress notice.

Defined (1)

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

/vendor/yoast/whip/src/presenters/Whip_WPMessagePresenter.php  
  1. class Whip_WPMessagePresenter implements Whip_MessagePresenter { 
  2.  
  3. private $message; 
  4.  
  5. /** 
  6. * Whip_WPMessagePresenter constructor. 
  7. * @param Whip_Message $message The message to use in the presenter. 
  8. */ 
  9. public function __construct( Whip_Message $message ) { 
  10. $this->message = $message; 
  11.  
  12. /** 
  13. * Registers hooks to WordPress. This is a separate function so you can 
  14. * control when the hooks are registered. 
  15. */ 
  16. public function register_hooks() { 
  17. add_action( 'admin_notices', array( $this, 'renderMessage' ) ); 
  18.  
  19. /** 
  20. * Renders the messages present in the global to notices. 
  21. */ 
  22. public function renderMessage() { 
  23. printf( '<div class="error">%s</div>', $this->kses( $this->message->body() ) ); 
  24.  
  25. /** 
  26. * Removes content from the message that we don't want to show. 
  27. * @param string $message The message to clean. 
  28. * @return string The cleaned message. 
  29. */ 
  30. public function kses( $message ) { 
  31. return wp_kses( $message, array( 
  32. 'a' => array( 
  33. 'href' => true,  
  34. 'target' => true,  
  35. ),  
  36. 'strong' => true,  
  37. 'p' => true,  
  38. 'ul' => true,  
  39. 'li' => true,  
  40. ) );