Ads Showing on Pro Sites to Users not Logged In

Help! I just discovered that we have ads displaying on Pro Sites to the public, when they should not be showing according to the settings.

To clarify, we have a global header/footer plugin inserting content above and below every site on the network. This has been working fine for years to show ads on all sites, and automatically hide those ads if the site has been upgraded to a Pro Site.

Here is the code snippet used:

<?php
if (is_pro_site()) {
	//do not show ads
} else {
	//show ads
	?>
<!-- ADSENSE AD SCRIPT IS HERE --><br />
<a href=&quot;http://tripawds.com/about/#supporter&quot; title=&quot;Upgrade blog to remove ads!&quot;>Tripawds Supporter sites have no ads.</a>
<?php
}
?>

I just discovered that if the user is not logged in, the ads display! If the user is a logged in member, the ads disappear.

This is incredibly embarrassing. It means all visitors to our main site are seeing ads at the top. It also means ads are showing atop our 501c3 Foundation website. And, we are exhibiting at a major conference next week hoping to attract corporate donors and sponsors. We don't need or want these folks seeing the ads. And, the ads shouldn't be there...

Can somebody please help me quickly figure out how to hide these Pro Sites ads outside the page or post?

I'm sure Aaron is busy, but if someone could ping Aaron we would be most appreciative. Tripawds helps people facing cancer and amputation for their pets, and we can't have them seeing inappropriate ads when they find our site. Same goes for our potential partners at the conference next week.

The screenshots attached show the main site and Foundation Pro Site with adds showing to the public, but hidden once logged in.

