Whip_Host

Represents a host.

Defined (1)

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

/vendor/yoast/whip/src/Whip_Host.php  
  1. class Whip_Host { 
  2. const HOST_NAME_KEY = 'WHIP_NAME_OF_HOST'; 
  3. const HOSTING_PAGE_FILTER_KEY = 'whip_hosting_page_url_wordpress'; 
  4.  
  5. /** 
  6. * Retrieves the name of the host if set. 
  7. * @return string The name of the host. 
  8. */ 
  9. public static function name() { 
  10. $name = (string) getenv( self::HOST_NAME_KEY ); 
  11.  
  12. return self::filterName( $name ); 
  13.  
  14. /** 
  15. * Filters the name if we are in a WordPress context. In a non-WordPress content this function just returns the passed name. 
  16. * @param string $name The current name of the host. 
  17. * @returns string The filtered name of the host. 
  18. */ 
  19. private static function filterName( $name ) { 
  20. if ( function_exists( 'apply_filters' ) ) { 
  21. return (string) apply_filters( strtolower( self::HOST_NAME_KEY ), $name ); 
  22.  
  23. return $name; 
  24.  
  25. /** 
  26. * Retrieves the message from the host if set. 
  27. * @param string $messageKey The key to use as the environment variable. 
  28. * @return string The message as set by the host. 
  29. */ 
  30. public static function message( $messageKey ) { 
  31. $message = (string) getenv( $messageKey ); 
  32.  
  33. return self::filterMessage( $messageKey, $message ); 
  34.  
  35. /** 
  36. * Filters the message if we are in a WordPress context. In a non-WordPress content this function just returns the passed message. 
  37. * @param string $messageKey The key used for the environment variable. 
  38. * @param string $message The current message from the host. 
  39. * @return string 
  40. */ 
  41. private static function filterMessage( $messageKey, $message ) { 
  42. if ( function_exists( 'apply_filters' ) ) { 
  43. return (string) apply_filters( strtolower( $messageKey ), $message ); 
  44.  
  45. return $message; 
  46.  
  47. /** 
  48. * Returns the URL for the hosting page 
  49. * @returns string The URL to the hosting overview page. 
  50. */ 
  51. public static function hostingPageUrl() { 
  52. $url = 'https://yoa.st/w3'; 
  53.  
  54. return self::filterHostingPageUrl( $url ); 
  55.  
  56. /** 
  57. * Filters the hosting page url if we are in a WordPress context. In a non-WordPress context this function just returns a link to the Yoast hosting page. 
  58. * @param string $url The previous URL. 
  59. * @returns string The new URL to the hosting overview page. 
  60. */ 
  61. private static function filterHostingPageUrl( $url ) { 
  62. if ( function_exists( 'apply_filters' ) && apply_filters( self::HOSTING_PAGE_FILTER_KEY, false ) ) { 
  63. return 'https://wordpress.org/hosting/'; 
  64.  
  65. return $url;