Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Alternative is to use: https://wordpress.org/plugins/user-access-shortcodes/
- //
- /**
- * Registers the [is_admin][/is_admin] shortcode
- * This shortcode displays content only to administrator users
- *
- * Example usage: [is_admin][site_reviews_form][/is_admin]
- *
- * Paste this in your active theme's functions.php file
- * @param array $atts
- * @param string $content
- * @return string
- */
- add_shortcode('is_admin', function ($atts, $content = '') {
- return (current_user_can('administrator') && !empty($content) && !is_feed())
- ? do_shortcode($content)
- : '';
- }, 10, 2);
- /**
- * Registers the [is_member][/is_member] shortcode
- * This shortcode displays content only to logged in users
- *
- * Example usage: [is_member][site_reviews_form][/is_member]
- *
- * Paste this in your active theme's functions.php file
- * @param array $atts
- * @param string $content
- * @return string
- */
- add_shortcode('is_member', function ($atts, $content = '') {
- return (is_user_logged_in() && !empty($content) && !is_feed())
- ? do_shortcode($content)
- : '';
- }, 10, 2);
- /**
- * Registers the [is_guest][/is_guest] shortcode
- * This shortcode displays content only to users who are not logged in
- *
- * Example usage: [is_guest][site_reviews_form][/is_guest]
- *
- * Paste this in your active theme's functions.php file
- * @param array $atts
- * @param string $content
- * @return string
- */
- add_shortcode('is_guest', function( $atts, $content = '') {
- return ((!is_user_logged_in() && !empty($content)) || is_feed())
- ? do_shortcode($content)
- : '';
- }, 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement