Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #907158
    cwallace
    Participant

    Hi guys,

    Kind of an advanced question, but here goes. I need to add a bit of code that will either allow or disallow the display of the sidebar based on role. I know how to do that, so that’s not the question. 😀 The question is, would wp-sidebar.php be the most appropriate place add that code? Here’s why: the code in wp-sidebar.php is short and sweet, as follows:

    <?php if ( x_get_content_layout() != ‘full-width’ ) : ?>

    <aside class=”<?php x_sidebar_class(); ?>” role=”complementary”>
    <?php if ( get_option( ‘ups_sidebars’ ) != array() ) : ?>
    <?php dynamic_sidebar( apply_filters( ‘ups_sidebar’, ‘sidebar-main’ ) ); ?>
    <?php else : ?>
    <?php dynamic_sidebar( ‘sidebar-main’ ); ?> <<<<– ADD MY CODE HERE?
    <?php endif; ?>
    </aside>

    <?php endif; ?>

    Rather than muck about in the dynamic_sidebar routine, I can add my conditional right above the call to it, which as far as I can tell, would work just fine. If there’s a better way, however, please enlighten me. 🙂

    Thanks!
    Chris

    #907687
    Christian
    Moderator

    Hey Chris,

    Yes, that is the correct place.

    Thanks.

    #908109
    cwallace
    Participant

    Thanks. Anyone needing to disable the sidebar on pages/posts where the user/role has to have permission can use the following. It’s in wp-sidebar.php in x/framework/views/integrity. Save the changed version of the file to x-child/framework/views/integrity.

    <?php if ( x_get_content_layout() != 'full-width' ) : ?>
    
      <aside class="<?php x_sidebar_class(); ?>" role="complementary">
        <?php if ( get_option( 'ups_sidebars' ) != array() ) : ?>
            <?php if ( current_user_can( 'edit_posts' ) ) : ?>
                   <?php dynamic_sidebar( apply_filters( 'ups_sidebar', 'sidebar-main' ) ); ?>
            <?php endif; ?>
        <?php else : ?>
            <?php if ( current_user_can( 'edit_posts' ) ) : ?>
               <?php dynamic_sidebar( 'sidebar-main' ); ?>
            <?php endif; ?>
        <?php endif; ?>
      </aside>
    
    <?php endif; ?>
    
    #908455
    Nico
    Moderator

    Hi There,

    Thank you so much for sharing. We really appreciate it.

    Feel free to share and to let us know if you need anything else.

    Thanks.

  • <script> jQuery(function($){ $("#no-reply-907158 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>