• Resolved andreasTypo

    (@andreastypo)


    Hi,

    First of all, the plugin is awesome.
    Really flexible and does exactly what you expect. Awesome job!

    I had a question though;
    When adding shortcode in my editor / wysiwyg it works perfect, like this;

    
    [restrict role="subscriber" page="391"]
    
    MY RESTRICTED CONTENT
    
    [/restrict]
    [login-form]
    

    The field was created with ACF, so I tried to add the shortcode in my page template as such;

    
    <?php echo do_shortcode("[restrict role="subscriber" page="391"]"); ?>
    
    <?php if (get_field('portfolio_item')) : ?>
        <?php echo wp_kses_post(get_field('portfolio_item')) ?>
    <?php endif; ?>
    
    <?php echo do_shortcode("[/restrict][login-form]"); ?>
    

    The code seems to break up and shows the content anyway and only 1 part of the code “[/restrict]”.

    I want to add the shortcode in the page template, so the client won’t be able to mess it up by accident.
    Am I missing something?

    Thanks!
    Kind regards

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter andreasTypo

    (@andreastypo)

    minor update
    Putting it all together as such fixes the rogue “[/restrict]” tag;

    
    <?php if (get_field('portfolio_item')) : ?>
        <?php echo do_shortcode("[restrict role='subscriber']".wp_kses_post(the_field('portfolio_item'))."[/restrict]"); ?>
    <?php endif; ?>
    

    However, content is shown even though a visitor isn’t logged in with subscriber access, so the plugin functionality loses its purpose now.

    Thanks in advance.
    Regards

    Plugin Author Joachim Jensen

    (@intoxstudio)

    If you are editing templates, I suggest using the PHP API instead of shortcodes. It could look something like this:

    
    $user = rua_get_user();
    $level_id = 123;
    
    if ($user && $user->has_level($level_id) && get_field('portfolio_item')) {
        the_field('portfolio_item');
    } else {
        echo get_the_content(null, false, 391);
    }
    

    I hope this helps!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘do_shortcode in page template’ is closed to new replies.