Log in

View Full Version : Prevent AdSense on not_logged_no_permission pages?


chefy
05-06-2014, 04:58 PM
If for example a guest is trying to access a thread posted on a members-only forum he will get an error message that says:

You are not logged in or you do not have permission to access this page. This could be due to one of several reasons:

blah blah blah...


I want to prevent AdSense to be shown on those specific not_logged_no_permission pages, how I can do that please? Thanks!

kh99
05-06-2014, 09:57 PM
The problem is that the ad templates (and header and footer templates) are rendered before you know if there is a permission problem. I suppose it's possible to re-render those templates in the case of an error (maybe using the error_nopermission hook), but it might take some code. At the minimum you'd need a "global" statement for any variables that the header or footer uses.

I guess another approach would be to do a str_replace() on the $header or $footer variables to remove the AdSense, but you'd have to figure out what you could match to do that.

chefy
05-06-2014, 10:43 PM
Thanks God I'm not using the ad templates, the AdSense code is directly attached to the navbar template. Is there any conditional I can use there against not_logged_no_permission pages?

kh99
05-06-2014, 11:04 PM
You might be able to create a plugin using hook error_nopermission and code like:
$show['hide_adsense'] = true;

then in the template surround your adsense code with:
<if condition="!$show['hide_adsense']">
// adsense code
</if>

There might be something you could check so that you wouldn't need the plugin, but I couldn't see anything that was immediately obvious.

Simon Lloyd
05-07-2014, 06:27 AM
Or in the template you could simply use this if condition<if condition="$show['search_engine']">

chefy
05-07-2014, 02:15 PM
You might be able to create a plugin using hook error_nopermission and code like:
$show['hide_adsense'] = true;

then in the template surround your adsense code with:
<if condition="!$show['hide_adsense']">
// adsense code
</if>

There might be something you could check so that you wouldn't need the plugin, but I couldn't see anything that was immediately obvious.

Unfortunately it's not working. When using your conditional I can still see the contents at every page even on those no permissions pages. Removing the ! prevents the content from being displayed at all pages without distinguishing no permission pages and yep I have double checked that I'm using the error_nopermission hook.

Or in the template you could simply use this if condition<if condition="$show['search_engine']">

Unfortunately this is also not working. It shows nothing at any page and when using the same conditional but preceded with a ! it shows the contents in all pages regardless if those are no permission pages.

I'm trying to do this in the navbar template, vBulletin 3.8.5

kh99
05-07-2014, 07:01 PM
Oh, maybe you need to add a global statement, like:
global $show;
$show['hide_adsense'] = true;

chefy
05-08-2014, 05:26 AM
It works, thank you very much man - you rock!

Simon Lloyd
05-08-2014, 04:49 PM
Unfortunately this is also not working. It shows nothing at any page and when using the same conditional but preceded with a ! it shows the contents in all pages regardless if those are no permission pages.

I'm trying to do this in the navbar template, vBulletin 3.8.5That shows it is working, preceeding it with ! means IF visitor (of any kind) is NOT a search engine then show everything inside the conditional, however if you were a search engine it will NOT show to you.