WPSEO_Admin_Banner_Renderer

Represents the render object for generating the html for the given banner.

Defined (1)

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

/admin/banner/class-admin-banner-renderer.php  
  1. class WPSEO_Admin_Banner_Renderer { 
  2.  
  3. /** @var string */ 
  4. protected $base_path = ''; 
  5.  
  6. /** 
  7. * Renders the admin banner. 
  8. * @param WPSEO_Admin_Banner $banner The banner to render. 
  9. * @return string 
  10. */ 
  11. public function render( WPSEO_Admin_Banner $banner ) { 
  12. $output = '<a class="wpseo-banner__link" target="_blank" href="' . esc_url( $banner->get_url() ) . '">'; 
  13. $output .= '<img class="wpseo-banner__image" width="' . esc_attr( $banner->get_width() ) . '" height="' . esc_attr( $banner->get_height() ) . '" src="' . esc_attr( $this->get_image_path( $banner->get_image() ) ) . '" alt="' . esc_attr( $banner->get_alt() ) . '"/>'; 
  14. $output .= '</a>'; 
  15.  
  16. return $output; 
  17.  
  18. /** 
  19. * Sets the base path, where the images are located. 
  20. * @param string $base_path The image location. 
  21. */ 
  22. public function set_base_path( $base_path ) { 
  23. $this->base_path = $base_path; 
  24.  
  25. /** 
  26. * Returns the full path for the image. 
  27. * @param string $image The image path. 
  28. * @return string 
  29. */ 
  30. protected function get_image_path( $image ) { 
  31. return rtrim( $this->base_path, '/' ) . '/' . ltrim( $image, '/' );