Thank you in advance for any help!

  • jcnjr

    I can't help but think my answer lies somewhere in here
    /pro-sites-files/modules/ads.php:699-718

    /* Ads functions used by other plugins */
    function psts_show_ads( $blog_id = null ) {
    	global $ProSites_Module_Ads;
    
    	if ( isset( $ProSites_Module_Ads ) && is_object( $ProSites_Module_Ads ) ) {
    		return $ProSites_Module_Ads->show_ads( $blog_id );
    	} else {
    		return true;
    	}
    }
    
    function psts_hide_ads( $blog_id = null ) {
    	global $ProSites_Module_Ads;
    
    	if ( isset( $ProSites_Module_Ads ) && is_object( $ProSites_Module_Ads ) ) {
    		return $ProSites_Module_Ads->hide_ads( $blog_id );
    	} else {
    		return false;
    	}
    }

    I just can't seem to get this working without throwing a fatal error... :-\

  • Sajid

    Hi @jcnjr,
    Hope you are doing good today :slight_smile:

    If I understand the issue correctly, you want to show adds to the users who are logged in and did not upgraded their website to a pro level ?

    If yes then try this updated code and then check again.

    <?php
    if ( is_pro_site() && ! is_user_logged_in() ) {
    	//do not show ads
    } else {
    	//show ads
    	?>
    <!-- ADSENSE AD SCRIPT IS HERE --><br />
    <a href="http://tripawds.com/about/#supporter" title="Upgrade blog to remove ads!">Tripawds Supporter sites have no ads.</a>
    <?php
    }
    ?>

    Hope that helps! If the issue persist then please send in FTP and WordPress admin login details so I can take a closer look at settings and make changes in file if needed. You can send in these details using our secure contact form in following format.

    Subject: "Attn: Sajid Javed"
    -Error log file link
    -WordPress admin username
    -WordPress admin password
    -login url
    -FTP credentials (host/username/password)
    -link back to this thread for reference
    -any other relevant urls
    Select "I have a different question" for your topic - this and the subject line ensure that it gets assigned to me

    Take care and have a nice day :slight_smile:
    Cheers, Sajid

  • jcnjr

    Sajid Thank you for the prompt reply. I'm sorry for not being perfectly clear...

    If I understand the issue correctly, you want to show adds to the users who are logged in and did not upgraded their website to a pro level ?

    We need to HIDE the content (ads) to all visitors and users on Pro Sites, regardless of their logged in status, just like the plugin is designed to do—and does via settings—within posts and pages. We just need to do it in the header using "if (is_pro_site())" or some variation.

    What I described above is how the ads are displaying on a Pro Site to the public. If a network user is logged in, they do not show on the pro Site.

    I have extened Support access to tripawds.com. But I do not believe this has anything to do with pro Sites settings. I will replicate this on our dev site and provide access and ftp credentials for that, since I am continuing to try and get this working on the live. With our conference next week, I may need to just remove the header ads there for now.

    PS: I had already tried your suggested fix. It does nothing, or rather does what's already happening—hide the ads if logged in. We need to hide the ads on Pro Sites to all visitors.

    Thanks again!

  • jcnjr

    UPDATE: I just discovered a related issue that requires notification of the Pro Sites developers!

    The Pro Sites Widget has very similar behavior to that which I have been describing:

    The widget on a Pro Site does NOT display to the public.
    Only logged in users see the widget.

    Compare these two screenshots of a Pro Site on our dev install.
    Logged User: Sees Pro Site widget and no ads.
    Public visitor: Sees ads and no widget


    Expected Functionality:
    Pro Site Widget should display for all users and visitors.
    Ads should be hidden from all all users and visitors.

    So I have apparently opened another can of worms...anyone have a fishing hook?

  • Sajid

    Hi @jcnjr,
    Hope you are doing good today :slight_smile:

    I am sorry for delay on this ticket. Lets figure out the first issue with Pro Sites adds here first to not confuse things and mess with each other.

    We need to HIDE the content (ads) to all visitors and users on Pro Sites, regardless of their logged in status, just like the plugin is designed to do—and does via settings—within posts and pages.

    I tested it on my own website, but could not replicate it. It does not show ads on sites to visitors or to lgged in users, when they are upgraded/purchased to a selected Pro Sites plan in Pro Sites > Settings > Advertising > Add Free Level.

    I tried with manual extension downgrading and also with stripe payment gateway. With existing user and site as well as with fresh user and site. But functionality is working just fine for me.

    I conducted this test on my site by deactivating all other plugins and on default WordPress theme.

    Okay now come back on your website. I tested the same thing on your website by creating a test user (wpmutestsajid) and test site (wpmutest) and its also working normal for me. Yes, that said its working the way it should work. It will display ads on free sites to user who are logged in and visitors. User must upgrade his/her site in order to remove ads.

    So here is the conclusion:

    1. On none Pro Sites (free ones) ads shows regardless of user login status (expected behavior).

    2. On Pro Sites (paid/upgraded sites) it does not shows ads at all regardless of user login status (expected behavior).

    To keep things simple, please create separate ticket for widget issue so we don't get confuse.

    Please advice so we can continue :slight_smile:
    Regards,
    Sajid

  • jcnjr

    2. On Pro Sites (paid/upgraded sites) it does not shows ads at all regardless of user login status (expected behavior).

    Thank you for your testing Sajid but this is wrong. Ads ARE still displaying on Pro Sites. The ad no longer appears in the global header at tripawds.com because I removed the ad script! To confirm, scroll all the way to the bottom, as a visitor, not logged in, and you will see the ad in the footer. See attached screenshot.

    It does not show ads on sites to visitors or to lgged in users, when they are upgraded/purchased to a selected Pro Sites plan in Pro Sites > Settings > Advertising > Add Free Level.

    Great, but this is not my concern. I am aware of this setting, but it is not what I need to address. The if (is_pro_site()) code is what I need to get working in the global header. We need to hide ads on Pro sites, to everyone—logged in users, and visitors alike. If a site is a Pro Site, I need to hide the ads. This code has worked for years, but a recent PSTS update has changed something so it no no longer functions as expected.

    Any help fixing that is greatly appreciated, I don't care about the widget right now and will start another ticket for that once we figure this out.

    NOTE: I sent credentials for tripawds.net so we could test there, where the ad script still remains, without any need for additional users and sites at tripawds.com.

  • Sajid

    Hi @jcnjr,
    Hope you are doing good today :slight_smile:

    Okay so you are getting issues with the code snippet. The default functionality to show hide ads on corresponding ads works fine.

    Regarding the code snippet, I tested it on my own website and its working fine for me as expected. I used following code to show in header according to ProSite status and its working fine for me.

    We need to hide ads on Pro sites, to everyone—logged in users, and visitors alike. If a site is a Pro Site, I need to hide the ads.

    The following code snippet is producing the exact same output depending on condition.

    <?php if( is_pro_site() ) :?>
    	<h1>Don't show ads</h1>
    <?php else: ?>
    	<h1>Show ads</h1>
    <?php endif; ?>

    I could not test on your website, because I keep getting the connection time out and error establishing a database connection issue on tripawds.com (getting lots of traffic).

    I created a test site and a test user on your website to not effect your live website and traffic.

    Could you please post the thread link where Aaron or any one else suggested you that code snippet ?

    Take care and have a nice day :slight_smile:
    Cheers, Sajid

  • jcnjr

    We originally added that code years ago, back in the if(is_supporter()) days.

    I can't find the specific topic where Aaron helped us get this working after Pro Sites upgrade.

    Perhaps someone can help me figure this out based on these discussions:

    https://premium.wpmudev.org/forums/topic/using-is_supporter-function-for-pro-sites#post-145699

    https://premium.wpmudev.org/forums/topic/hide-or-show-ads-with-pro-membership

    https://premium.wpmudev.org/forums/topic/is_pro_site-usage-coding-help-please#post-189120

    https://premium.wpmudev.org/forums/topic/third-party-ads-on-free-blogs

    https://premium.wpmudev.org/forums/topic/is-supporter-doesnt-work-as-expected-for-non-logged-in-users

    https://premium.wpmudev.org/forums/topic/conditional-hook-in-prosite

    Thanks in advance for any help!
    For now, I have had to turn off our global header ads. And I will keep looking for the older topics.

  • jcnjr

    So close!

    After digging through many of those threads, I seem to have the following working on our dev install (tripawds.net):

    <?php
    $blog_id = get_current_blog_id();
    if ( is_pro_site($blog_id) ) {
    	//do not show ads
    } else {
    	//show ads
    	?>
    	<!-- AD CODE HERE -->
    <?php
    }
    ?>

    Anyone care to help confirm the following behavior, or provide any other feedback in case I'm doing something messy here?

    Main Site (Pro Site level 1): http://tripawds.net/
    Ads do not show to public, nor if logged in. (Expected)

    Test Pro Site level 1: http://sandbox.tripawds.net/
    Ads do not show to public, nor if logged in. (Expected)

    Test Pro level 2: http://hoang.tripawds.net/
    Ads do not show to public, nor if logged in. (Expected)

    Test Non-Pro Site: http://rvblogz.tripawds.net/
    Ads DO show to public. Ads should NOT show to public. (Expected)

    Just looking for a little reassurance before I add this to our live site.

    Thanks!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.