Skip to content

Instantly share code, notes, and snippets.

@ideadude
Created March 5, 2020 21:26
Show Gist options
  • Save ideadude/679b0c83295368ba11379c9cfec064cc to your computer and use it in GitHub Desktop.
Save ideadude/679b0c83295368ba11379c9cfec064cc to your computer and use it in GitHub Desktop.
Unhook JNews Theme Ads if the user is a PMPro member
// Unhook JNews Theme Ads if the user is a PMPro member
// Add this code into a custom plugin.
// I am not sure that this is running late enough to override
// the JNews Ad insert. You may need to hook into init later
// or even another hook that runs later.
function my_hide_jnews_ads_from_members() {
// do nothing if PMPro is not running
if ( ! function_exists( 'pmpro_hasMembershipLevel' ) ) {
return;
}
// do nothing if not a member
// can change this to check for specific levels
if ( ! pmpro_hasMembershipLevel() ) {
return;
}
// ok, let's hide ads from members
// we are running remove_action on things loaded in JNews/class/Ads.php
// header
remove_action('jnews_header_top_ads', array('\JNews\Single\SinglePost\Ads', 'header_top'));
remove_action('jnews_header_ads', array('\JNews\Single\SinglePost\Ads', 'header'));
// article
remove_action('jnews_article_top_ads', array('\JNews\Single\SinglePost\Ads', 'article_top'));
remove_action('jnews_content_top_ads', array('\JNews\Single\SinglePost\Ads', 'content_top'));
remove_action('jnews_article_bottom_ads', array('\JNews\Single\SinglePost\Ads', 'article_bottom'));
remove_action('jnews_content_inline_ads', array('\JNews\Single\SinglePost\Ads', 'content_inline'));
remove_action('jnews_single_post_before_content', array('\JNews\Single\SinglePost\Ads', 'article_content_top'), 10);
remove_action('jnews_single_post_after_content', array('\JNews\Single\SinglePost\Ads', 'article_content_bottom'), 10);
// paragraph
remove_filter('the_content', array($this, 'inject_ads'), 10);
// archive
remove_action('jnews_archive_above_content', array('\JNews\Single\SinglePost\Ads', 'above_content'));
remove_action('jnews_archive_above_hero', array('\JNews\Single\SinglePost\Ads', 'above_hero'));
remove_action('jnews_archive_below_hero', array('\JNews\Single\SinglePost\Ads', 'below_hero'));
// sidefeed
remove_action('jnews_sidefeed_ads', array('\JNews\Single\SinglePost\Ads', 'sidefeed'));
// footer
remove_action('jnews_above_footer_ads', array('\JNews\Single\SinglePost\Ads', 'above_footer'));
remove_action('jnews_after_main', array'\JNews\Single\SinglePost\Ads', 'after_main'));
remove_action('wp_footer', array('\JNews\Single\SinglePost\Ads', 'sticky_footer_ads'), 50);
// page level ads
remove_action('wp_footer', array('\JNews\Single\SinglePost\Ads', 'page_level_ads'));
}
add_action( 'init', 'my_hide_jnews_ads_from_members', 20 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment