| 1 |
<?php |
| 2 |
|
| 3 |
/******************************************* |
| 4 |
* Restrict Content Short Codes |
| 5 |
*******************************************/ |
| 6 |
|
| 7 |
function restrict_shortcode( $atts, $content = null ) { |
| 8 |
extract( shortcode_atts( array( |
| 9 |
'userlevel' => 'none', |
| 10 |
), $atts ) ); |
| 11 |
|
| 12 |
global $rc_options; |
| 13 |
|
| 14 |
if ($userlevel == 'admin' && current_user_can('switch_themes')) |
| 15 |
{ |
| 16 |
return do_shortcode($content); |
| 17 |
} |
| 18 |
if ($userlevel == 'editor' && current_user_can('moderate_comments')) |
| 19 |
{ |
| 20 |
return do_shortcode($content); |
| 21 |
} |
| 22 |
if ($userlevel == 'author' && current_user_can('upload_files')) |
| 23 |
{ |
| 24 |
return do_shortcode($content); |
| 25 |
} |
| 26 |
if ($userlevel == 'contributor' && current_user_can('edit_posts')) |
| 27 |
{ |
| 28 |
return do_shortcode($content); |
| 29 |
} |
| 30 |
if ($userlevel == 'subscriber' && current_user_can('read')) |
| 31 |
{ |
| 32 |
return do_shortcode($content); |
| 33 |
} |
| 34 |
if ($userlevel == 'none' && is_user_logged_in()) |
| 35 |
{ |
| 36 |
return do_shortcode($content); |
| 37 |
} |
| 38 |
else return '<span style="color: red;">' . str_replace('{userlevel}', $userlevel, $rc_options['shortcode_message']) . '</span>'; |
| 39 |
} |
| 40 |
add_shortcode('restrict', 'restrict_shortcode'); |
| 41 |
|
| 42 |
function rc_not_logged_in($atts, $content = null) { |
| 43 |
if(!is_user_logged_in()) { |
| 44 |
return do_shortcode( $content ); |
| 45 |
} |
| 46 |
} |
| 47 |
add_shortcode('not_logged_in', 'rc_not_logged_in'); |
| 48 |
|