How do I disable tracking for editable users (canAdminPage?)
Permalink
How do I access the old canAdminPage() method for the current page in order to disable tracking codes? I don't want admin users triggering google analytics hits as they navigate around my site.
I found out how to do this in 5.6, but the page properties have since changed and I've searched for a couple of hours and not found an answer for 5.7
I found out how to do this in 5.6, but the page properties have since changed and I've searched for a couple of hours and not found an answer for 5.7
Nobody have any ideas?
It should work the same way as it has before if you're calling the method for the permissions object (or actually it's permission checker in 5.7). I don't understand what you refer to by saying "the page properties have since changed". I don't think the method names for the permission checker have changed.
If you posted your code in the topic, it might help to see your problem. Also, if you see some error messages, post them too.
If you posted your code in the topic, it might help to see your problem. Also, if you see some error messages, post them too.
I was using code from this page:http://www.concrete5.org/documentation/how-tos/developers/how-to-hi...
The new footer require code is thus:
But this just returns the tracking code regardless with no errors.
<?php $_trackingCodePosition = Config::get('SITE_TRACKING_CODE_POSITION'); if (empty($disableTrackingCode) && (empty($_trackingCodePosition) || $_trackingCodePosition === 'bottom')) { global $cp; if (is_object($cp) && ($cp->canWrite() || $cp->canAddSubContent() || $cp->canAdminPage())) { echo '<!-- tracking code disabled -->'; } else { echo Config::get('SITE_TRACKING_CODE'); } } print $this->controller->outputFooterItems(); ?>
The new footer require code is thus:
<?php $c = Page::getCurrentPage(); if (is_object($c)) { $cp = new Permissions($c); Loader::element('page_controls_footer', array('cp' => $cp, 'c' => $c)); } $_trackingCodePosition = Config::get('concrete.seo.tracking.code_position'); if (empty($disableTrackingCode) && (empty($_trackingCodePosition) || $_trackingCodePosition === 'bottom')) { global $cp; if (is_object($cp) && ($cp->canWrite() || $cp->canAddSubContent() || $cp->canAdminPage())) { echo '<!-- tracking code disabled -->'; } else { echo Config::get('SITE_TRACKING_CODE'); } }
Viewing 15 lines of 19 lines. View entire code block.
But this just returns the tracking code regardless with no errors.
Thanks! The "old way" still works, just need to change:
to:
Thanks for saving me! How do we get that "How To" page updated?
Cheers
global $cp;
to:
$cp = new Permissions($c);
Thanks for saving me! How do we get that "How To" page updated?
Cheers
By the way, I think it would be way easier to do it straight in the "footer_required" element call.
Meaning that this should work too in your footer (although have not tested):
Meaning that this should work too in your footer (although have not tested):
Your first solution worked, but I do prefer the second option and having it in the theme, rather than overriding system files.
The second one works, but I replaced view with Loader, since that seems to be how the header works when passing parameters in. I take it that the header required can have the same parameters passed like this?
The second one works, but I replaced view with Loader, since that seems to be how the header works when passing parameters in. I take it that the header required can have the same parameters passed like this?
You should also be able to pass the same parameters as the second argument to the View::element() call. The Loader method is just a synonym / backwards compatibility function for the same thing.
I can see the Loader call is still being used in the core themes as well but its use should be discouraged as it's a legacy method.
I can see the Loader call is still being used in the core themes as well but its use should be discouraged as it's a legacy method.