Support Forum

spa_get_usergroups_all();

SD Stan Dahl
Stan Dahl
Member

Hi,

I want to use this function and I need to want what it returns.

spa_get_usergroups_all();

Is it an array? or multi-dimensional array?

Also, to call this from a 3rd party plugin’s admin panel in the WordPress admin, do I need to instantiate anything or refer to any global objects?

Thanks for your help!

8 Answers

New Answer

MP Mr Papa
Mr Papa
Member

before calling the function, you might need to add:

sp_forum_api_support();

which will make sure forum api is fully loaded…

the function will return a php object… the members are the columns of the sfusergroups table in the db…

SD Stan Dahl
Stan Dahl
Member

HI Mr Papa – thank you for your help.

One last part I’m stuck with, if spa_get_usergroups_all() returns an object, is it of a particular class?

What I am expecting is some kind of list of all of the usergroups in the table.

so if I have:

$usergrps = spa_get_usergroups_all();

I can’t do:

$usergrps->usergroup_name;

because I need to iterate the rows of the table some how.

I’m sure I’m just not seeing the obvious with this, but any light you can shed on this would be greatly appreciated.

Thanks!

YS Yellow Swordfish
Yellow Swordfish
Member

You must extract the data in the

$usergrps->usergroup_name

form. It returns a class of the WP database OBJECT type. As, by default and if no user group ID is passed, it returns all user groups in the table – then you will need to iterate through them using a foreach loop.

So – something along the lines of:

$userGroups = spa_get_usergroups_all();
if($usergGroups) {
    foreach($userGroups as $group) {
        $group_name = $group->usergroup_name;
        // etc...
    }
}

is what you need…

SD Stan Dahl
Stan Dahl
Member

Hi Guys,

The following code is failing on the red function call

if ( function_exists ( ‘sp_forum_api_support’ ) ) {
   sp_forum_api_support();
   $swl_ugroups = spa_get_usergroups_all();

   …
}

Not sure how to debug this.

Does sp_forum_api_support() have any return values?

YS Yellow Swordfish
Yellow Swordfish
Member

I can see there may be one or two function sequencing issues. Instead of making that call why not just use the code it contains which is – quite simply:

$swl_ugroups = return spdb_table(SFUSERGROUPS);
SD Stan Dahl
Stan Dahl
Member

is “SFUSERGROUPS” a constant defined somewhere?

as it is written: $swl_ugroups = return spdb_table(SFUSERGROUPS);

doesn’t work either.

Is there something I’m missing with this entire setup?

Right now I have the Simple Press plugin installed. Is anything else needed for this to work?

I really don’t want to get to the point of writing a direct database call to the table myself

SD Stan Dahl
Stan Dahl
Member

ok, made a bit of progress on this:

$swl_ugroups = spdb_table(SFUSERGROUPS);

this is actually giving me an array.

YS Yellow Swordfish
Yellow Swordfish
Member

Sounds good. The main problem is one of scope. Any decent plugin will try and only load the components that are absolutely necessary on page loads where the plugin is not the actual focus. We actually take some pride in this respect and this function you were chasing (and I know we suggested it!) is not really a part of our API that is easier to expose.

Let us know how it goes…