Forums

[resolved] Restrict visibility of sidebar widgets to pre-assigned user level (3 posts)

  1. sweetangst
    Member
    Posted 2 years ago #

    WP: WordPress 2.8.1
    Plugins:

    • Role Scoper
    • Sidebar Login

    I'm using Role Scoper to do what Post Levels used to do.

    E.g. I have Categories 0, 1, 2, 3... and User Group Levels 0, 1, 2, 3.. etc and your User Group Level must be equal to or greater than the category level to be able to read posts in that category.

    Now what I want to do is restrict the visibility of certain sidebar widgets within the post template -- not the page template.

    I already have separate sidebars for Pages vs Posts. So the index.php of the site is a Page with an empty sidebar. The rest of the blog is all post based and has a sidebar with all the widgets.

    After logging in a user is taken to the blog posts and shown whatever posts they have the access to view along with the widget-filled sidebar.

    What I want to do is impliment some kind of extra query so that if your User Level is >0, you can see the widgets. If your user level =0, you don't.

    Any suggestions on where to start with that?

    First thoughts: Add visibility query to dynamic sidebar and then just add the php code for sidebar login for the static sidebar so that the user gets the sidebar login widget no matter what.

  2. sweetangst
    Member
    Posted 2 years ago #

    Addition to above: So I'm guessing I've got to create an sql query that looks in the table where the groups are and finds out what the group is for the current user, using this, and then use something like the if/else statement at the bottom.

  3. sweetangst
    Member
    Posted 2 years ago #

    MWUAHAHAHA I WIN!

    <div id="sidebar">
    <ul style="margin-top: 0px;">
    <?php
    	global $user_ID;
    	get_currentuserinfo();
    	$queryface = $wpdb->get_var("SELECT group_id FROM $wpdb->user2group_rs WHERE user_id=$user_ID");
    	?>
    
    	<?php if($queryface > 6):
    		dynamic_sidebar();
    	 elseif ($queryface <= 6): {
    	echo "<li>";
    	sidebarlogin();
    	echo "</li>";
    } endif; ?>
    </ul>
    </div>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.