OS : Linux
PHP Version : 7.4.33
Software : Apache/2.4.6 (CentOS) PHP/7.4.33 array(
'tag' => '300x250_mediumrectangle',
'height' => '250',
'width' => '300',
),
'leaderboard' => array(
'tag' => '728x90_leaderboard',
'height' => '90',
'width' => '728',
),
'mobile_leaderboard' => array(
'tag' => '320x50_mobileleaderboard',
'height' => '50',
'width' => '320',
),
'wideskyscraper' => array(
'tag' => '160x600_wideskyscraper',
'height' => '600',
'width' => '160',
),
);
/**
* Mapping array of location slugs to placement ids
*
* @var array
*/
public static $ad_location_ids = array(
'top' => 110,
'belowpost' => 120,
'belowpost2' => 130,
'sidebar' => 140,
'widget' => 150,
'gutenberg' => 200,
'inline' => 310,
'inline-plugin' => 320,
);
/**
* Counter to enable unique, sequential section IDs for all amp-ad units
*
* @var int
*/
public static $amp_section_id = 1;
/**
* Checks for AMP support and returns true iff active & AMP request
* @return boolean True if supported AMP request
*
* @since 7.5.0
*/
public static function is_amp() {
return class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request();
}
/**
* Increment the AMP section ID and return the value
*
* @return int
*/
public static function get_amp_section_id() {
return self::$amp_section_id++;
}
public static $SOLO_UNIT_CSS = 'float:left;margin-right:5px;margin-top:0px;';
/**
* Convenience function for grabbing options from params->options
*
* @param string $option the option to grab
* @param mixed $default (optional)
* @return option or $default if not set
*
* @since 4.5.0
*/
function option( $option, $default = false ) {
if ( ! isset( $this->params->options[ $option ] ) ) {
return $default;
}
return $this->params->options[ $option ];
}
/**
* Returns the ad tag property array for supported ad types.
* @return array array with ad tags
*
* @since 7.1.0
*/
function get_ad_tags() {
return self::$ad_tag_ids;
}
/**
* Returns the solo css for unit
* @return string the special css for solo units
*
* @since 7.1.0
*/
function get_solo_unit_css() {
return self::$SOLO_UNIT_CSS;
}
/**
* Instantiate the plugin
*
* @since 4.5.0
*/
function __construct() {
add_action( 'wp', array( $this, 'init' ) );
add_action( 'rest_api_init', array( $this, 'init' ) );
}
/**
* Code to run on WordPress 'init' hook
*
* @since 4.5.0
*/
function init() {
require_once WORDADS_ROOT . '/php/params.php';
$this->params = new WordAds_Params();
if ( $this->should_bail() || self::is_infinite_scroll() ) {
return;
}
if ( is_admin() ) {
require_once WORDADS_ROOT . '/php/admin.php';
return;
}
$this->insert_adcode();
if ( '/ads.txt' === $_SERVER['REQUEST_URI'] ) {
if ( false === ( $ads_txt_transient = get_transient( 'jetpack_ads_txt' ) ) ) {
$ads_txt_transient = ! is_wp_error( WordAds_API::get_wordads_ads_txt() ) ? WordAds_API::get_wordads_ads_txt() : '';
set_transient( 'jetpack_ads_txt', $ads_txt_transient, DAY_IN_SECONDS );
}
/**
* Provide plugins a way of modifying the contents of the automatically-generated ads.txt file.
*
* @module wordads
*
* @since 6.1.0
*
* @param string WordAds_API::get_wordads_ads_txt() The contents of the ads.txt file.
*/
$ads_txt_content = apply_filters( 'wordads_ads_txt', $ads_txt_transient );
header( 'Content-Type: text/plain; charset=utf-8' );
echo esc_html( $ads_txt_content );
die();
}
}
/**
* Check for Jetpack's The_Neverending_Home_Page and use got_infinity
*
* @return boolean true if load came from infinite scroll
*
* @since 4.5.0
*/
public static function is_infinite_scroll() {
return class_exists( 'The_Neverending_Home_Page' ) && The_Neverending_Home_Page::got_infinity();
}
/**
* Add the actions/filters to insert the ads. Checks for mobile or desktop.
*
* @since 4.5.0
*/
private function insert_adcode() {
add_filter( 'wp_resource_hints', array( $this, 'resource_hints' ), 10, 2 );
add_action( 'wp_head', array( $this, 'insert_head_meta' ), 20 );
add_action( 'wp_head', array( $this, 'insert_head_iponweb' ), 30 );
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
add_filter( 'wordads_ads_txt', array( $this, 'insert_custom_adstxt' ) );
/**
* Filters enabling ads in `the_content` filter
*
* @see https://jetpack.com/support/ads/
*
* @module wordads
*
* @since 5.8.0
*
* @param bool True to disable ads in `the_content`
*/
if ( ! apply_filters( 'wordads_content_disable', false ) ) {
add_filter( 'the_content', array( $this, 'insert_ad' ) );
}
/**
* Filters enabling ads in `the_excerpt` filter
*
* @see https://jetpack.com/support/ads/
*
* @module wordads
*
* @since 5.8.0
*
* @param bool True to disable ads in `the_excerpt`
*/
if ( ! apply_filters( 'wordads_excerpt_disable', false ) ) {
add_filter( 'the_excerpt', array( $this, 'insert_ad' ) );
}
if ( $this->option( 'enable_header_ad', true ) ) {
if ( self::is_amp() ) {
add_filter( 'the_content', array( $this, 'insert_header_ad_amp' ) );
} else {
switch ( get_stylesheet() ) {
case 'twentyseventeen':
case 'twentyfifteen':
case 'twentyfourteen':
add_action( 'wp_footer', array( $this, 'insert_header_ad_special' ) );
break;
default:
add_action( 'wp_head', array( $this, 'insert_header_ad' ), 100 );
break;
}
}
}
}
/**
* Register desktop scripts and styles
*
* @since 4.5.0
*/
function enqueue_scripts() {
wp_enqueue_style(
'wordads',
WORDADS_URL . 'css/style.css',
array(),
'2015-12-18'
);
}
/**
* Add the IPW resource hints
*
* @since 7.9
*/
public function resource_hints( $hints, $relation_type ) {
if ( 'dns-prefetch' === $relation_type ) {
$hints[] = '//s.pubmine.com';
$hints[] = '//x.bidswitch.net';
$hints[] = '//static.criteo.net';
$hints[] = '//ib.adnxs.com';
$hints[] = '//aax.amazon-adsystem.com';
$hints[] = '//bidder.criteo.com';
$hints[] = '//cas.criteo.com';
$hints[] = '//gum.criteo.com';
$hints[] = '//ads.pubmatic.com';
$hints[] = '//gads.pubmatic.com';
$hints[] = '//tpc.googlesyndication.com';
$hints[] = '//ad.doubleclick.net';
$hints[] = '//googleads.g.doubleclick.net';
$hints[] = '//www.googletagservices.com';
$hints[] = '//cdn.switchadhub.com';
$hints[] = '//delivery.g.switchadhub.com';
$hints[] = '//delivery.swid.switchadhub.com';
}
return $hints;
}
/**
* IPONWEB metadata used by the various scripts
*
* @return [type] [description]
*/
function insert_head_meta() {
if ( self::is_amp() ) {
return;
}
$themename = esc_js( get_stylesheet() );
$pagetype = intval( $this->params->get_page_type_ipw() );
$data_tags = ( $this->params->cloudflare ) ? ' data-cfasync="false"' : '';
$site_id = $this->params->blog_id;
$consent = intval( isset( $_COOKIE['personalized-ads-consent'] ) );
echo <<
var __ATA_PP = { pt: $pagetype, ht: 2, tn: '$themename', amp: false, siteid: $site_id, consent: $consent };
var __ATA = __ATA || {};
__ATA.cmd = __ATA.cmd || [];
__ATA.criteo = __ATA.criteo || {};
__ATA.criteo.cmd = __ATA.criteo.cmd || [];
HTML;
}
/**
* IPONWEB scripts in
*
* @since 4.5.0
*/
function insert_head_iponweb() {
if ( self::is_amp() ) {
return;
}
$data_tags = ( $this->params->cloudflare ) ? ' data-cfasync="false"' : '';
echo <<
(function(){function g(a,c){a:{for(var b=a.length,d="string"==typeof a?a.split(""):a,e=0;ec?null:"string"==typeof a?a.charAt(c):a[c]};function h(a,c,b){b=null!=b?"="+encodeURIComponent(String(b)):"";if(c+=b){b=a.indexOf("#");0>b&&(b=a.length);var d=a.indexOf("?");if(0>d||d>b){d=b;var e=""}else e=a.substring(d+1,b);a=[a.substr(0,d),e,a.substr(b)];b=a[1];a[1]=c?b?b+"&"+c:c:b;a=a[0]+(a[1]?"?"+a[1]:"")+a[2]}return a};var k=0;function l(a,c){var b=document.createElement("script");b.src=a;b.onload=function(){c&&c(void 0)};b.onerror=function(){c("error")};a=document.getElementsByTagName("head");var d;a&&0!==a.length?d=a[0]:d=document.documentElement;d.appendChild(b)}function m(a){return"string"==typeof a&&0