Support Forum

Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
coding-topic
spa_get_usergroups_all();
Avatar
Stan Dahl
Member
sp_UserOfflineSmall Offline
Oct 12, 2015 - 10:58 am

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!

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Oct 12, 2015 - 9:20 pm

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...

Avatar
Stan Dahl
Member
sp_UserOfflineSmall Offline
Oct 14, 2015 - 5:11 pm

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!

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Oct 14, 2015 - 5:25 pm

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...

andy-signature.png
YELLOW
SWORDFISH
Avatar
Stan Dahl
Member
sp_UserOfflineSmall Offline
Oct 15, 2015 - 5:58 pm

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?

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Oct 16, 2015 - 4:00 am

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);
andy-signature.png
YELLOW
SWORDFISH
Avatar
Stan Dahl
Member
sp_UserOfflineSmall Offline
Oct 16, 2015 - 9:46 am

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

Avatar
Stan Dahl
Member
sp_UserOfflineSmall Offline
Oct 16, 2015 - 10:01 am

ok, made a bit of progress on this:

$swl_ugroups = spdb_table(SFUSERGROUPS);

this is actually giving me an array.

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Oct 16, 2015 - 10:44 am

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...

andy-signature.png
YELLOW
SWORDFISH
Forum Timezone: Europe/Stockholm
Most Users Ever Online: 1170
Currently Online:
Guest(s) 1
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Mr Papa: 19448
Ike: 2086
Brandon: 864
kvr28: 804
jim: 649
FidoSysop: 577
Conrad_Farlow: 531
fiddlerman: 358
Stefano Prete: 325
Member Stats:
Guest Posters: 618
Members: 17357
Moderators: 0
Admins: 4
Forum Stats:
Groups: 7
Forums: 17
Topics: 10123
Posts: 79616