What? A plugin to determine if the current visitor has CP access Why? Sometimes I wish to show certaun links (publish/edit) only to people with CP Access How? 3 lines of code… but haven’t found any alternative for this:
<?php
$plugin_info = array(
'pi_name' => 'CP Access',
'pi_version' => '1.0',
'pi_author' => 'Boris Toet',
'pi_author_url' => 'http://www.score-advertising.nl',
'pi_description' => 'Determines if the current visitor has CP access.',
'pi_usage' => Cp_access::usage()
);
class Cp_access
{
var $return_data = "";
function Cp_access() {
global $TMPL;
global $SESS;
if($SESS->userdata['can_access_cp'] == 'y') {
$this->return_data = $TMPL->tagdata;
} else {
$this->return_data = '';
}
}
function usage()
{
ob_start();
?>
[code] CP Access
As simple as it gets… just put {exp:cp_access} tags around stuff you only want visible to Members with CP access:
{exp:cp_access}Only Visible to Members with CP Access{/exp:cp_access}
<?php
$buffer = ob_get_contents();
ob_end_clean();
return $buffer;
}
/* END */
} ?> </code></pre>
Still don’t understand why {cp_access} (or something alike) isn’t available as a standard variable.
Hiya,
You must have been reading my mind on this one. I made something just like this a few weeks back. Never got around to uploading it though but I’m sure this will help out a fair few people that want to do this sort of thing.
Still don’t understand why {cp_access} (or something alike) isn’t available as a standard variable.
If it were then what would us add-on developers do with ourselves? 😉
Best wishes,
Mark
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.