Groups - Version 1.3.1

Version Description

  • Added users property to Groups_Group
  • Moved tests out of core folder
  • Fixed missing $wpdb in Groups_Group's getter
  • Added group filters on users admin section
Download this release

Release Info

Developer itthinx
Plugin Icon 128x128 Groups
Version 1.3.1
Comparing to
See all releases

Code changes from version 1.3.0 to 1.3.1

groups.php CHANGED
@@ -21,13 +21,13 @@
21
  * Plugin Name: Groups
22
  * Plugin URI: http://www.itthinx.com/plugins/groups
23
  * Description: Groups provides group-based user membership management, group-based capabilities and content access control.
24
- * Version: 1.3.0
25
  * Author: itthinx
26
  * Author URI: http://www.itthinx.com
27
  * Donate-Link: http://www.itthinx.com
28
  * License: GPLv3
29
  */
30
- define( 'GROUPS_CORE_VERSION', '1.3.0' );
31
  define( 'GROUPS_FILE', __FILE__ );
32
  if ( !defined( 'GROUPS_CORE_DIR' ) ) {
33
  define( 'GROUPS_CORE_DIR', WP_PLUGIN_DIR . '/groups' );
21
  * Plugin Name: Groups
22
  * Plugin URI: http://www.itthinx.com/plugins/groups
23
  * Description: Groups provides group-based user membership management, group-based capabilities and content access control.
24
+ * Version: 1.3.1
25
  * Author: itthinx
26
  * Author URI: http://www.itthinx.com
27
  * Donate-Link: http://www.itthinx.com
28
  * License: GPLv3
29
  */
30
+ define( 'GROUPS_CORE_VERSION', '1.3.1' );
31
  define( 'GROUPS_FILE', __FILE__ );
32
  if ( !defined( 'GROUPS_CORE_DIR' ) ) {
33
  define( 'GROUPS_CORE_DIR', WP_PLUGIN_DIR . '/groups' );
images/groups-grey-8x8.png ADDED
Binary file
lib/admin/class-groups-admin-users.php CHANGED
@@ -50,10 +50,44 @@ class Groups_Admin_Users {
50
  add_action( 'admin_head', array( __CLASS__, 'admin_head' ) );
51
  // allow to add or remove selected users to groups
52
  add_action( 'load-users.php', array( __CLASS__, 'load_users' ) );
 
 
 
 
53
  }
54
  }
55
  }
56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  /**
58
  * Adds the group add/remove buttons after the last action box.
59
  */
@@ -99,7 +133,37 @@ class Groups_Admin_Users {
99
  ';
100
  echo '</script>';
101
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  }
 
103
  }
104
 
105
  /**
50
  add_action( 'admin_head', array( __CLASS__, 'admin_head' ) );
51
  // allow to add or remove selected users to groups
52
  add_action( 'load-users.php', array( __CLASS__, 'load_users' ) );
53
+ // add links to filter users by group
54
+ add_filter( 'views_users', array( __CLASS__, 'views_users' ) );
55
+ // modify query to filter users by group
56
+ add_filter( 'pre_user_query', array( __CLASS__, 'pre_user_query' ) );
57
  }
58
  }
59
  }
60
 
61
+ /**
62
+ * Modify query to filter users by group.
63
+ *
64
+ * @param WP_User_Query $user_query
65
+ * @return WP_User_Query
66
+ */
67
+ public static function pre_user_query( $user_query ) {
68
+ global $pagenow, $wpdb;
69
+ if ( ( $pagenow == 'users.php' ) && empty( $_GET['page'] ) ) {
70
+ if ( isset( $_REQUEST['group'] ) ) {
71
+ $group_id = $_REQUEST['group'];
72
+ if ( Groups_Group::read( $group_id ) ) {
73
+ $group = new Groups_Group( $group_id );
74
+ $users = $group->users;
75
+ $include = array();
76
+ if ( count( $users ) > 0 ) {
77
+ foreach( $users as $user ) {
78
+ $include[] = $user->user->ID;
79
+ }
80
+ } else { // no results
81
+ $include[] = 0;
82
+ }
83
+ $ids = implode( ',', wp_parse_id_list( $include ) );
84
+ $user_query->query_where .= " AND $wpdb->users.ID IN ($ids)";
85
+ }
86
+ }
87
+ }
88
+ return $user_query;
89
+ }
90
+
91
  /**
92
  * Adds the group add/remove buttons after the last action box.
93
  */
133
  ';
134
  echo '</script>';
135
 
136
+ // .subsubsub rule added because with views_users() the list can get long
137
+ // icon distinguishes from role links
138
+ echo '<style type="text/css">';
139
+ echo '.subsubsub { white-space: normal; }';
140
+ echo 'a.group { background: url(' . GROUPS_PLUGIN_URL . '/images/groups-grey-8x8.png) transparent no-repeat left center; padding-left: 10px;}';
141
+ echo '</style>';
142
+ }
143
+ }
144
+
145
+ /**
146
+ * Hooked on filter in class-wp-list-table.php to add links that
147
+ * filter by group.
148
+ * @param array $views
149
+ */
150
+ public static function views_users( $views ) {
151
+ global $pagenow, $wpdb;
152
+ if ( ( $pagenow == 'users.php' ) && empty( $_GET['page'] ) ) {
153
+ $group_table = _groups_get_tablename( "group" );
154
+ $groups = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $group_table ORDER BY name" ) );
155
+ foreach( $groups as $group ) {
156
+ $group = new Groups_Group( $group->group_id );
157
+ $user_count = count( $group->users );
158
+ $views[] = sprintf(
159
+ '<a class="group" href="%s" title="%s">%s</a>',
160
+ esc_url( add_query_arg( 'group', $group->group_id, admin_url( 'users.php' ) ) ),
161
+ sprintf( '%s Group', wp_filter_nohtml_kses( $group->name ) ),
162
+ sprintf( '%s <span class="count">(%s)</span>', wp_filter_nohtml_kses( $group->name ), $user_count )
163
+ );
164
+ }
165
  }
166
+ return $views;
167
  }
168
 
169
  /**
lib/core/class-groups-group.php CHANGED
@@ -49,11 +49,14 @@ class Groups_Group implements I_Capable {
49
  * - datetime
50
  * - name
51
  * - description
 
 
52
  *
53
  * @param string $name property's name
54
  * @return property value, will return null if property does not exist
55
  */
56
  public function __get( $name ) {
 
57
  $result = null;
58
  if ( $this->group !== null ) {
59
  switch( $name ) {
@@ -78,7 +81,20 @@ class Groups_Group implements I_Capable {
78
  }
79
  }
80
  break;
81
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  }
83
  return $result;
84
  }
49
  * - datetime
50
  * - name
51
  * - description
52
+ * - capabilities, returns an array of Groups_Capability
53
+ * - users, returns an array of Groups_User
54
  *
55
  * @param string $name property's name
56
  * @return property value, will return null if property does not exist
57
  */
58
  public function __get( $name ) {
59
+ global $wpdb;
60
  $result = null;
61
  if ( $this->group !== null ) {
62
  switch( $name ) {
81
  }
82
  }
83
  break;
84
+ case 'users' :
85
+ $user_group_table = _groups_get_tablename( "user_group" );
86
+ $users = $wpdb->get_results( $wpdb->prepare(
87
+ "SELECT ID FROM $wpdb->users LEFT JOIN $user_group_table ON $wpdb->users.ID = $user_group_table.user_id WHERE $user_group_table.group_id = %d",
88
+ Groups_Utility::id( $this->group->group_id )
89
+ ) );
90
+ if ( $users ) {
91
+ $result = array();
92
+ foreach( $users as $user ) {
93
+ $result[] = new Groups_User( $user->ID );
94
+ }
95
+ }
96
+ break;
97
+ }
98
  }
99
  return $result;
100
  }
