Shortcode to Hide a Section of Content from Everyone but the Author
-
I am trying to create a shortcode that I can wrap around a piece of content to hide ot from everyone but the author who wrote the content. (I want to use it for an “edit this post” link). I am using this:
function authoronly( $atts, $content = null ) { if( is_user_logged_in() and // Force user validation... STUFF !empty($GLOBALS['post']) and // Check if a $post exists in globals !empty($GLOBALS['current_user']) and // Check if current_user exists in globals ($GLOBALS['current_user']->ID == $GLOBALS['post']->post_author) // Match User IDs ){ $content } add_shortcode("authoronly", "authoronly");
I think the nested brackets are causing the problem. Any suggesion?
Thanks
- The topic ‘Shortcode to Hide a Section of Content from Everyone but the Author’ is closed to new replies.