HTML;
}
$form_factor = 'square';
if ( 250 > $width ) {
$form_factor = 'skyscraper';
} elseif ( 300 < $width ) {
$form_factor = 'leaderboard';
}
return $this->get_dynamic_ad_snippet( $section_id, $form_factor, $location );
}
/**
* Returns the dynamic snippet to be inserted into the ad unit
*
* @param int $section_id section_id.
* @param string $form_factor form_factor.
* @param string $location location.
* @param string $relocate location to be moved after the fact for themes without required hook.
* @param string | null $id A unique string ID or placeholder.
*
* @return string
*
* @since 8.7
*/
public function get_dynamic_ad_snippet( $section_id, $form_factor = 'square', $location = '', $relocate = '', $id = null ) {
$is_location_enabled = in_array( $location, array( 'top', 'belowpost', 'inline' ), true );
if ( $is_location_enabled ) {
return self::get_watl_ad_html_tag( $location );
}
return $this->get_fallback_ad_snippet( $section_id, $form_factor, $location, $relocate, $id );
}
/**
* Returns the fallback dynamic snippet to be inserted into the ad unit
*
* @param int $section_id section_id.
* @param string $form_factor form_factor.
* @param string $location location.
* @param string $relocate location to be moved after the fact for themes without required hook.
* @param string | null $id A unique string ID or placeholder.
*
* @return string
*
* @since 8.7
*/
public function get_fallback_ad_snippet( $section_id, $form_factor = 'square', $location = '', $relocate = '', $id = null ) {
$div_id = 'atatags-' . $section_id . '-' . ( $id ?? uniqid() );
$div_id = esc_attr( $div_id );
// Default form factor.
$form_factor_id = self::$form_factor_ids['square'];
if ( isset( self::$form_factor_ids[ $form_factor ] ) ) {
$form_factor_id = self::$form_factor_ids[ $form_factor ];
}
$loc_id = 100;
if ( isset( self::$ad_location_ids[ $location ] ) ) {
$loc_id = self::$ad_location_ids[ $location ];
}
$form_factor_id = esc_js( $form_factor_id );
$advertisements_text = esc_js( __( 'Advertisements', 'jetpack' ) );
$report_ad_text = esc_js( __( 'Report this ad', 'jetpack' ) );
$privacy_settings_text = esc_js( __( 'Privacy settings', 'jetpack' ) );
$relocate_script = '';
if ( ! empty( $relocate ) ) {
$selector = wp_json_encode( $relocate );
$relocate_script = <<
var adNode = document.getElementById( '{$div_id}' );
var selector = {$selector};
var relocateNode = document.querySelector( selector );
relocateNode.parentNode.insertBefore( adNode, relocateNode );
JS;
}
return <<
{$relocate_script}
HTML;
}
/**
* Returns the complete ad div with snippet to be inserted into the page
*
* @param string $spot top, side, inline, or belowpost.
* @param string $snippet The snippet to insert into the div.
* @param array $css_classes CSS classes.
* @return string The supporting ad unit div.
*
* @since 7.1
*/
public function get_ad_div( $spot, $snippet, array $css_classes = array() ) {
if ( strpos( strtolower( $spot ), 'amp' ) === false && ! 'inline' === $spot ) {
return $snippet; // we don't want dynamic ads to be inserted for AMP & Gutenberg.
}
$css_classes[] = 'wpcnt';
if ( 'top' === $spot ) {
$css_classes[] = 'wpcnt-header';
}
$spot = esc_attr( $spot );
$classes = esc_attr( implode( ' ', $css_classes ) );
$about = esc_html__( 'Advertisements', 'jetpack' );
return <<
HTML;
}
/**
* Check the reasons to bail before we attempt to insert ads.
*
* @return true if we should bail (don't insert ads)
*
* @since 4.5.0
*/
public function should_bail() {
return ! $this->option( 'wordads_approved' ) || (bool) $this->option( 'wordads_unsafe' );
}
/**
* Returns markup for HTML5 house ad base on unit
*
* @param string $unit mrec, widesky, or leaderboard.
* @return string markup for HTML5 house ad
*
* @since 4.7.0
*/
public function get_house_ad( $unit = 'mrec' ) {
switch ( $unit ) {
case 'widesky':
$width = 160;
$height = 600;
break;
case 'leaderboard':
$width = 728;
$height = 90;
break;
case 'mrec':
default:
$width = 300;
$height = 250;
break;
}
return <<
HTML;
}
/**
* Returns the html ad tag used by WordAds Tag Library
*
* @param string $slot_type e.g belowpost, gutenberg_rectangle.
*
* @return string
*
* @since 8.7
*/
public static function get_watl_ad_html_tag( string $slot_type ): string {
$uid = uniqid( 'atatags-dynamic-' . $slot_type . '-' );
return <<
HTML;
}
/**
* Activation hook actions
*
* @since 4.5.0
*/
public static function activate() {
WordAds_API::update_wordads_status_from_api();
}
/**
* Registers the widgets.
*/
public function widget_callback() {
register_widget( 'WordAds_Sidebar_Widget' );
$ccpa_enabled = get_option( 'wordads_ccpa_enabled' );
if ( $ccpa_enabled ) {
register_widget( 'WordAds_Ccpa_Do_Not_Sell_Link_Widget' );
}
}
}
add_action( 'jetpack_activate_module_wordads', array( 'WordAds', 'activate' ) );
add_action( 'jetpack_activate_module_wordads', array( 'WordAds_Cron', 'activate' ) );
add_action( 'jetpack_deactivate_module_wordads', array( 'WordAds_Cron', 'deactivate' ) );
global $wordads;
$wordads = new WordAds();