Permission based content

Permission based content

We needed a simple permission based content plugin. So, I wrote one which adds a couple shortcodes where you can specify what permission is required to view the content. Usage is as follows:

[user]This content will shown to any authenticated user.
 It will not be shown to any visitor.[/user]
[user can=read]This content will shown to any user with 
subscriber or higher privs.[/user]
[user can=edit_published_posts]This content will shown 
to any user with author or higher privs.[/user]

See the Codex for the list of permissions.

Download it here: [download#24]

(Visited 1 times, 1 visits today)
  • WordPress Plugin Releases for 10/27 « Weblog Tools Collection
    Posted at 09:02h, 27 October Reply

    […] Content by Permission adds a couple shortcodes where you can specify what permission is required to view the content. […]

  • Thomas
    Posted at 12:05h, 02 November Reply


    Thank you for this little plugin! I tweaked it a little bit as I needed to make some shortcode working inside this plugin shortcode. For this purpose, I changed the $content to do_shortcode($content)

    This is a life saver plugin! 🙂

    • chuck scott
      Posted at 17:52h, 31 July Reply

      Hi – can you post your code how you changed it to allow shortcodes within shortcodes as i’ve tried a number of things to no avail – e.g., i modifed Andrea and Ron’s original to this ->


      but when i put the following shortcodes in a page like this ->


      To create your FREE Community Ads you must be [cs-loginlink] to do so …

      God Bless!



      [formidable id=9]


      what i get is the cs-loginlink jumps out of context when page is viewed …
      so it reads and looks silly thus i know i’m missing something with shortcodes within shortcodes …

      thanks in advance for any pointers you can share … cordially, chuck scott

      ps – here is my custom login shortcode from child theme functions file ->

      /* CS - create shortcode for customized Log in with page redirect back to page before login */
      add_shortcode( 'cs-loginlink', 'cs_login_link' );
      function cs_login_link() {
      return wp_loginout( get_permalink() );

      • Ron
        Posted at 17:59h, 31 July Reply

        You can’t do shortcodes within shortcodes. The post above does not suggest that you can. You can use multiple shortcodes in a post as long as they are not nested.

        • chuck scott
          Posted at 17:14h, 01 August Reply

          Hi Ron – thanks for quick response … turns out i was able to get the example above to work and that my problem had to do with my shortcode cs-loginlink and the use of wp_loginout … once i changed from wp_loginout to wp_login_url then things started to come together (see new shortcode function below) …

          then when i put my login shortcode within your [visitor] shortcode, that indeed did not work but i found two conditions in which it would work …

          a) if i added the following filter to my child theme’s function file, then i could have my login shortcode work within your visitor shortcode ->

          add_filter('the_content', 'do_shortcode'); */

          b) the other alternative which was alluded to above by Thomas also seemed to work in that if i commented out the filter i just mentioned, and modified your code as follows it too allowed the login link to work within the visitor link –

          /* Add Ron and Andrea Content by Permission v 0.1 */
          function ra_user_content( $atts, $content = '' ) {
          if( empty( $atts ) && is_user_logged_in() )
          return do_shortcode($content);
          if( !empty( $atts['can'] ) && current_user_can( $atts['can'] ) )
          return do_shortcode($content);
          return '';
          function ra_visitor_content( $atts, $content = '' ) {
          if( !is_user_logged_in() )
          return do_shortcode($content);
          return '';
          add_shortcode( 'user', 'ra_user_content' );
          add_shortcode( 'visitor', 'ra_visitor_content' );

          accordingly, do you see any danger using the modified version of your visitor user code with said shortcode enhancements ..??.. currently it seems to work in IE and Firefox and is not generating any php errors that i can see on server …

          truly appreciate your input and certainly all the code love you and Andrea share with WP community … thanks in advance for attention to this … cordially, chuck scott

          My New shortcode for login link ->

          /* CS - create shortcode for customized Log in with page redirect back to page before login */
          add_shortcode( 'cs-loginlink', 'cs_login_link' );
          function cs_login_link($attr, $content) {
          $out = 'login';
          return do_shortcode ( $out );

          • chuck scott
            Posted at 17:19h, 01 August

            oops … the $out line seemed to get truncated even though i surrounded it with code tags so will try again but using long hand –

            original - $out = 'login';

            long hand - dollar sign out = span style font weight bold href wp_login_url get permalink title = click here .... login word close a close span end php line

  • Richard
    Posted at 05:04h, 17 January Reply

    Hi there – i just wanted to say thanks for this too. Really helpful.


Post A Comment