PluginProbe
wpForo Forum / 2.3.0
wpForo Forum v2.3.0
3.1.5 3.1.4 3.1.2 3.1.1 3.1.0 3.0.9 3.0.8 3.0.7 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.2 All 137 releases
wpforo / classes / UserGroups.php

UserGroups.php in wpForo Forum 2.3.0, at classes/UserGroups.php

617 lines 19.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace wpforo\classes;
4
5 use stdClass;
6
7 // Exit if accessed directly
8 if( ! defined( 'ABSPATH' ) ) exit;
9
10 class UserGroups {
11 public $default;
12 public $default_groupid;
13 public $cans;
14 public $current;
15 private $post_flood_intervals;
16
17 function __construct() {
18 $this->init_defaults();
19 $this->cans = apply_filters( 'wpforo_usergroup_cans', $this->default->cans );
20 $this->init_hooks();
21 }
22
23 private function init_defaults() {
24 $this->default = new stdClass;
25
26 $this->default->default_groupid = 3;
27
28 $this->default->group = [
29 'groupid' => 0,
30 'name' => '',
31 'cans' => '',
32 'description' => '',
33 'utitle' => '',
34 'role' => '',
35 'access' => '',
36 'color' => '',
37 'visible' => 0,
38 'secondary' => 0,
39 'is_default' => 0,
40 ];
41
42 $this->default->post_flood_intervals = [
43 0 => 0,
44 1 => 0,
45 2 => 0,
46 3 => 0,
47 4 => 0,
48 5 => 0,
49 ];
50
51 $this->default->cans = [
52 'mf' => __( 'Dashboard - Manage Boards & Forums', 'wpforo' ),
53 'ms' => __( 'Dashboard - Manage Settings', 'wpforo' ),
54 'mt' => __( 'Dashboard - Manage Tools', 'wpforo' ),
55 'vm' => __( 'Dashboard - Manage Members', 'wpforo' ),
56 'aum' => __( 'Dashboard - Moderate Topics & Posts', 'wpforo' ),
57 'vmg' => __( 'Dashboard - Manage Usergroups', 'wpforo' ),
58 'mp' => __( 'Dashboard - Manage Phrases', 'wpforo' ),
59 'mth' => __( 'Dashboard - Manage Themes', 'wpforo' ),
60
61 'em' => __( 'Dashboard - Can edit member', 'wpforo' ),
62 'bm' => __( 'Dashboard - Can ban member', 'wpforo' ),
63 'dm' => __( 'Dashboard - Can delete member', 'wpforo' ),
64
65 'aup' => __( 'Front - Can pass moderation', 'wpforo' ),
66 'view_stat' => __( 'Front - Can view statistic', 'wpforo' ),
67 'vmem' => __( 'Front - Can view members', 'wpforo' ),
68 'vprf' => __( 'Front - Can view profiles', 'wpforo' ),
69 'vpra' => __( 'Front - Can view member activity', 'wpforo' ),
70 'vprs' => __( 'Front - Can view member subscriptions', 'wpforo' ),
71
72 'upc' => __( 'Front - Can upload cover', 'wpforo' ),
73 'upa' => __( 'Front - Can upload avatar', 'wpforo' ),
74 'ups' => __( 'Front - Can have signature', 'wpforo' ),
75 'va' => __( 'Front - Can view avatars', 'wpforo' ),
76
77 'vmu' => __( 'Front - Can view member username', 'wpforo' ),
78 'vmm' => __( 'Front - Can view member email', 'wpforo' ),
79 'vmt' => __( 'Front - Can view member title', 'wpforo' ),
80 'vmct' => __( 'Front - Can view member custom title', 'wpforo' ),
81 'vmr' => __( 'Front - Can view member reputation', 'wpforo' ),
82 'vmw' => __( 'Front - Can view member website', 'wpforo' ),
83 'vmsn' => __( 'Front - Can view member social networks', 'wpforo' ),
84 'vmrd' => __( 'Front - Can view member reg. date', 'wpforo' ),
85 'vml' => __( 'Front - Can view member location', 'wpforo' ),
86 'vmo' => __( 'Front - Can view member occupation', 'wpforo' ),
87 'vms' => __( 'Front - Can view member signature', 'wpforo' ),
88 'vmam' => __( 'Front - Can view member about me', 'wpforo' ),
89 'vwpm' => __( 'Front - Can write PM', 'wpforo' ),
90 'caa' => __( 'Front - Can access to attachments', 'wpforo' ),
91 'vt_add_topic' => __( 'Front - Can access to add topic page', 'wpforo' ),
92 ];
93 }
94
95 private function init_options() {
96 $this->default_groupid = $this->get_default_groupid( $this->default->default_groupid );
97 $this->post_flood_intervals = wpforo_get_option( 'wpforo_post_flood_intervals', $this->default->post_flood_intervals );
98 }
99
100 public function init_current() {
101 if( ! $this->current = $this->get_usergroup( WPF()->current_user_groupid ) ) {
102 $this->current = $this->get_usergroup();
103 }
104 }
105
106 private function init_hooks() {
107 // add_action('wpforo_after_add_usergroup', array($this, 'after_add_edit_usergroup'));
108 // add_action('wpforo_after_edit_usergroup', array($this, 'after_add_edit_usergroup'));
109 if( WPF()->is_installed() ) $this->init_options();
110 }
111
112 public function get_flood_interval( $groupid, $obj = 'post' ) {
113 $flood_interval = ( wpfkey( $this->post_flood_intervals, $groupid ) ? $this->post_flood_intervals[ $groupid ] : 3 );
114
115 return apply_filters( 'wpforo_usergroup_get_flood_interval', intval( $flood_interval ), $groupid, $obj );
116 }
117
118 public function fix_group( $group ) {
119 $group = wpforo_array_args_cast_and_merge( (array) $group, $this->default->group );
120 $cans = array_map( '__return_zero', $this->cans );
121 $group['cans'] = maybe_unserialize( $group['cans'] );
122 if( is_array( $group['cans'] ) ) {
123 $group['cans'] = wpforo_array_args_cast_and_merge( $group['cans'], $cans );
124 } else {
125 $group['cans'] = $cans;
126 }
127
128 return $group;
129 }
130
131 function usergroup_list_data() {
132 $ugdata = [];
133 $groups = WPF()->db->get_results( 'SELECT * FROM ' . WPF()->tables->usergroups . ' ORDER BY `name` ', ARRAY_A );
134 foreach( $groups as $group ) {
135 $user_count = WPF()->db->get_var( "SELECT COUNT(*) FROM " . WPF()->tables->profiles . " WHERE `groupid` = " . intval( $group['groupid'] ) . " OR FIND_IN_SET(" . intval( $group['groupid'] ) . ", `secondary_groupids`)" );
136 $ugdata[ $group['groupid'] ]['groupid'] = intval( $group['groupid'] );
137 $ugdata[ $group['groupid'] ]['name'] = wpforo_phrase( $group['name'], false );
138 $ugdata[ $group['groupid'] ]['role'] = $group['role'];
139 $ugdata[ $group['groupid'] ]['count'] = intval( $user_count );
140 $ugdata[ $group['groupid'] ]['access'] = $group['access'];
141 $ugdata[ $group['groupid'] ]['color'] = $group['color'];
142 $ugdata[ $group['groupid'] ]['secondary'] = $group['secondary'];
143 }
144
145 return $ugdata;
146 }
147
148 function add( $title, $cans = [], $description = '', $role = 'subscriber', $access = 'standard', $color = '', $visible = 1, $secondary = 0 ) {
149 $i = 2;
150 $real_title = $title;
151 while( WPF()->db->get_var(
152 WPF()->db->prepare(
153 "SELECT `groupid` FROM `" . WPF()->tables->usergroups . "` WHERE `name` = %s",
154 sanitize_text_field( $title )
155 )
156 ) ) {
157 $title = $real_title . '-' . $i;
158 $i ++;
159 }
160
161 $group = [
162 'name' => sanitize_text_field( $title ),
163 'cans' => serialize( wpforo_parse_args( $cans, array_map( '__return_zero', $this->cans ) ) ),
164 'description' => $description,
165 'utitle' => sanitize_text_field( $real_title ),
166 'role' => $role,
167 'access' => $access,
168 'color' => $color,
169 'visible' => $visible,
170 'secondary' => $secondary,
171 ];
172
173 if( WPF()->db->insert( WPF()->tables->usergroups, $group, [ '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%d' ] ) ) {
174 $group['groupid'] = WPF()->db->insert_id;
175
176 do_action( 'wpforo_after_add_usergroup', $group );
177
178 WPF()->notice->add( 'User group successfully added', 'success' );
179
180 return $group['groupid'];
181 }
182
183 WPF()->notice->add( 'User group add error', 'error' );
184
185 return false;
186 }
187
188 function edit( $groupid, $title, $cans, $description = '', $role = null, $access = null, $color = '', $visible = 1, $secondary = 0 ) {
189 if( ! $this->can( 'vmg' ) ) {
190 WPF()->notice->add( 'Permission denied', 'error' );
191
192 return false;
193 }
194
195 if( $groupid = intval( $groupid ) ) {
196 $old_group = $this->get_usergroup( $groupid );
197 $group = [
198 'name' => sanitize_text_field( $title ),
199 'cans' => serialize( wpforo_parse_args( $cans, array_map( '__return_zero', $this->cans ) ) ),
200 'description' => $description,
201 'utitle' => $old_group['utitle'],
202 'role' => is_null( $role ) ? $old_group['role'] : $role,
203 'access' => is_null( $access ) ? $old_group['access'] : $access,
204 'color' => $color,
205 'visible' => $visible,
206 'secondary' => $secondary,
207 ];
208
209 if( false !== WPF()->db->update( WPF()->tables->usergroups, $group, [ 'groupid' => $groupid ], [ '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%d' ], [ '%d' ] ) ) {
210 $group['groupid'] = $groupid;
211
212 do_action( 'wpforo_after_edit_usergroup', $group );
213
214 WPF()->notice->add( 'User group successfully edited', 'success' );
215
216 return $groupid;
217 }
218 }
219
220 WPF()->notice->add( 'User group edit error', 'error' );
221
222 return false;
223 }
224
225 function delete( $groupid, $mergeid ) {
226 if( ! $this->can( 'vmg' ) ) {
227 WPF()->notice->add( 'Permission denied', 'error' );
228
229 return false;
230 }
231
232 if( ( $groupid = intval( $groupid ) ) && ! in_array( $groupid, [ 1, 4 ] ) ) {
233 if( $mergeid = intval( $mergeid ) ) {
234 $sql = "UPDATE `" . WPF()->tables->profiles . "` SET `groupid` = %d WHERE `groupid` = %d";
235 WPF()->db->query( WPF()->db->prepare( $sql, $mergeid, $groupid ) );
236 }
237
238 if( false !== WPF()->db->delete( WPF()->tables->usergroups, [ 'groupid' => $groupid ], [ '%d' ] ) ) {
239 WPF()->notice->add( wpforo_phrase( 'Usergroup has been successfully deleted. All users of this usergroup have been moved to the usergroup you\'ve chosen', false ), 'success' );
240
241 return $groupid;
242 }
243 }
244
245 WPF()->notice->add( 'Can\'t delete this Usergroup', 'error' );
246
247 return false;
248 }
249
250 public function _get_usergroup( $groupid = 4 ) {
251 return WPF()->db->get_row(
252 WPF()->db->prepare(
253 "SELECT * FROM `" . WPF()->tables->usergroups . "` WHERE `groupid` = %d",
254 $groupid
255 ),
256 ARRAY_A
257 );
258 }
259
260 public function get_usergroup( $groupid = 4 ) {
261 return wpforo_ram_get( [ $this, '_get_usergroup' ], $groupid );
262 }
263
264 public function _get_usergroups( $field = 'full' ) {
265 if( $field === 'full' ) {
266 $groups = (array) WPF()->db->get_results( "SELECT * FROM `" . WPF()->tables->usergroups . "`", ARRAY_A );
267 } else {
268 $groups = WPF()->db->get_col( "SELECT `$field` FROM `" . WPF()->tables->usergroups . "`" );
269 }
270
271 return $groups;
272 }
273
274 public function get_usergroups( $field = 'full' ) {
275 return wpforo_ram_get( [ $this, '_get_usergroups' ], $field );
276 }
277
278 /**
279 * @param array|int $selected
280 * @param array|int $exclude
281 *
282 * @return string
283 */
284 public function get_selectbox( $selected = [], $exclude = [] ) {
285 $selected = array_map( 'intval', (array) $selected );
286 $exclude = array_map( 'intval', (array) $exclude );
287 $html = '';
288 foreach( $this->usergroup_list_data() as $group ) {
289 if( in_array( $group['groupid'], $exclude ) ) continue;
290 $html .= sprintf(
291 '<option value="%1$s" %2$s>%3$s</option>',
292 intval( $group['groupid'] ),
293 in_array( $group['groupid'], $selected ) ? ' selected ' : '',
294 esc_html( $group['name'] ) . "\t(" . $group['count'] . ")"
295 );
296 }
297
298 return $html;
299 }
300
301 /**
302 * @param array|int $selected
303 * @param array|int $exclude
304 */
305 public function show_selectbox( $selected = [], $exclude = [] ) {
306 echo $this->get_selectbox( $selected, $exclude );
307 }
308
309 function get_visible_usergroup_ids() {
310 $key = [ 'usergroup', 'get_visible_usergroup_ids' ];
311 if( WPF()->ram_cache->exists( $key ) ) return WPF()->ram_cache->get( $key );
312 $col = WPF()->db->get_col( "SELECT `groupid` FROM `" . WPF()->tables->usergroups . "` WHERE `visible` = 1" );
313 WPF()->ram_cache->set( $key, $col );
314
315 return $col;
316 }
317
318 public function _get_secondary_groupids() {
319 return WPF()->db->get_col( "SELECT `groupid` FROM `" . WPF()->tables->usergroups . "` WHERE `groupid` NOT IN(1,2,4) AND `secondary` = 1" );
320 }
321
322 public function get_secondary_groupids() {
323 return wpforo_ram_get( [$this, '_get_secondary_groupids'] );
324 }
325
326 function get_secondary_group_names( $ids ) {
327 if( ! is_array( $ids ) ) $ids = explode( ',', $ids );
328 $ids = array_map( 'intval', $ids );
329 $ids = array_diff( $ids, [ 1, 2, 4 ] );
330 if( $ids ) {
331 $ids = implode( ',', $ids );
332
333 return WPF()->db->get_col( "SELECT `name` FROM `" . WPF()->tables->usergroups . "` WHERE `secondary` = 1 AND `groupid` IN (" . esc_sql( $ids ) . ")" );
334 }
335
336 return [];
337 }
338
339 /**
340 * @deprecated since 2.1.6, instead of this method you can use $this->get_secondary_groups()
341 */
342 function get_secondary_usergroups() {
343 return $this->get_secondary_groups();
344 }
345
346 function get_secondary_groups() {
347 return wpforo_ram_get( [ $this, '_get_secondary_groups' ] );
348 }
349
350 function _get_secondary_groups() {
351 return (array) WPF()->db->get_results( "SELECT * FROM `" . WPF()->tables->usergroups . "` WHERE `groupid` NOT IN(1,2,4) AND `secondary` = 1", ARRAY_A );
352 }
353
354 function get_groupids_by_role( $role ) {
355 if( $role ) {
356 $ugids = WPF()->db->get_col( "SELECT `groupid` FROM `" . WPF()->tables->usergroups . "` WHERE `role` = '" . esc_sql( $role ) . "' ORDER BY `groupid` ASC" );
357 if( ! empty( $ugids ) ) {
358 return $ugids;
359 }
360 }
361
362 return null;
363 }
364
365 function get_group_by_role( $role ) {
366 if( $role ) {
367 $usergroups = WPF()->db->get_results( "SELECT * FROM `" . WPF()->tables->usergroups . "` WHERE `role` = '" . esc_sql( $role ) . "' ORDER BY `groupid` ASC", ARRAY_A );
368 if( ! empty( $usergroups ) ) {
369 return $usergroups;
370 }
371 }
372
373 return null;
374 }
375
376 function get_roles() {
377 $roles = wp_roles();
378 $roles = $roles->get_names();
379
380 return $roles;
381 }
382
383 function get_roles_ug() {
384 $roles_ug = WPF()->db->get_results( "SELECT `name`, `role` FROM `" . WPF()->tables->usergroups . "`", ARRAY_A );
385 $roles = wp_roles();
386 $roles = $roles->get_names();
387 if( ! empty( $roles ) ) {
388 foreach( $roles as $role => $name ) {
389 foreach( $roles_ug as $ug ) {
390 if( wpfval( $ug, 'role' ) && $role == $ug['role'] ) {
391 $roles_ug[ $role ][] = $ug['name'];
392 }
393 }
394 }
395 }
396
397 return $roles_ug;
398 }
399
400 function get_roles_woug() {
401 $roles_woug = [];
402 $roles_ug = WPF()->db->get_col( "SELECT `role` FROM `" . WPF()->tables->usergroups . "` GROUP BY `role`" );
403 $roles = wp_roles();
404 $roles = $roles->get_names();
405 if( ! empty( $roles ) ) {
406 foreach( $roles as $role => $name ) {
407 if( ! in_array( $role, $roles_ug ) ) {
408 $roles_woug[ $role ] = $name;
409 }
410 }
411 }
412
413 return $roles_woug;
414 }
415
416 function get_role_usergroup_relation() {
417 $roles = [];
418 $data = WPF()->db->get_results( "SELECT `groupid`, `role` FROM `" . WPF()->tables->usergroups . "` ORDER BY `groupid` DESC", ARRAY_A );
419 if( ! empty( $data ) ) {
420 $data = array_map( function($d){ $d['groupid'] = intval( $d['groupid'] ); return $d; }, $data );
421 foreach( $data as $rel ) {
422 if( $rel['groupid'] === 1 && in_array( $rel['role'], [ 'subscriber', 'contributor' ], true ) ) {
423 $roles['administrator'] = $rel['groupid'];
424 } elseif( $rel['groupid'] === 2 && $rel['role'] === 'subscriber' ) {
425 $roles['editor'] = $rel['groupid'];
426 } elseif( $rel['role'] ) {
427 $roles[ $rel['role'] ] = $rel['groupid'];
428 }
429 }
430 }
431
432 return $roles;
433 }
434
435 function get_usergroup_role_relation() {
436 $usergroups = [];
437 $data = WPF()->db->get_results( "SELECT `groupid`, `role` FROM `" . WPF()->tables->usergroups . "`", ARRAY_A );
438 if( ! empty( $data ) ) {
439 foreach( $data as $rel ) {
440 $usergroups[ $rel['groupid'] ] = $rel['role'];
441 }
442 }
443
444 return $usergroups;
445 }
446
447 function get_usergroup_access_relation() {
448 $usergroups = [];
449 $data = WPF()->db->get_results( "SELECT `groupid`, `access` FROM `" . WPF()->tables->usergroups . "`", ARRAY_A );
450 if( ! empty( $data ) ) {
451 foreach( $data as $rel ) {
452 $usergroups[ (int) $rel['groupid'] ] = $rel['access'];
453 }
454 }
455
456 return $usergroups;
457 }
458
459 function set_ug_roles( $ug_role ) {
460 if( ! empty( $ug_role ) ) {
461 foreach( $ug_role as $usergroupid => $role ) {
462 $role = sanitize_text_field( $role );
463 WPF()->db->query( "UPDATE " . WPF()->tables->usergroups . " SET `role` = '" . esc_sql( $role ) . "' WHERE `groupid` = " . intval( $usergroupid ) );
464 }
465 }
466 }
467
468 function set_users_groupid( $groupid_userids ) {
469 $status = [ 'error' => 0, 'success' => false ];
470 if( ! empty( $groupid_userids ) ) {
471 foreach( $groupid_userids as $group_id => $user_ids ) {
472 if( $group_id && ! empty( $user_ids ) ) {
473 $userids = implode( ',', $user_ids );
474 $sql = "UPDATE " . WPF()->tables->profiles . " SET `groupid` = " . intval( $group_id ) . " WHERE `userid` IN(" . esc_sql( $userids ) . ")";
475 if( false === WPF()->db->query( $sql ) ) {
476 $status['error'] = WPF()->db->last_error;
477 $status['success'] = false;
478 break;
479 } else {
480 $status['success'] = true;
481 }
482 }
483 }
484 }
485 do_action( 'wpforo_set_users_groupid', $groupid_userids, $status );
486
487 return $status;
488 }
489
490 function build_users_groupid_array( $usergroupid_role, $users ) {
491 $array = [];
492 $group_users = [];
493 $user_prime_group = [];
494 $user_second_groups = [];
495 if( ! empty( $users ) ) {
496 foreach( $users as $user ) {
497 if( ! empty( $user->roles ) ) {
498 foreach( $user->roles as $role ) {
499 //$ugids = wpforo_key( $usergroupid_role, $role, 'sort' );
500 $ugids = [];
501 if( !empty( $usergroupid_role ) ){
502 foreach ( $usergroupid_role as $_role => $_groupid ){
503 if( $_role === $role ){
504 $ugids[] = $_groupid;
505 }
506 }
507 }
508 sort( $ugids );
509
510 $ug_count = count( $ugids );
511 if( ! empty( $ugids ) ) {
512 foreach( $ugids as $ugid ) {
513 // The count of $ug_count === 1 means the user role is synced,
514 // it has one unique usergroup.
515 if( $ug_count === 1 ) {
516 if( ! isset( $user_prime_group[ $user->ID ] ) ) {
517 $user_prime_group[ $user->ID ][] = $ugid;
518 $group_users[ $ugid ][] = intval( $user->ID );
519 } else {
520 $user_second_groups[ $user->ID ][] = $ugid;
521 }
522 }
523 }
524 }
525 }
526 }
527 }
528 }
529 $array['group_users'] = $group_users;
530 $array['user_prime_group'] = $user_prime_group;
531 $array['user_second_groups'] = $user_second_groups;
532
533 return $array;
534 }
535
536 public function after_add_edit_usergroup( $group ) {
537 if( wpforo_setting( 'authorization', 'role_synch' ) ) {
538 $limit = apply_filters( 'wpforo_synch_roles_users_limit', 5000 );
539 $users = get_users( [ 'role' => $group['role'], 'number' => $limit ] );
540 if( ! empty( $users ) ) {
541 if( count( $users ) <= $limit ) {
542 $status = wpforo_synch_role( [ $group['groupid'] => $group['role'] ], $users );
543 wpforo_clean_cache( 'user' );
544 if( $error = wpfval( $status, 'error' ) ) {
545 WPF()->notice->add( $error, 'error' );
546 }
547 } else {
548 WPF()->notice->add( 'Please make sure you don\'t have not-synched Roles in the "User Roles" table below, then click on the [Synchronize] button to update users Usergroup IDs.', 'error' );
549 }
550 }
551 }
552 }
553
554 public function can( $do, $groupids = null ) {
555 if( is_null( $groupids ) ) {
556 if( current_user_can( 'administrator' ) ) return 1;
557 $groupids = WPF()->current_user_groupids;
558 }
559
560 if( $groupids = array_map( 'intval', (array) $groupids ) ) {
561 foreach( $groupids as $groupid ) {
562 if( $groupid ) {
563 $group = $this->get_usergroup( $groupid );
564 $group_cans = unserialize( $group['cans'] );
565 if( (int) wpfval( $group_cans, $do ) ) return 1;
566 }
567 }
568 }
569
570 return 0;
571 }
572
573 public function get_groupids_by_can( $do ) {
574 $usergroupids = [];
575 $usergroups = $this->get_usergroups();
576 foreach( $usergroups as $usergroup ) {
577 $cans = unserialize( $usergroup['cans'] );
578 if( isset( $cans[ $do ] ) && $cans[ $do ] ) {
579 $usergroupids[] = $usergroup['groupid'];
580 }
581 }
582
583 return $usergroupids;
584 }
585
586 public function can_manage_forum( $groupids = null ) {
587 return ( $this->can( 'cf', $groupids ) && $this->can( 'ef', $groupids ) && $this->can( 'df', $groupids ) ) || $this->can( 'mf', $groupids );
588 }
589
590 public function set_default( $groupid ) {
591 if( in_array( intval($groupid), [1,4], true ) ) return false;
592 if( WPF()->db->update(
593 WPF()->tables->usergroups,
594 ['is_default' => 1],
595 ['groupid' => $groupid],
596 ['%d'],
597 ['%d']
598 )){
599 return false !== WPF()->db->query( WPF()->db->prepare(
600 "UPDATE `" . WPF()->tables->usergroups . "` SET `is_default` = 0 WHERE `groupid` <> %d",
601 $groupid
602 ));
603 }
604
605 return false;
606 }
607
608 public function get_default_groupid( $default_groupid ){
609 $groupid = (int) WPF()->db->get_var(
610 "SELECT `groupid` FROM `" . WPF()->tables->usergroups . "` WHERE `is_default` = 1 ORDER BY `groupid` DESC"
611 );
612 if( !$groupid ) $groupid = $default_groupid;
613
614 return $groupid;
615 }
616 }
617