WordAds_Params

The WordPress Core WordAds Params class.

Defined (1)

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

/modules/wordads/php/params.php  
  1. class WordAds_Params { 
  2.  
  3. /** 
  4. * Setup parameters for serving the ads 
  5. * @since 4.5.0 
  6. */ 
  7. public function __construct() { 
  8. $this->options = array( 
  9. 'wordads_approved' => (bool) get_option( 'wordads_approved', false ),  
  10. 'wordads_active' => (bool) get_option( 'wordads_active', false ),  
  11. 'wordads_house' => (bool) get_option( 'wordads_house', true ),  
  12. 'enable_header_ad' => (bool) get_option( 'enable_header_ad', false ) 
  13. ); 
  14.  
  15. $host = 'localhost'; 
  16. if ( isset( $_SERVER['HTTP_HOST'] ) ) { 
  17. $host = $_SERVER['HTTP_HOST']; 
  18.  
  19. $this->url = ( is_ssl() ? 'https' : 'http' ) . '://' . $host . $_SERVER['REQUEST_URI']; 
  20. if ( ! ( false === strpos( $this->url, '?' ) ) && ! isset( $_GET['p'] ) ) { 
  21. $this->url = substr( $this->url, 0, strpos( $this->url, '?' ) ); 
  22.  
  23. $this->cloudflare = self::is_cloudflare(); 
  24. $this->blog_id = Jetpack::get_option( 'id', 0 ); 
  25. $this->mobile_device = jetpack_is_mobile( 'any', true ); 
  26. $this->targeting_tags = array( 
  27. 'WordAds' => 1,  
  28. 'BlogId' => Jetpack::is_development_mode() ? 0 : Jetpack_Options::get_option( 'id' ),  
  29. 'Domain' => esc_js( parse_url( home_url(), PHP_URL_HOST ) ),  
  30. 'PageURL' => esc_js( $this->url ),  
  31. 'LangId' => false !== strpos( get_bloginfo( 'language' ), 'en' ) ? 1 : 0, // TODO something else? 
  32. 'AdSafe' => 1, // TODO 
  33. ); 
  34.  
  35. /** 
  36. * @return boolean true if the user is browsing on a mobile device (iPad not included) 
  37. * @since 4.5.0 
  38. */ 
  39. public function is_mobile() { 
  40. return ! empty( $this->mobile_device ); 
  41.  
  42. /** 
  43. * @return boolean true if site is being served via CloudFlare 
  44. * @since 4.5.0 
  45. */ 
  46. public static function is_cloudflare() { 
  47. if ( defined( 'WORDADS_CLOUDFLARE' ) ) { 
  48. return true; 
  49. if ( isset( $_SERVER['HTTP_CF_CONNECTING_IP'] ) ) { 
  50. return true; 
  51. if ( isset( $_SERVER['HTTP_CF_IPCOUNTRY'] ) ) { 
  52. return true; 
  53. if ( isset( $_SERVER['HTTP_CF_VISITOR'] ) ) { 
  54. return true; 
  55.  
  56. return false; 
  57.  
  58. /** 
  59. * @return boolean true if user is browsing in iOS device 
  60. * @since 4.5.0 
  61. */ 
  62. public function is_ios() { 
  63. return in_array( $this->get_device(), array( 'ipad', 'iphone', 'ipod' ) ); 
  64.  
  65. /** 
  66. * Returns the user's device (see user-agent.php) or 'desktop' 
  67. * @return string user device 
  68. * @since 4.5.0 
  69. */ 
  70. public function get_device() { 
  71. global $agent_info; 
  72.  
  73. if ( ! empty( $this->mobile_device ) ) { 
  74. return $this->mobile_device; 
  75.  
  76. if ( $agent_info->is_ipad() ) { 
  77. return 'ipad'; 
  78.  
  79. return 'desktop'; 
  80.  
  81. /** 
  82. * @return string The type of page that is being loaded 
  83. * @since 4.5.0 
  84. */ 
  85. public function get_page_type() { 
  86. if ( ! empty( $this->page_type ) ) { 
  87. return $this->page_type; 
  88.  
  89. if ( self::is_static_home() ) { 
  90. $this->page_type = 'static_home'; 
  91. } else if ( is_home() ) { 
  92. $this->page_type = 'home'; 
  93. } else if ( is_page() ) { 
  94. $this->page_type = 'page'; 
  95. } else if ( is_single() ) { 
  96. $this->page_type = 'post'; 
  97. } else if ( is_search() ) { 
  98. $this->page_type = 'search'; 
  99. } else if ( is_category() ) { 
  100. $this->page_type = 'category'; 
  101. } else if ( is_archive() ) { 
  102. $this->page_type = 'archive'; 
  103. } else { 
  104. $this->page_type = 'wtf'; 
  105.  
  106. return $this->page_type; 
  107.  
  108. /** 
  109. * Returns true if page is static home 
  110. * @return boolean true if page is static home 
  111. * @since 4.5.0 
  112. */ 
  113. public static function is_static_home() { 
  114. return is_front_page() && 
  115. 'page' == get_option( 'show_on_front' ) && 
  116. get_option( 'page_on_front' ); 
  117.  
  118. /** 
  119. * Logic for if we should show an ad 
  120. * @since 4.5.0 
  121. */ 
  122. public static function should_show() { 
  123. global $wp_query; 
  124. if ( is_single() || ( is_page() && ! is_home() ) ) { 
  125. return true; 
  126.  
  127. // TODO this would be a good place for allowing the user to specify 
  128. if ( ( is_home() || is_archive() || is_search() ) && 0 == $wp_query->current_post ) { 
  129. return true; 
  130.  
  131. return false; 
  132.  
  133. /** 
  134. * Logic for if we should show a mobile ad 
  135. * @since 4.5.0 
  136. */ 
  137. public static function should_show_mobile() { 
  138. global $wp_query; 
  139.  
  140. if ( ! in_the_loop() || ! did_action( 'wp_head' ) ) { 
  141. return false; 
  142.  
  143. if ( is_single() || ( is_page() && ! is_home() ) ) { 
  144. return true; 
  145.  
  146. if ( ( is_home() || is_archive() ) && 0 == $wp_query->current_post ) { 
  147. return true; 
  148.  
  149. return false;