Skip to content

Commit b617006

Browse files
committed
First pass at exclusive type groups.
This change introduces a new taxonomy option called `exclusive` that uses radio buttons instead of checkboxes, making a user's entry into a specific group exclusive (joining one will remove them from others.) Might be more to do here, but this was pretty easy otherwise. Fixes #11.
1 parent a6a3975 commit b617006

File tree

3 files changed

+37
-11
lines changed

3 files changed

+37
-11
lines changed

readme.txt

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
Contributors: johnjamesjacoby, stuttter
33
Tags: taxonomy, term, user, group, type
44
Requires at least: 4.7
5-
Tested up to: 4.8
6-
Stable tag: 1.1.0
5+
Tested up to: 4.9
6+
Stable tag: 2.0.0
77
License: GPLv2 or later
88
License URI: https://www.gnu.org/licenses/gpl-2.0.html
99
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=9Q4F4EL5YJ62J
@@ -77,6 +77,11 @@ http://github.com/stuttter/wp-user-groups/
7777

7878
== Changelog ==
7979

80+
= [2.0.0] - 2017/10/24 =
81+
* Fix bug with user filtering
82+
* Fix bug with setting user terms
83+
* Add `exclusive` group argument to use radios instead of checkboxes
84+
8085
= [1.1.0] - 2017/03/28 =
8186
* Change default taxonomy to `user-group` in wp_get_users_of_group()
8287

wp-user-groups.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* License: GPLv2 or later
99
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
1010
* Description: Group users together with taxonomies & terms.
11-
* Version: 1.1.0
11+
* Version: 2.0.0
1212
* Text Domain: wp-user-groups
1313
* Domain Path: /wp-user-groups/assets/languages/
1414
*/
@@ -38,7 +38,7 @@ function _wp_user_groups() {
3838
add_action( 'plugins_loaded', '_wp_user_groups' );
3939

4040
/**
41-
* Return the plugin's URL
41+
* Return the plugin URL
4242
*
4343
* @since 0.1.4
4444
*
@@ -56,5 +56,5 @@ function wp_user_groups_get_plugin_url() {
5656
* @return int
5757
*/
5858
function wp_user_groups_get_asset_version() {
59-
return 201703280001;
59+
return 201710240001;
6060
}

wp-user-groups/includes/classes/class-user-taxonomy.php

+27-6
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,10 @@ protected function table_contents( $user, $tax, $terms ) {
463463
<thead>
464464
<tr>
465465
<td id="cb" class="manage-column column-cb check-column">
466-
<label class="screen-reader-text" for="cb-select-all-1"><?php esc_html_e( 'Select All', 'wp-user-groups' ); ?></label>
467-
<input id="cb-select-all-1" type="checkbox">
466+
<?php if ( ! $this->is_exclusive() ) : ?>
467+
<label class="screen-reader-text" for="cb-select-all-1"><?php esc_html_e( 'Select All', 'wp-user-groups' ); ?></label>
468+
<input id="cb-select-all-1" type="checkbox">
469+
<?php endif; ?>
468470
</td>
469471
<th scope="col" class="manage-column column-name column-primary"><?php esc_html_e( 'Name', 'wp-user-groups' ); ?></th>
470472
<th scope="col" class="manage-column column-description"><?php esc_html_e( 'Description', 'wp-user-groups' ); ?></th>
@@ -480,7 +482,7 @@ protected function table_contents( $user, $tax, $terms ) {
480482

481483
<tr class="<?php echo ( true === $active ) ? 'active' : 'inactive'; ?>">
482484
<th scope="row" class="check-column">
483-
<input type="checkbox" name="<?php echo esc_attr( $this->taxonomy ); ?>[]" id="<?php echo esc_attr( $this->taxonomy ); ?>-<?php echo esc_attr( $term->slug ); ?>" value="<?php echo esc_attr( $term->slug ); ?>" <?php checked( $active ); ?> />
485+
<input type="<?php echo $this->is_exclusive() ? 'radio' : 'checkbox'; ?>" name="<?php echo esc_attr( $this->taxonomy ); ?>[]" id="<?php echo esc_attr( $this->taxonomy ); ?>-<?php echo esc_attr( $term->slug ); ?>" value="<?php echo esc_attr( $term->slug ); ?>" <?php checked( $active ); ?> />
484486
<label for="<?php echo esc_attr( $this->taxonomy ); ?>-<?php echo esc_attr( $term->slug ); ?>"></label>
485487
</th>
486488
<td class="column-primary">
@@ -514,8 +516,10 @@ protected function table_contents( $user, $tax, $terms ) {
514516
<tfoot>
515517
<tr>
516518
<td class="manage-column column-cb check-column">
517-
<label class="screen-reader-text" for="cb-select-all-2"><?php esc_html_e( 'Select All', 'wp-user-groups' ); ?></label>
518-
<input id="cb-select-all-2" type="checkbox">
519+
<?php if ( ! $this->is_exclusive() ) : ?>
520+
<label class="screen-reader-text" for="cb-select-all-2"><?php esc_html_e( 'Select All', 'wp-user-groups' ); ?></label>
521+
<input id="cb-select-all-2" type="checkbox">
522+
<?php endif; ?>
519523
</td>
520524
<th scope="col" class="manage-column column-name column-primary"><?php esc_html_e( 'Name', 'wp-user-groups' ); ?></th>
521525
<th scope="col" class="manage-column column-description"><?php esc_html_e( 'Description', 'wp-user-groups' ); ?></th>
@@ -644,7 +648,12 @@ protected function parse_labels() {
644648
*/
645649
protected function parse_options() {
646650
return wp_parse_args( $this->args, array(
647-
'user_group' => true, // Custom
651+
652+
// Custom
653+
'user_group' => true, // Make it easy to identify user groups
654+
'exclusive' => false, // Check vs. Radio
655+
656+
// Core
648657
'hierarchical' => true,
649658
'public' => false,
650659
'show_ui' => true,
@@ -732,6 +741,18 @@ public function bulk_actions_sort( $actions = array() ) {
732741
return $new;
733742
}
734743

744+
/**
745+
* Is this an exclusive user group type, where a user can only belong to one
746+
* group within the taxonomy?
747+
*
748+
* @since 2.0.0
749+
*
750+
* @return bool
751+
*/
752+
public function is_exclusive() {
753+
return ( true === $this->args['exclusive'] );
754+
}
755+
735756
/**
736757
* Handle bulk editing of users
737758
*

0 commit comments

Comments
 (0)