• Hi Guys,

    I have created some custom widgets and I want those widgets to be displayed to certain user groups.
    For example, I have created a widget titled ‘Top Team’. This widget should only be displayed when a member of the Top team has logged in.
    For the creation of user groups, I had used “Role Scoper” plugin.
    I tried using a number of “Widgets plugins” available such as Widget Logic, Custom Widgets and few others. But I was unable to display the widgets for certain user groups.
    Can someone please help me with this?
    Please let me know what condition should I add in Widget Logic so that members of a particular group can only see some widgets which are intended for them. Can I specify multiple user Ids in condition for Widget logic and how?

    Thanks in advance.

    Regards,
    Vishal Wadkar.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Any luck with this? Would like the same ability!

    role scoper’s documentation seems quiet on this, but a quick look through the code I can see code like

    $user_groups = WP_Scoped_User::get_groups_for_user( );

    which combined with wp_get_current_user http://codex.wordpress.org/Function_Reference/wp_get_current_user

    should get you what you want, though I think the $user_groups array you get back is an array of group IDs which may not be super helpful. Anyway, here’s my untested code example:

    $current_user = wp_get_current_user();
    if (0==$current_user->ID ) return false;
    $user_groups = WP_Scoped_User::get_groups_for_user( $current_user->ID );
    return in_array([group_id_to_test], $user_groups));

    Hi alanft,

    thanks for the answer. I actually managed to use widget logic and just check for an ability. Seemed to be easiest. See following links for possibilities:

    http://codex.wordpress.org/Function_Reference/current_user_can

    Link to some other widget logic possibilities:
    http://wparena.com/how-to/how-to-hide-show-widgets-on-certain-wordpress-pages-posts-categories/

    Hope that will help people!

    Looking for the same thing here. Using Role Scoper and Widget Logic. Also want to display widgets when a user belonging to a certain user group is logged in. So far I have:

    $group_id_in_question = 9;
    global $current_user;
    if ( isset( $current_user->groups[ $group_id_in_question ] ) );

    But when I logged in as a user under group 9 I do not see that widget.

    Tried

    $group_id_in_question = 9;
    $current_user = wp_get_current_user();
    global $current_user;
    if ( isset( $current_user->groups[ $group_id_in_question ] ) );

    but I do not see the widget

    Got help . Had to use $wpdb to access the needed data in the database, declare this variable and a few others global to access them from functions.php and write a function to get the RS user group connected to to the current user.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Show Widget depending on user Group’ is closed to new replies.