Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ads: January Ads Tweaks #8587

Merged
merged 2 commits into from
Jan 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _inc/lib/class.core-rest-api-endpoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -1731,7 +1731,7 @@ public static function get_updateable_data_list( $selector = '' ) {
'enable_header_ad' => array(
'description' => esc_html__( 'Display an ad unit at the top of each page.', 'jetpack' ),
'type' => 'boolean',
'default' => 0,
'default' => 1,
'validate_callback' => __CLASS__ . '::validate_boolean',
'jp_group' => 'wordads',
),
Expand Down
2 changes: 1 addition & 1 deletion modules/wordads/php/params.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function __construct() {
'wordads_approved' => false,
'wordads_active' => false,
'wordads_house' => true,
'enable_header_ad' => false,
'enable_header_ad' => true,
'wordads_second_belowpost' => true,
'wordads_display_front_page' => true,
'wordads_display_post' => true,
Expand Down
7 changes: 6 additions & 1 deletion modules/wordads/php/widgets.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
class WordAds_Sidebar_Widget extends WP_Widget {

private static $allowed_tags = array( 'mrec', 'wideskyscraper' );
private static $num_widgets = 0;

function __construct() {
parent::__construct(
Expand All @@ -31,9 +32,14 @@ public function widget( $args, $instance ) {
$instance['unit'] = 'mrec';
}

self::$num_widgets++;
$about = __( 'Advertisements', 'jetpack' );
$width = WordAds::$ad_tag_ids[$instance['unit']]['width'];
$height = WordAds::$ad_tag_ids[$instance['unit']]['height'];
$unit_id = 1 == self::$num_widgets ? 3 : self::$num_widgets + 3; // 2nd belowpost is '4'
$section_id = 0 === $wordads->params->blog_id ?
WORDADS_API_TEST_ID :
$wordads->params->blog_id . $unit_id;

$snippet = '';
if ( $wordads->option( 'wordads_house', true ) ) {
Expand All @@ -46,7 +52,6 @@ public function widget( $args, $instance ) {

$snippet = $wordads->get_house_ad( $unit );
} else {
$section_id = 0 === $wordads->params->blog_id ? WORDADS_API_TEST_ID : $wordads->params->blog_id . '3';
$snippet = $wordads->get_ad_snippet( $section_id, $height, $width );
}

Expand Down
34 changes: 31 additions & 3 deletions modules/wordads/wordads.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,38 @@ private function insert_adcode() {
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( 'the_content', array( $this, 'insert_ad' ) );
add_filter( 'the_excerpt', array( $this, 'insert_ad' ) );

if ( $this->option( 'enable_header_ad' ) ) {
/**
* 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 ) ) {
switch ( get_stylesheet() ) {
case 'twentyseventeen':
case 'twentyfifteen':
Expand Down