Groups – Check if user in group, *within shortcode*
-
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
- The topic ‘Groups – Check if user in group, *within shortcode*’ is closed to new replies.