Commit b617006b authored by John James Jacoby's avatar John James Jacoby
Browse files

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.
parent a6a3975d
......@@ -2,8 +2,8 @@
Contributors: johnjamesjacoby, stuttter
Tags: taxonomy, term, user, group, type
Requires at least: 4.7
Tested up to: 4.8
Stable tag: 1.1.0
Tested up to: 4.9
Stable tag: 2.0.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
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/
== Changelog ==
= [2.0.0] - 2017/10/24 =
* Fix bug with user filtering
* Fix bug with setting user terms
* Add `exclusive` group argument to use radios instead of checkboxes
= [1.1.0] - 2017/03/28 =
* Change default taxonomy to `user-group` in wp_get_users_of_group()
......
......@@ -8,7 +8,7 @@
* License: GPLv2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Description: Group users together with taxonomies & terms.
* Version: 1.1.0
* Version: 2.0.0
* Text Domain: wp-user-groups
* Domain Path: /wp-user-groups/assets/languages/
*/
......@@ -38,7 +38,7 @@ function _wp_user_groups() {
add_action( 'plugins_loaded', '_wp_user_groups' );
/**
* Return the plugin's URL
* Return the plugin URL
*
* @since 0.1.4
*
......@@ -56,5 +56,5 @@ function wp_user_groups_get_plugin_url() {
* @return int
*/
function wp_user_groups_get_asset_version() {
return 201703280001;
return 201710240001;
}
......@@ -463,8 +463,10 @@ class WP_User_Taxonomy {
<thead>
<tr>
<td id="cb" class="manage-column column-cb check-column">
<label class="screen-reader-text" for="cb-select-all-1"><?php esc_html_e( 'Select All', 'wp-user-groups' ); ?></label>
<input id="cb-select-all-1" type="checkbox">
<?php if ( ! $this->is_exclusive() ) : ?>
<label class="screen-reader-text" for="cb-select-all-1"><?php esc_html_e( 'Select All', 'wp-user-groups' ); ?></label>
<input id="cb-select-all-1" type="checkbox">
<?php endif; ?>
</td>
<th scope="col" class="manage-column column-name column-primary"><?php esc_html_e( 'Name', 'wp-user-groups' ); ?></th>
<th scope="col" class="manage-column column-description"><?php esc_html_e( 'Description', 'wp-user-groups' ); ?></th>
......@@ -480,7 +482,7 @@ class WP_User_Taxonomy {
<tr class="<?php echo ( true === $active ) ? 'active' : 'inactive'; ?>">
<th scope="row" class="check-column">
<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 ); ?> />
<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 ); ?> />
<label for="<?php echo esc_attr( $this->taxonomy ); ?>-<?php echo esc_attr( $term->slug ); ?>"></label>
</th>
<td class="column-primary">
......@@ -514,8 +516,10 @@ class WP_User_Taxonomy {
<tfoot>
<tr>
<td class="manage-column column-cb check-column">
<label class="screen-reader-text" for="cb-select-all-2"><?php esc_html_e( 'Select All', 'wp-user-groups' ); ?></label>
<input id="cb-select-all-2" type="checkbox">
<?php if ( ! $this->is_exclusive() ) : ?>
<label class="screen-reader-text" for="cb-select-all-2"><?php esc_html_e( 'Select All', 'wp-user-groups' ); ?></label>
<input id="cb-select-all-2" type="checkbox">
<?php endif; ?>
</td>
<th scope="col" class="manage-column column-name column-primary"><?php esc_html_e( 'Name', 'wp-user-groups' ); ?></th>
<th scope="col" class="manage-column column-description"><?php esc_html_e( 'Description', 'wp-user-groups' ); ?></th>
......@@ -644,7 +648,12 @@ class WP_User_Taxonomy {
*/
protected function parse_options() {
return wp_parse_args( $this->args, array(
'user_group' => true, // Custom
// Custom
'user_group' => true, // Make it easy to identify user groups
'exclusive' => false, // Check vs. Radio
// Core
'hierarchical' => true,
'public' => false,
'show_ui' => true,
......@@ -732,6 +741,18 @@ class WP_User_Taxonomy {
return $new;
}
/**
* Is this an exclusive user group type, where a user can only belong to one
* group within the taxonomy?
*
* @since 2.0.0
*
* @return bool
*/
public function is_exclusive() {
return ( true === $this->args['exclusive'] );
}
/**
* Handle bulk editing of users
*
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment