Skip to content

Commit

Permalink
feat(ads): suppress ads on sponsored posts
Browse files Browse the repository at this point in the history
  • Loading branch information
adekbadek committed Sep 13, 2021
1 parent 04fd88a commit 0df2bfd
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions includes/class-newspack-sponsors-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ public static function instance() {
*/
public function __construct() {
add_action( 'init', [ __CLASS__, 'init' ] );
add_filter( 'newspack_ads_should_display_for_post', [ __CLASS__, 'suppress_ads' ], 10, 2 );
}

/**
* Add Sponsors CPT to the CPTs which should have ads suppressed.
*
* @param bool $should_display Should ads be displayed on this post?
* @param int $post_id Post ID.
*/
public static function suppress_ads( $should_display, $post_id ) {
$sponsors = get_sponsors_for_post( $post_id );
if ( $sponsors && count( $sponsors ) ) {
return false;
}
return $should_display;
}

/**
Expand Down

0 comments on commit 0df2bfd

Please sign in to comment.