WPSEO_Admin_Banner_Spot

Represents the an admin banner spot.

Defined (1)

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

/admin/banner/class-admin-banner-spot.php  
  1. class WPSEO_Admin_Banner_Spot { 
  2.  
  3. /** @var string */ 
  4. private $title; 
  5.  
  6. /** @var string */ 
  7. private $description = ''; 
  8.  
  9. /** @var string */ 
  10. private $extra = ''; 
  11.  
  12. /** @var WPSEO_Admin_Banner[] */ 
  13. private $banners = array(); 
  14.  
  15. /** 
  16. * WPSEO_Admin_Banner_Spot constructor. 
  17. * @param string $title The title for the spot. 
  18. * @param WPSEO_Admin_Banner_Renderer $banner_renderer The renderer for the banner. 
  19. */ 
  20. public function __construct( $title, WPSEO_Admin_Banner_Renderer $banner_renderer = null ) { 
  21. $this->title = $title; 
  22. $this->banner_renderer = ( is_null( $banner_renderer ) ? new WPSEO_Admin_Banner_Renderer() : $banner_renderer ); 
  23.  
  24. /** 
  25. * Returns the title. 
  26. * @return string 
  27. */ 
  28. public function get_title() { 
  29. return $this->title; 
  30.  
  31. /** 
  32. * Returns the description. 
  33. * @return string 
  34. */ 
  35. public function get_description() { 
  36. return $this->description; 
  37.  
  38. /** 
  39. * Returns the extra content. 
  40. * @return string 
  41. */ 
  42. public function get_extra() { 
  43. return $this->extra; 
  44.  
  45. /** 
  46. * Sets the description 
  47. * @param string $description The description. 
  48. */ 
  49. public function set_description( $description ) { 
  50. $this->description = $description; 
  51.  
  52. /** 
  53. * Sets the "extra" 
  54. * @param string $extra The "extra". 
  55. */ 
  56. public function set_extra( $extra ) { 
  57. $this->extra = $extra; 
  58.  
  59. /** 
  60. * Adds an admin banner. 
  61. * @param WPSEO_Admin_Banner $banner The banner to add. 
  62. */ 
  63. public function add_banner( WPSEO_Admin_Banner $banner ) { 
  64. $this->banners[] = $banner; 
  65.  
  66. /** 
  67. * Renders the banner. 
  68. * @return string 
  69. */ 
  70. public function render_banner() { 
  71. if ( ! $this->has_banners() ) { 
  72. return ''; 
  73.  
  74. return $this->banner_renderer->render( $this->get_random_banner() ); 
  75.  
  76. /** 
  77. * Checks if there are any banners set. 
  78. * @return bool 
  79. */ 
  80. public function has_banners() { 
  81. return ! empty( $this->banners ); 
  82.  
  83. /** 
  84. * Returns a random banner. 
  85. * @return null|WPSEO_Admin_Banner 
  86. */ 
  87. protected function get_random_banner() { 
  88. return $this->banners[ array_rand( $this->banners, 1 ) ];