• Anonymous User 9906592

    (@anonymized-9906592)


    Hi All,

    The groups plugin is great, and is quite frankly a must-have for WordPress developer. However, I run into snags from time to time… like this one:

    How do you check if a user belongs to a group, *within a shortcode file*?. It seems that when I use the following snippet (recommended on the plugin author’s site), the script breaks. From what I can tell, the include that calls on pluggable.php is where the failure is, unless I’m missing something somewhere. (?)

    $is_a_member = false;
    require_once( ABSPATH . 'wp-includes/pluggable.php' );
    if ( $group = Groups_Group::read_by_name( $wmbf_group_capability ) ) {
    $is_a_member = Groups_User_Group::read( get_current_user_id() , $group->group_id );
    }
    echo 'Result is: '.$is_a_member. '<br>';

    This breaks the page, where it works just fine if I use it elsewhere in my theme’s normal display/page files. I even did a basic test to see if the include by itself is successful or not, and it appears to come back as unsuccessful.

    Suggestions on how to achieve this?

    To note: the shortcode is declared in my functions.php file, and within that shortcode declaration I do an include to another .php file that has the guts of the shortcode’s processing in it.

    Pulling out my hair. Thanks much for any input,

    HJ

    https://wordpress.org/plugins/groups/

Viewing 1 replies (of 1 total)
  • Hi HJ,
    The code seems correct, be sure your $wmbf_group_capability is defined.
    Did you get any errors in debug.log?
    Please enable debug, edit wp-config.php and replace the following line

    define('WP_DEBUG', false );

    with these lines

    define('WP_DEBUG', true );
    define('WP_DEBUG_DISPLAY', false);
    define('WP_DEBUG_LOG', true );

    Then visit your page. If errors exist then a file named debug.log under wp-content folder will be created.

    Kind Regards,
    Antonio B.

Viewing 1 replies (of 1 total)
  • The topic ‘Groups – Check if user in group, *within shortcode*’ is closed to new replies.