lib/{core → test}/groups-tests.php RENAMED
@@ -169,6 +169,9 @@ if ( defined( 'ABSPATH' ) ) {
169
  $sour_group = new Groups_Group( $sour_group_id );
170
  $lemon_group = new Groups_Group( $lemon_group_id );
171
 
 
 
 
172
  // all should be able to "dance" : check by capability label ...
173
  assert( '$fruits_group->can( "dance" )' );
174
  assert( '$sweet_group->can( "dance" )' );
169
  $sour_group = new Groups_Group( $sour_group_id );
170
  $lemon_group = new Groups_Group( $lemon_group_id );
171
 
172
+ // retrieve users
173
+ assert( 'count( $fruits_group->users ) > 0' );
174
+
175
  // all should be able to "dance" : check by capability label ...
176
  assert( '$fruits_group->can( "dance" )' );
177
  assert( '$sweet_group->can( "dance" )' );
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === Groups ===
2
  Contributors: itthinx
3
  Donate link: http://www.itthinx.com/plugins/groups
4
- Tags: access, access control, capability, capabilities, content, download, downloads, file, file access, files, group, groups, member, members, membership, permission, permissions
5
  Requires at least: 3.3
6
  Tested up to: 3.4.2
7
- Stable tag: 1.3.0
8
  License: GPLv3
9
 
10
  Groups provides group-based user membership management, group-based capabilities and content access control.
@@ -17,7 +17,9 @@ It integrates standard WordPress capabilities and application-specific capabilit
17
  ### Extensions ###
18
 
19
  - [Groups File Access](http://www.itthinx.com/plugins/groups-file-access/) Groups File Access is an extension that allows to provide file download links for authorized users. Access to files is restricted to users by their group membership.
20
- - [Groups WooCommerce](http://www.woothemes.com/extension/groups-woocommerce/) Groups for WooCommerce is a WordPress plugin that allows you to sell memberships
 
 
21
 
22
  ### Features ###
23
 
@@ -319,6 +321,12 @@ See also [Groups](http://www.itthinx.com/plugins/groups/)
319
 
320
  == Changelog ==
321
 
 
 
 
 
 
 
322
  = 1.3.0 =
323
  * Added feature that allows to show access restrictions depending on post type
324
  * Added support for access restrictions on Media
@@ -399,6 +407,9 @@ Some installations wouldn't work correctly, showing no capabilities and making i
399
 
400
  == Upgrade Notice ==
401
 
 
 
 
402
  = 1.3.0 =
403
  * New access restriction features and fixes, adds support for access restrictions depending on post type and for Media
404
 
1
  === Groups ===
2
  Contributors: itthinx
3
  Donate link: http://www.itthinx.com/plugins/groups
4
+ Tags: access, access control, capability, capabilities, content, download, downloads, file, file access, files, group, groups, member, members, membership, memberships, paypal, permission, permissions, subscription, subscriptions, woocommerce
5
  Requires at least: 3.3
6
  Tested up to: 3.4.2
7
+ Stable tag: 1.3.1
8
  License: GPLv3
9
 
10
  Groups provides group-based user membership management, group-based capabilities and content access control.
17
  ### Extensions ###
18
 
19
  - [Groups File Access](http://www.itthinx.com/plugins/groups-file-access/) Groups File Access is an extension that allows to provide file download links for authorized users. Access to files is restricted to users by their group membership.
20
+ - [Groups Notifications](http://www.itthinx.com/plugins/groups-notifications/) Adds customizable notifications for events related to Groups.
21
+ - [Groups PayPal](http://www.itthinx.com/plugins/groups-paypal/) Groups for PayPal allows to sell memberships and subscriptions with Groups.
22
+ - [Groups WooCommerce](http://www.woothemes.com/extension/groups-woocommerce/) Groups for WooCommerce is a WordPress plugin that allows you to sell memberships.
23
 
24
  ### Features ###
25
 
321
 
322
  == Changelog ==
323
 
324
+ = 1.3.1 =
325
+ * Added users property to Groups_Group
326
+ * Moved tests out of core folder
327
+ * Fixed missing $wpdb in Groups_Group's getter
328
+ * Added group filters on users admin section
329
+
330
  = 1.3.0 =
331
  * Added feature that allows to show access restrictions depending on post type
332
  * Added support for access restrictions on Media
407
 
408
  == Upgrade Notice ==
409
 
410
+ = 1.3.1 =
411
+ * Now you can filter the users section by group. This release also brings API enhancements and fixes.
412
+
413
  = 1.3.0 =
414
  * New access restriction features and fixes, adds support for access restrictions depending on post type and for Media
415