September 9, 201313 yr Hi everyone, I've got a PHP issue that's giving me some grief. I know it's wrong, but I just can't determine exactly what the issue is. I'm using the WPMU Membership plugin, which comes with some shortcodes to protect content from various audiences. I need to display the logged in users name and a logout link that redirects them to a specific page. The shortcode ("not-level-general-public") included below stops non logged in users from seeing this section. I know my "echo do_shortcode" code works, as I'm using identical code elsewhere on the site, however there's something about the code inside my echo statement (below) that's returning errors. I think it's something to do with opening another PHP string within a PHP string, but my PHP knowledge is not strong enough to determine the problem. Can anyone tell me where I'm going wrong? Cheers, Chris <?php echo do_shortcode('[not-level-general-public] <p>Hello, <?php global $current_user; get_currentuserinfo(); echo $current_user->user_firstname; ?></p> <a href="<?php echo wp_logout_url('/aspire-login/'); ?>">Log Out</a> [/not-level-general-public]'); ?>
September 10, 201313 yr <?php echo do_shortcode('[not-level-general-public]); ?> <p>Hello, <?php global $current_user; get_currentuserinfo(); echo $current_user->user_firstname; ?></p> <a href="<?php echo wp_logout_url('/aspire-login/'); ?>">Log Out</a> <?php echo do_shortcode('[/not-level-general-public]); ?> Try that.
September 10, 201313 yr <?php echo do_shortcode('[not-level-general-public]); ?> <p>Hello, <?php global $current_user; get_currentuserinfo(); echo $current_user->user_firstname; ?></p> <a href="<?php echo wp_logout_url('/aspire-login/'); ?>">Log Out</a> <?php echo do_shortcode('[/not-level-general-public]); ?> Try that. Nearly! Try this: <?php echo do_shortcode('[not-level-general-public]'); ?> <p>Hello, <?php global $current_user; get_currentuserinfo(); echo $current_user->user_firstname; ?></p> <a href="<?php echo wp_logout_url('/aspire-login/'); ?>">Log Out</a> <?php echo do_shortcode('[/not-level-general-public]'); ?>
September 23, 201313 yr Author Thank you both for your speedy replies, and apologies for my delay in getting back to you. I've got family visiting from Australia, and have been playing tour guide for the last couple of weeks. Think I'll need a holiday once they've gone home... ;-) I've added the code you suggested, and although it appears to work better than any previous iteration, it doesn't quite appear to have done the trick. Both the username and the log out links work, but the content is visible to all users, not just logged in ones. Also, the closing shortcode code is visible to front end users (see screenshot01.png). I'm using the following variation elsewhere on the site, and it appears to work without any issues: <?php echo do_shortcode('[level-clients] <div class="widget category_posts_widget"> <h3 class="widget-title">Your Account</h3> <ul> <li><a href="http://www.domain.com/add-profile/">Add Your Profile</a></li> <li><a href="http://www.domain.com/profile-edit-request/">Request Profile Edit</a></li> </ul> </div> <!-- closes "member-details" --> [/level-clients]'); ?> It appears that you need to leave that 'echo do_shortcode' statement open, and the code that you want hidden / displayed in a certain area goes between the opening and closing shortcodes. The problem is I have no idea how to include the PHP statements within that code without opening and closing them first. I'm certainly no expert, but I suspect the issue is something to do with having additional PHP statements opening and closing inside the shortcode. If I use just plain HTML, then there are no problems. However as soon as I add PHP, that's when I encounter errors. Any further thoughts?
September 23, 201313 yr Your syntax is wrong. When it says to leave the shortcode open it means like this: <?php echo do_shortcode('[level-clients]); ?> without the closing : <?php echo do_shortcode('[/level-clients]'); ?> You always need to close your php statement with ; ?> before you start your html.
September 23, 201313 yr Author Hi Mantis. Thanks again for your reply, but this still doesn't work, unfortunately. Using the example above that A posted results in that screenshot I posted earlier, where you can see the closing shortcode on the front end of the site. The example that I posted earlier this morning works perfectly. When the user is not logged in, they can't see the content, and when they are, the appropriate content is visible to them. For the time being, I'm going to remove this section from the site and hopefully revisit it at a later stage. It's taking up too much time trying to figure it out, and the client is keen to have the project completed. Thanks again everyone!
September 23, 201313 yr Author Hmmm... earlier screenshot doesn't appear to have come through. Just in case it helps.
Create an account or sign in to comment