Groups - Version 1.4.8

Version Description

  • Fixed: A closing tag in the group list on the user profile.
  • Fixed: Help wording.
  • Improved: Capabilities in the Access Restrictions column are sorted for more consistent display.
  • Improved: Reduced ID, Edit and Remove column widths on Groups and Capabilities screens.
  • Fixed: Stripping added slashes from groups and capabilities displayed.
  • Added: Feedback when groups and capabilities are created, updated or removed in admin.
  • Added: group and exclude_group attributes for the [groups_user_groups] shortcode.
  • Improved: Replaced remnant CR LF line-endings in code.
  • Fixed: Handling updates to a capability when the capability field is empty.
  • Fixed: Handling updates to a group when the name field is empty.
  • Fixed: Don't allow to use the name of another existing group when updating a group.
  • Fixed: Don't allow to use the name of another existing capability when updating one.
Download this release

Release Info

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

Code changes from version 1.4.7 to 1.4.8

css/groups_admin.css CHANGED
@@ -116,6 +116,15 @@ div.capability.edit label {
116
  width: 250px;
117
  }
118
 
 
 
 
 
 
 
 
 
 
119
  .manage-groups .required,
120
  .manage-capabilities .required {
121
  background: url(../images/required.png) transparent no-repeat left center;
@@ -219,3 +228,7 @@ div.groups-footer form {
219
  line-height: 18px;
220
  padding: 2px;
221
  }
 
 
 
 
116
  width: 250px;
117
  }
118
 
119
+ .groups-overview th.edit,
120
+ .groups-overview th.group_id,
121
+ .groups-overview th.remove,
122
+ .capabilities-overview th.capability_id,
123
+ .capabilities-overview th.edit,
124
+ .capabilities-overview th.remove {
125
+ width:10%;
126
+ }
127
+
128
  .manage-groups .required,
129
  .manage-capabilities .required {
130
  background: url(../images/required.png) transparent no-repeat left center;
228
  line-height: 18px;
229
  padding: 2px;
230
  }
231
+
232
+ .groups.messages {
233
+ padding: 1em 0;
234
+ }
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.4.7
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.4.7' );
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.4.8
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.4.8' );
31
  define( 'GROUPS_FILE', __FILE__ );
32
  if ( !defined( 'GROUPS_CORE_DIR' ) ) {
33
  define( 'GROUPS_CORE_DIR', WP_PLUGIN_DIR . '/groups' );
lib/access/class-groups-access-meta-boxes.php CHANGED
@@ -106,7 +106,7 @@ class Groups_Access_Meta_Boxes {
106
  __( 'Use the <em>Access restrictions</em> box to limit the visibility of posts, pages and other post types.', GROUPS_PLUGIN_DOMAIN ) .
107
  '</p>' .
108
  '<p>' .
109
- __( 'You can select one or more capabilities that enabled for access restriction.', GROUPS_PLUGIN_DOMAIN ) .
110
  ' ' .
111
  __( 'Note that you must be a member of a group that has such a capability assigned.', GROUPS_PLUGIN_DOMAIN ) .
112
  '</p>' .
106
  __( 'Use the <em>Access restrictions</em> box to limit the visibility of posts, pages and other post types.', GROUPS_PLUGIN_DOMAIN ) .
107
  '</p>' .
108
  '<p>' .
109
+ __( 'You can select one or more capabilities that are enabled for access restriction.', GROUPS_PLUGIN_DOMAIN ) .
110
  ' ' .
111
  __( 'Note that you must be a member of a group that has such a capability assigned.', GROUPS_PLUGIN_DOMAIN ) .
112
  '</p>' .
lib/access/class-groups-access-shortcodes.php CHANGED
@@ -164,13 +164,13 @@ class Groups_Access_Shortcodes {
164
  if ( $content !== null ) {
165
  $groups_user = new Groups_User( get_current_user_id() );
166
  $capability = $options['capability'];
167
- $capabilities = array_map( 'trim', explode( ',', $capability ) );
168
- $show_content = true;
169
- foreach( $capabilities as $capability ) {
170
- if ( $groups_user->can( $capability ) ) {
171
- $show_content = false;
172
- break;
173
- }
174
  }
175
  if ( $show_content ) {
176
  remove_shortcode( 'groups_can_not' );
164
  if ( $content !== null ) {
165
  $groups_user = new Groups_User( get_current_user_id() );
166
  $capability = $options['capability'];
167
+ $capabilities = array_map( 'trim', explode( ',', $capability ) );
168
+ $show_content = true;
169
+ foreach( $capabilities as $capability ) {
170
+ if ( $groups_user->can( $capability ) ) {
171
+ $show_content = false;
172
+ break;
173
+ }
174
  }
175
  if ( $show_content ) {
176
  remove_shortcode( 'groups_can_not' );
lib/access/class-groups-post-access.php CHANGED
@@ -131,11 +131,11 @@ class Groups_Post_Access {
131
 
132
  // this only applies to logged in users
133
  if ( $user_id ) {
134
- // if administrators can override access, don't filter
135
- if ( get_option( GROUPS_ADMINISTRATOR_ACCESS_OVERRIDE, GROUPS_ADMINISTRATOR_ACCESS_OVERRIDE_DEFAULT ) ) {
136
- if ( user_can( $user_id, 'administrator' ) ) {
137
- return $where;
138
- }
139
  }
140
  }
141
 
@@ -144,8 +144,8 @@ class Groups_Post_Access {
144
  if ( $user = new Groups_User( $user_id ) ) {
145
  $capabilities = $user->capabilities_deep;
146
  if ( is_array( $capabilities ) ) {
147
- foreach ( $capabilities as $capability ) {
148
- $caps[] = "'". $capability . "'";
149
  }
150
  }
151
  }
131
 
132
  // this only applies to logged in users
133
  if ( $user_id ) {
134
+ // if administrators can override access, don't filter
135
+ if ( get_option( GROUPS_ADMINISTRATOR_ACCESS_OVERRIDE, GROUPS_ADMINISTRATOR_ACCESS_OVERRIDE_DEFAULT ) ) {
136
+ if ( user_can( $user_id, 'administrator' ) ) {
137
+ return $where;
138
+ }
139
  }
140
  }
141
 
144
  if ( $user = new Groups_User( $user_id ) ) {
145
  $capabilities = $user->capabilities_deep;
146
  if ( is_array( $capabilities ) ) {
147
+ foreach ( $capabilities as $capability ) {
148
+ $caps[] = "'". $capability . "'";
149
  }
150
  }
151
  }
lib/admin/class-groups-admin-post-columns.php CHANGED
@@ -93,6 +93,7 @@ class Groups_Admin_Post_Columns {
93
  $read_caps = get_post_meta( $post_id, Groups_Post_Access::POSTMETA_PREFIX . Groups_Post_Access::READ_POST_CAPABILITY );
94
  $valid_read_caps = Groups_Options::get_option( Groups_Post_Access::READ_POST_CAPABILITIES, array( Groups_Post_Access::READ_POST_CAPABILITY ) );
95
  if ( count( $valid_read_caps ) > 0 ) {
 
96
  $output = '<ul>';
97
  foreach( $valid_read_caps as $valid_read_cap ) {
98
  if ( $capability = Groups_Capability::read_by_capability( $valid_read_cap ) ) {
93
  $read_caps = get_post_meta( $post_id, Groups_Post_Access::POSTMETA_PREFIX . Groups_Post_Access::READ_POST_CAPABILITY );
94
  $valid_read_caps = Groups_Options::get_option( Groups_Post_Access::READ_POST_CAPABILITIES, array( Groups_Post_Access::READ_POST_CAPABILITY ) );
95
  if ( count( $valid_read_caps ) > 0 ) {
96
+ sort( $valid_read_caps );
97
  $output = '<ul>';
98
  foreach( $valid_read_caps as $valid_read_cap ) {
99
  if ( $capability = Groups_Capability::read_by_capability( $valid_read_cap ) ) {
lib/admin/class-groups-admin-user-profile.php CHANGED
@@ -73,7 +73,7 @@ class Groups_Admin_User_Profile {
73
  foreach( $groups as $group ) {
74
  $output .= '<li>' . wp_filter_nohtml_kses( $group->name ) . '</li>';
75
  }
76
- $output .= '<ul>';
77
  }
78
  }
79
  echo $output;
73
  foreach( $groups as $group ) {
74
  $output .= '<li>' . wp_filter_nohtml_kses( $group->name ) . '</li>';
75
  }
76
+ $output .= '</ul>';
77
  }
78
  }
79
  echo $output;
lib/admin/class-groups-admin.php CHANGED
@@ -28,6 +28,12 @@ if ( !defined( 'ABSPATH' ) ) {
28
  */
29
  class Groups_Admin {
30
 
 
 
 
 
 
 
31
  /**
32
  * Sets up action hooks.
33
  */
@@ -69,6 +75,41 @@ class Groups_Admin {
69
  Groups_UIE::enqueue( 'select' );
70
  }
71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  /**
73
  * Prints admin notices.
74
  */
28
  */
29
  class Groups_Admin {
30
 
31
+ /**
32
+ * Holds admin messages.
33
+ * @var string
34
+ */
35
+ private static $messages = array();
36
+
37
  /**
38
  * Sets up action hooks.
39
  */
75
  Groups_UIE::enqueue( 'select' );
76
  }
77
 
78
+ /**
79
+ * Add a message to the list of messages displayed in the admin sections.
80
+ * The message is filtered using wp_filter_kses() and wrapped in a div
81
+ * with class 'updated' for messages of type 'info' and 'error' for
82
+ * those of type 'error'.
83
+ *
84
+ * @param string $message the message
85
+ * @param string $type type of message, defaults to 'info'
86
+ * @uses wp_filter_kses()
87
+ */
88
+ public static function add_message( $message, $type = 'info' ) {
89
+ $class = 'updated';
90
+ switch( $type ) {
91
+ case 'error' :
92
+ $class = 'error';
93
+ }
94
+ self::$messages[] = '<div class="'.$class.'">' . balanceTags( stripslashes( wp_filter_kses( $message ) ), true ) . '</div>';
95
+ }
96
+
97
+ /**
98
+ * Returns the list of messages as a string.
99
+ * An empty string is returned if there are no messages.
100
+ *
101
+ * @return string
102
+ */
103
+ public static function render_messages() {
104
+ $output = '';
105
+ if ( !empty( self::$messages ) ) {
106
+ $output .= '<div class="groups messages">';
107
+ $output .= implode( '', self::$messages );
108
+ $output .= '</div>';
109
+ }
110
+ return $output;
111
+ }
112
+
113
  /**
114
  * Prints admin notices.
115
  */
lib/admin/groups-admin-capabilities-add.php CHANGED
@@ -51,18 +51,18 @@ function groups_admin_capabilities_add() {
51
  __( 'Add a new capability', GROUPS_PLUGIN_DOMAIN ) .
52
  '</h2>' .
53
  '</div>' .
54
-
55
  '<form id="add-capability" action="' . $current_url . '" method="post">' .
56
  '<div class="capability new">' .
57
 
58
  '<div class="field">' .
59
  '<label for="capability-field" class="field-label first required">' .__( 'Capability', GROUPS_PLUGIN_DOMAIN ) . '</label>' .
60
- '<input id="name-field" name="capability-field" class="capability-field" type="text" value="' . esc_attr( $capability ) . '"/>' .
61
  '</div>' .
62
 
63
  '<div class="field">' .
64
  '<label for="description-field" class="field-label description-field">' .__( 'Description', GROUPS_PLUGIN_DOMAIN ) . '</label>' .
65
- '<textarea id="description-field" name="description-field" rows="5" cols="45">' . wp_filter_nohtml_kses( $description ) . '</textarea>' .
66
  '</div>' .
67
 
68
  '<div class="field">' .
@@ -99,5 +99,13 @@ function groups_admin_capabilities_add_submit() {
99
  $capability = isset( $_POST['capability-field'] ) ? $_POST['capability-field'] : null;
100
  $description = isset( $_POST['description-field'] ) ? $_POST['description-field'] : '';
101
 
102
- return Groups_Capability::create( compact( "capability", "description" ) );
 
 
 
 
 
 
 
 
103
  } // function groups_admin_capabilities_add_submit
51
  __( 'Add a new capability', GROUPS_PLUGIN_DOMAIN ) .
52
  '</h2>' .
53
  '</div>' .
54
+ Groups_Admin::render_messages() .
55
  '<form id="add-capability" action="' . $current_url . '" method="post">' .
56
  '<div class="capability new">' .
57
 
58
  '<div class="field">' .
59
  '<label for="capability-field" class="field-label first required">' .__( 'Capability', GROUPS_PLUGIN_DOMAIN ) . '</label>' .
60
+ '<input id="name-field" name="capability-field" class="capability-field" type="text" value="' . esc_attr( stripslashes( $capability ) ) . '"/>' .
61
  '</div>' .
62
 
63
  '<div class="field">' .
64
  '<label for="description-field" class="field-label description-field">' .__( 'Description', GROUPS_PLUGIN_DOMAIN ) . '</label>' .
65
+ '<textarea id="description-field" name="description-field" rows="5" cols="45">' . stripslashes( wp_filter_nohtml_kses( $description ) ) . '</textarea>' .
66
  '</div>' .
67
 
68
  '<div class="field">' .
99
  $capability = isset( $_POST['capability-field'] ) ? $_POST['capability-field'] : null;
100
  $description = isset( $_POST['description-field'] ) ? $_POST['description-field'] : '';
101
 
102
+ $capability_id = Groups_Capability::create( compact( "capability", "description" ) );
103
+ if ( !$capability_id ) {
104
+ if ( empty( $capability ) ) {
105
+ Groups_Admin::add_message( __( 'The <em>Capability</em> must not be empty.', GROUPS_PLUGIN_DOMAIN ), 'error' );
106
+ } else if ( Groups_Capability::read_by_capability( $capability ) ) {
107
+ Groups_Admin::add_message( sprintf( __( 'The <em>%s</em> capability already exists.', GROUPS_PLUGIN_DOMAIN ), stripslashes( wp_filter_nohtml_kses( ( $capability ) ) ) ), 'error' );
108
+ }
109
+ }
110
+ return $capability_id;
111
  } // function groups_admin_capabilities_add_submit
lib/admin/groups-admin-capabilities-edit.php CHANGED
@@ -57,6 +57,8 @@ function groups_admin_capabilities_edit( $capability_id ) {
57
  __( 'Edit a capability', GROUPS_PLUGIN_DOMAIN ) .
58
  '</h2>' .
59
  '</div>' .
 
 
60
 
61
  '<form id="edit-capability" action="' . $current_url . '" method="post">' .
62
  '<div class="capability edit">' .
@@ -64,12 +66,12 @@ function groups_admin_capabilities_edit( $capability_id ) {
64
 
65
  '<div class="field">' .
66
  '<label for="capability-field" class="field-label first required">' .__( 'Capability', GROUPS_PLUGIN_DOMAIN ) . '</label>' .
67
- '<input ' . $capability_readonly . ' id="capability-field" name="capability-field" class="capability-field" type="text" value="' . esc_attr( $capability_capability ) . '"/>' .
68
  '</div>' .
69
 
70
  '<div class="field">' .
71
  '<label for="description-field" class="field-label description-field">' .__( 'Description', GROUPS_PLUGIN_DOMAIN ) . '</label>' .
72
- '<textarea id="description-field" name="description-field" rows="5" cols="45">' . wp_filter_nohtml_kses( $description ) . '</textarea>' .
73
  '</div>' .
74
 
75
  '<div class="field">' .
@@ -91,28 +93,46 @@ function groups_admin_capabilities_edit( $capability_id ) {
91
  * Handle edit form submission.
92
  */
93
  function groups_admin_capabilities_edit_submit() {
94
-
 
 
95
  if ( !current_user_can( GROUPS_ADMINISTER_GROUPS ) ) {
96
  wp_die( __( 'Access denied.', GROUPS_PLUGIN_DOMAIN ) );
97
  }
98
-
99
  if ( !wp_verify_nonce( $_POST[GROUPS_ADMIN_GROUPS_NONCE], 'capabilities-edit' ) ) {
100
  wp_die( __( 'Access denied.', GROUPS_PLUGIN_DOMAIN ) );
101
  }
102
-
103
  $capability_id = isset( $_POST['capability-id-field'] ) ? $_POST['capability-id-field'] : null;
104
  $capability = Groups_Capability::read( $capability_id );
105
  if ( $capability ) {
106
  $capability_id = $capability->capability_id;
107
  if ( $capability->capability !== Groups_Post_Access::READ_POST_CAPABILITY ) {
108
- $capability = isset( $_POST['capability-field'] ) ? $_POST['capability-field'] : null;
109
  } else {
110
- $capability = Groups_Post_Access::READ_POST_CAPABILITY;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
  }
112
- $description = isset( $_POST['description-field'] ) ? $_POST['description-field'] : '';
113
- return Groups_Capability::update( compact( "capability_id", "capability", "description" ) );
114
- } else {
115
- return false;
116
  }
117
-
118
  } // function groups_admin_capabilities_edit_submit
57
  __( 'Edit a capability', GROUPS_PLUGIN_DOMAIN ) .
58
  '</h2>' .
59
  '</div>' .
60
+
61
+ Groups_Admin::render_messages() .
62
 
63
  '<form id="edit-capability" action="' . $current_url . '" method="post">' .
64
  '<div class="capability edit">' .
66
 
67
  '<div class="field">' .
68
  '<label for="capability-field" class="field-label first required">' .__( 'Capability', GROUPS_PLUGIN_DOMAIN ) . '</label>' .
69
+ '<input ' . $capability_readonly . ' id="capability-field" name="capability-field" class="capability-field" type="text" value="' . esc_attr( stripslashes( $capability_capability ) ) . '"/>' .
70
  '</div>' .
71
 
72
  '<div class="field">' .
73
  '<label for="description-field" class="field-label description-field">' .__( 'Description', GROUPS_PLUGIN_DOMAIN ) . '</label>' .
74
+ '<textarea id="description-field" name="description-field" rows="5" cols="45">' . stripslashes( wp_filter_nohtml_kses( $description ) ) . '</textarea>' .
75
  '</div>' .
76
 
77
  '<div class="field">' .
93
  * Handle edit form submission.
94
  */
95
  function groups_admin_capabilities_edit_submit() {
96
+
97
+ $result = false;
98
+
99
  if ( !current_user_can( GROUPS_ADMINISTER_GROUPS ) ) {
100
  wp_die( __( 'Access denied.', GROUPS_PLUGIN_DOMAIN ) );
101
  }
102
+
103
  if ( !wp_verify_nonce( $_POST[GROUPS_ADMIN_GROUPS_NONCE], 'capabilities-edit' ) ) {
104
  wp_die( __( 'Access denied.', GROUPS_PLUGIN_DOMAIN ) );
105
  }
106
+
107
  $capability_id = isset( $_POST['capability-id-field'] ) ? $_POST['capability-id-field'] : null;
108
  $capability = Groups_Capability::read( $capability_id );
109
  if ( $capability ) {
110
  $capability_id = $capability->capability_id;
111
  if ( $capability->capability !== Groups_Post_Access::READ_POST_CAPABILITY ) {
112
+ $capability_field = isset( $_POST['capability-field'] ) ? $_POST['capability-field'] : null;
113
  } else {
114
+ $capability_field = Groups_Post_Access::READ_POST_CAPABILITY;
115
+ }
116
+ if ( !empty( $capability_field ) ) {
117
+ $update = true;
118
+ if ( $other_capability = Groups_Capability::read_by_capability( $capability_field ) ) {
119
+ if ( $other_capability->capability_id != $capability_id ) {
120
+ Groups_Admin::add_message( sprintf( __( 'The <em>%s</em> capability already exists and cannot be assigned to this one.', GROUPS_PLUGIN_DOMAIN ), stripslashes( wp_filter_nohtml_kses( $other_capability->capability ) ) ), 'error' );
121
+ $update = false;
122
+ }
123
+ }
124
+ if ( $update ) {
125
+ $description = isset( $_POST['description-field'] ) ? $_POST['description-field'] : '';
126
+ $capability_id = Groups_Capability::update( array( 'capability_id' => $capability_id, 'capability' => $capability_field, 'description' => $description ) );
127
+ if ( $capability_id ) {
128
+ $result = $capability_id;
129
+ } else {
130
+ Groups_Admin::add_message( sprintf( __( 'The <em>%s</em> capability could not be updated.', GROUPS_PLUGIN_DOMAIN ), stripslashes( wp_filter_nohtml_kses( $capability ) ) ), 'error' );
131
+ }
132
+ }
133
+ } else {
134
+ Groups_Admin::add_message( __( 'The <em>Capability</em> must not be empty.', GROUPS_PLUGIN_DOMAIN ), 'error' );
135
  }
 
 
 
 
136
  }
137
+ return $result;
138
  } // function groups_admin_capabilities_edit_submit
lib/admin/groups-admin-capabilities-remove.php CHANGED
@@ -58,7 +58,7 @@ function groups_admin_capabilities_remove( $capability_id ) {
58
  '<div class="capability remove">' .
59
  '<input id="capability-id-field" name="capability-id-field" type="hidden" value="' . esc_attr( intval( $capability->capability_id ) ) . '"/>' .
60
  '<ul>' .
61
- '<li>' . sprintf( __( 'Capability : %s', GROUPS_PLUGIN_DOMAIN ), wp_filter_nohtml_kses( $capability->capability ) ) . '</li>' .
62
  '</ul> ' .
63
  wp_nonce_field( 'capabilities-remove', GROUPS_ADMIN_GROUPS_NONCE, true, false ) .
64
  '<input class="button" type="submit" value="' . __( 'Remove', GROUPS_PLUGIN_DOMAIN ) . '"/>' .
58
  '<div class="capability remove">' .
59
  '<input id="capability-id-field" name="capability-id-field" type="hidden" value="' . esc_attr( intval( $capability->capability_id ) ) . '"/>' .
60
  '<ul>' .
61
+ '<li>' . sprintf( __( 'Capability : %s', GROUPS_PLUGIN_DOMAIN ), stripslashes( wp_filter_nohtml_kses( $capability->capability ) ) ) . '</li>' .
62
  '</ul> ' .
63
  wp_nonce_field( 'capabilities-remove', GROUPS_ADMIN_GROUPS_NONCE, true, false ) .
64
  '<input class="button" type="submit" value="' . __( 'Remove', GROUPS_PLUGIN_DOMAIN ) . '"/>' .
lib/admin/groups-admin-capabilities.php CHANGED
@@ -55,17 +55,25 @@ function groups_admin_capabilities() {
55
  // handle action submit - do it
56
  switch( $_POST['action'] ) {
57
  case 'add' :
58
- if ( !groups_admin_capabilities_add_submit() ) {
59
  return groups_admin_capabilities_add();
 
 
 
60
  }
61
  break;
62
  case 'edit' :
63
- if ( !groups_admin_capabilities_edit_submit() ) {
64
  return groups_admin_capabilities_edit( $_POST['capability-id-field'] );
 
 
 
65
  }
66
  break;
67
  case 'remove' :
68
- groups_admin_capabilities_remove_submit();
 
 
69
  break;
70
  // bulk actions on groups: capabilities
71
  case 'groups-action' :
@@ -185,7 +193,9 @@ function groups_admin_capabilities() {
185
  __( 'Capabilities', GROUPS_PLUGIN_DOMAIN ) .
186
  '</h2>' .
187
  '</div>';
188
-
 
 
189
  $output .=
190
  '<div class="manage">' .
191
  "<a title='" . __( 'Click to add a new capability', GROUPS_PLUGIN_DOMAIN ) . "' class='add button' href='" . esc_url( $current_url ) . "&action=add'><img class='icon' alt='" . __( 'Add', GROUPS_PLUGIN_DOMAIN) . "' src='". GROUPS_PLUGIN_URL . "images/add.png'/><span class='label'>" . __( 'New Capability', GROUPS_PLUGIN_DOMAIN) . "</span></a>" .
55
  // handle action submit - do it
56
  switch( $_POST['action'] ) {
57
  case 'add' :
58
+ if ( !( $capability_id = groups_admin_capabilities_add_submit() ) ) {
59
  return groups_admin_capabilities_add();
60
+ } else {
61
+ $capability = Groups_Capability::read( $capability_id );
62
+ Groups_Admin::add_message( sprintf( __( 'The <em>%s</em> capability has been created.', GROUPS_PLUGIN_DOMAIN ), stripslashes( wp_filter_nohtml_kses( $capability->capability ) ) ) );
63
  }
64
  break;
65
  case 'edit' :
66
+ if ( !( $capability_id = groups_admin_capabilities_edit_submit() ) ) {
67
  return groups_admin_capabilities_edit( $_POST['capability-id-field'] );
68
+ } else {
69
+ $capability = Groups_Capability::read( $capability_id );
70
+ Groups_Admin::add_message( sprintf( __( 'The <em>%s</em> capability has been updated.', GROUPS_PLUGIN_DOMAIN ), stripslashes( wp_filter_nohtml_kses( $capability->capability ) ) ) );
71
  }
72
  break;
73
  case 'remove' :
74
+ if ( $capability_id = groups_admin_capabilities_remove_submit() ) {
75
+ Groups_Admin::add_message( __( 'The capability has been deleted.', GROUPS_PLUGIN_DOMAIN ) );
76
+ }
77
  break;
78
  // bulk actions on groups: capabilities
79
  case 'groups-action' :
193
  __( 'Capabilities', GROUPS_PLUGIN_DOMAIN ) .
194
  '</h2>' .
195
  '</div>';
196
+
197
+ $output .= Groups_Admin::render_messages();
198
+
199
  $output .=
200
  '<div class="manage">' .
201
  "<a title='" . __( 'Click to add a new capability', GROUPS_PLUGIN_DOMAIN ) . "' class='add button' href='" . esc_url( $current_url ) . "&action=add'><img class='icon' alt='" . __( 'Add', GROUPS_PLUGIN_DOMAIN) . "' src='". GROUPS_PLUGIN_URL . "images/add.png'/><span class='label'>" . __( 'New Capability', GROUPS_PLUGIN_DOMAIN) . "</span></a>" .
lib/admin/groups-admin-groups-add.php CHANGED
@@ -61,6 +61,8 @@ function groups_admin_groups_add() {
61
  $output .= '</h2>';
62
  $output .= '</div>';
63
 
 
 
64
  $output .= '<form id="add-group" action="' . $current_url . '" method="post">';
65
  $output .= '<div class="group new">';
66
 
@@ -68,7 +70,7 @@ function groups_admin_groups_add() {
68
  $output .= '<label for="name-field" class="field-label first required">';
69
  $output .= __( 'Name', GROUPS_PLUGIN_DOMAIN );
70
  $output .= '</label>';
71
- $output .= '<input id="name-field" name="name-field" class="namefield" type="text" value="' . esc_attr( $name ) . '"/>';
72
  $output .= '</div>';
73
 
74
  $output .= '<div class="field">';
@@ -83,7 +85,7 @@ function groups_admin_groups_add() {
83
  $output .= __( 'Description', GROUPS_PLUGIN_DOMAIN );
84
  $output .= '</label>';
85
  $output .= '<textarea id="description-field" name="description-field" rows="5" cols="45">';
86
- $output .= wp_filter_nohtml_kses( $description );
87
  $output .= '</textarea>';
88
  $output .= '</div>';
89
 
@@ -93,7 +95,7 @@ function groups_admin_groups_add() {
93
  $capabilities = $wpdb->get_results( "SELECT * FROM $capability_table ORDER BY capability" );
94
 
95
  $output .= '<div class="select-capability-container" style="width:62%;">';
96
- $output .= '<label>';
97
  $output .= __( 'Capabilities', GROUPS_PLUGIN_DOMAIN );
98
  $output .= sprintf(
99
  '<select class="select capability" name="capability_ids[]" multiple="multiple" placeholder="%s">',
@@ -105,8 +107,8 @@ function groups_admin_groups_add() {
105
  $output .= '</select>';
106
  $output .= '</label>';
107
  $output .= '</div>';
108
- $output .= '<p class="description">';
109
- $output .= __( 'These capabilities will be assigned to the group.', GROUPS_PLUGIN_DOMAIN );
110
  $output .= '</p>';
111
 
112
  $output .= Groups_UIE::render_select( '.select.capability' );
@@ -158,6 +160,12 @@ function groups_admin_groups_add_submit() {
158
  Groups_Group_Capability::create( array( 'group_id' => $group_id, 'capability_id' => $cap ) );
159
  }
160
  }
 
 
 
 
 
 
161
  }
162
 
163
  return $group_id;
61
  $output .= '</h2>';
62
  $output .= '</div>';
63
 
64
+ $output .= Groups_Admin::render_messages();
65
+
66
  $output .= '<form id="add-group" action="' . $current_url . '" method="post">';
67
  $output .= '<div class="group new">';
68
 
70
  $output .= '<label for="name-field" class="field-label first required">';
71
  $output .= __( 'Name', GROUPS_PLUGIN_DOMAIN );
72
  $output .= '</label>';
73
+ $output .= '<input id="name-field" name="name-field" class="namefield" type="text" value="' . esc_attr( stripslashes( $name ) ) . '"/>';
74
  $output .= '</div>';
75
 
76
  $output .= '<div class="field">';
85
  $output .= __( 'Description', GROUPS_PLUGIN_DOMAIN );
86
  $output .= '</label>';
87
  $output .= '<textarea id="description-field" name="description-field" rows="5" cols="45">';
88
+ $output .= stripslashes( wp_filter_nohtml_kses( $description ) );
89
  $output .= '</textarea>';
90
  $output .= '</div>';
91
 
95
  $capabilities = $wpdb->get_results( "SELECT * FROM $capability_table ORDER BY capability" );
96
 
97
  $output .= '<div class="select-capability-container" style="width:62%;">';
98
+ $output .= '<label>';
99
  $output .= __( 'Capabilities', GROUPS_PLUGIN_DOMAIN );
100
  $output .= sprintf(
101
  '<select class="select capability" name="capability_ids[]" multiple="multiple" placeholder="%s">',
107
  $output .= '</select>';
108
  $output .= '</label>';
109
  $output .= '</div>';
110
+ $output .= '<p class="description">';
111
+ $output .= __( 'These capabilities will be assigned to the group.', GROUPS_PLUGIN_DOMAIN );
112
  $output .= '</p>';
113
 
114
  $output .= Groups_UIE::render_select( '.select.capability' );
160
  Groups_Group_Capability::create( array( 'group_id' => $group_id, 'capability_id' => $cap ) );
161
  }
162
  }
163
+ } else {
164
+ if ( !$name ) {
165
+ Groups_Admin::add_message( __( 'The name must not be empty.', GROUPS_PLUGIN_DOMAIN ), 'error' );
166
+ } else if ( Groups_Group::read_by_name( $name ) ) {
167
+ Groups_Admin::add_message( sprintf( __( 'The <em>%s</em> group already exists.', GROUPS_PLUGIN_DOMAIN ), stripslashes( wp_filter_nohtml_kses( ( $name ) ) ) ), 'error' );
168
+ }
169
  }
170
 
171
  return $group_id;
lib/admin/groups-admin-groups-edit.php CHANGED
@@ -70,6 +70,8 @@ function groups_admin_groups_edit( $group_id ) {
70
  $output .= '</h2>';
71
  $output .= '</div>';
72
 
 
 
73
  $output .= '<form id="edit-group" action="' . $current_url . '" method="post">';
74
  $output .= '<div class="group edit">';
75
  $output .= '<input id="group-id-field" name="group-id-field" type="hidden" value="' . esc_attr( intval( $group_id ) ) . '"/>';
@@ -78,7 +80,7 @@ function groups_admin_groups_edit( $group_id ) {
78
  $output .= '<label for="name-field" class="field-label first required">';
79
  $output .= __( 'Name', GROUPS_PLUGIN_DOMAIN );
80
  $output .= '</label>';
81
- $output .= '<input ' . $name_readonly . ' id="name-field" name="name-field" class="namefield" type="text" value="' . esc_attr( $name ) . '"/>';
82
  $output .= '</div>';
83
 
84
  $output .= '<div class="field">';
@@ -93,7 +95,7 @@ function groups_admin_groups_edit( $group_id ) {
93
  $output .= __( 'Description', GROUPS_PLUGIN_DOMAIN );
94
  $output .= '</label>';
95
  $output .= '<textarea id="description-field" name="description-field" rows="5" cols="45">';
96
- $output .= wp_filter_nohtml_kses( $description );
97
  $output .= '</textarea>';
98
  $output .= '</div>';
99
 
@@ -113,7 +115,7 @@ function groups_admin_groups_edit( $group_id ) {
113
 
114
  $output .= '<div class="field">';
115
  $output .= '<div class="select-capability-container" style="width:62%;">';
116
- $output .= '<label>';
117
  $output .= __( 'Capabilities', GROUPS_PLUGIN_DOMAIN );
118
  $output .= sprintf(
119
  '<select class="select capability" name="capability_ids[]" multiple="multiple" placeholder="%s">',
@@ -126,8 +128,8 @@ function groups_admin_groups_edit( $group_id ) {
126
  $output .= '</select>';
127
  $output .= '</label>';
128
  $output .= '</div>'; // .select-capability-container
129
- $output .= '<p class="description">';
130
- $output .= __( 'The chosen capabilities are assigned to the group.', GROUPS_PLUGIN_DOMAIN );
131
  $output .= '</p>';
132
  $output .= '</div>'; // .field
133
  $output .= Groups_UIE::render_select( '.select.capability' );
@@ -172,6 +174,24 @@ function groups_admin_groups_edit_submit() {
172
  }
173
  $parent_id = isset( $_POST['parent-id-field'] ) ? $_POST['parent-id-field'] : null;
174
  $description = isset( $_POST['description-field'] ) ? $_POST['description-field'] : '';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
  $group_id = Groups_Group::update( compact( "group_id", "name", "parent_id", "description" ) );
176
 
177
  if ( $group_id ) {
70
  $output .= '</h2>';
71
  $output .= '</div>';
72
 
73
+ $output .= Groups_Admin::render_messages();
74
+
75
  $output .= '<form id="edit-group" action="' . $current_url . '" method="post">';
76
  $output .= '<div class="group edit">';
77
  $output .= '<input id="group-id-field" name="group-id-field" type="hidden" value="' . esc_attr( intval( $group_id ) ) . '"/>';
80
  $output .= '<label for="name-field" class="field-label first required">';
81
  $output .= __( 'Name', GROUPS_PLUGIN_DOMAIN );
82
  $output .= '</label>';
83
+ $output .= '<input ' . $name_readonly . ' id="name-field" name="name-field" class="namefield" type="text" value="' . esc_attr( stripslashes( $name ) ) . '"/>';
84
  $output .= '</div>';
85
 
86
  $output .= '<div class="field">';
95
  $output .= __( 'Description', GROUPS_PLUGIN_DOMAIN );
96
  $output .= '</label>';
97
  $output .= '<textarea id="description-field" name="description-field" rows="5" cols="45">';
98
+ $output .= stripslashes( wp_filter_nohtml_kses( $description ) );
99
  $output .= '</textarea>';
100
  $output .= '</div>';
101
 
115
 
116
  $output .= '<div class="field">';
117
  $output .= '<div class="select-capability-container" style="width:62%;">';
118
+ $output .= '<label>';
119
  $output .= __( 'Capabilities', GROUPS_PLUGIN_DOMAIN );
120
  $output .= sprintf(
121
  '<select class="select capability" name="capability_ids[]" multiple="multiple" placeholder="%s">',
128
  $output .= '</select>';
129
  $output .= '</label>';
130
  $output .= '</div>'; // .select-capability-container
131
+ $output .= '<p class="description">';
132
+ $output .= __( 'The chosen capabilities are assigned to the group.', GROUPS_PLUGIN_DOMAIN );
133
  $output .= '</p>';
134
  $output .= '</div>'; // .field
135
  $output .= Groups_UIE::render_select( '.select.capability' );
174
  }
175
  $parent_id = isset( $_POST['parent-id-field'] ) ? $_POST['parent-id-field'] : null;
176
  $description = isset( $_POST['description-field'] ) ? $_POST['description-field'] : '';
177
+
178
+ if ( empty( $name ) ) {
179
+ Groups_Admin::add_message( __( 'The <em>Name</em> must not be empty.', GROUPS_PLUGIN_DOMAIN ), 'error' );
180
+ return false;
181
+ }
182
+
183
+ if ( $other_group = Groups_Group::read_by_name( $name ) ) {
184
+ if ( $other_group->group_id != $group_id ) {
185
+ Groups_Admin::add_message(
186
+ sprintf(
187
+ __( 'The <em>%s</em> group already exists and cannot be used to name this one.', GROUPS_PLUGIN_DOMAIN ), stripslashes( wp_filter_nohtml_kses( $other_group->name ) )
188
+ ),
189
+ 'error'
190
+ );
191
+ return false;
192
+ }
193
+ }
194
+
195
  $group_id = Groups_Group::update( compact( "group_id", "name", "parent_id", "description" ) );
196
 
197
  if ( $group_id ) {
lib/admin/groups-admin-groups-remove.php CHANGED
@@ -58,7 +58,7 @@ function groups_admin_groups_remove( $group_id ) {
58
  '<div class="group remove">' .
59
  '<input id="group-id-field" name="group-id-field" type="hidden" value="' . esc_attr( intval( $group->group_id ) ) . '"/>' .
60
  '<ul>' .
61
- '<li>' . sprintf( __( 'Group Name : %s', GROUPS_PLUGIN_DOMAIN ), wp_filter_nohtml_kses( $group->name ) ) . '</li>' .
62
  '</ul> ' .
63
  wp_nonce_field( 'groups-remove', GROUPS_ADMIN_GROUPS_NONCE, true, false ) .
64
  '<input class="button" type="submit" value="' . __( 'Remove', GROUPS_PLUGIN_DOMAIN ) . '"/>' .
58
  '<div class="group remove">' .
59
  '<input id="group-id-field" name="group-id-field" type="hidden" value="' . esc_attr( intval( $group->group_id ) ) . '"/>' .
60
  '<ul>' .
61
+ '<li>' . sprintf( __( 'Group Name : %s', GROUPS_PLUGIN_DOMAIN ), stripslashes( wp_filter_nohtml_kses( $group->name ) ) ) . '</li>' .
62
  '</ul> ' .
63
  wp_nonce_field( 'groups-remove', GROUPS_ADMIN_GROUPS_NONCE, true, false ) .
64
  '<input class="button" type="submit" value="' . __( 'Remove', GROUPS_PLUGIN_DOMAIN ) . '"/>' .
lib/admin/groups-admin-groups.php CHANGED
@@ -56,17 +56,25 @@ function groups_admin_groups() {
56
  // handle action submit - do it
57
  switch( $_POST['action'] ) {
58
  case 'add' :
59
- if ( !groups_admin_groups_add_submit() ) {
60
  return groups_admin_groups_add();
 
 
 
61
  }
62
  break;
63
  case 'edit' :
64
- if ( !groups_admin_groups_edit_submit() ) {
65
  return groups_admin_groups_edit( $_POST['group-id-field'] );
 
 
 
66
  }
67
  break;
68
  case 'remove' :
69
- groups_admin_groups_remove_submit();
 
 
70
  break;
71
  // bulk actions on groups: add capabilities, remove capabilities, remove groups
72
  case 'groups-action' :
@@ -193,6 +201,8 @@ function groups_admin_groups() {
193
  '</h2>' .
194
  '</div>';
195
 
 
 
196
  $output .=
197
  '<div class="manage">' .
198
  "<a title='" . __( 'Click to add a new group', GROUPS_PLUGIN_DOMAIN ) . "' class='add button' href='" . esc_url( $current_url ) . "&action=add'><img class='icon' alt='" . __( 'Add', GROUPS_PLUGIN_DOMAIN) . "' src='". GROUPS_PLUGIN_URL ."images/add.png'/><span class='label'>" . __( 'New Group', GROUPS_PLUGIN_DOMAIN) . "</span></a>" .
@@ -323,15 +333,15 @@ function groups_admin_groups() {
323
  $output .= '</form>';
324
  }
325
 
326
- $output .= '<div class="page-options right">';
327
- $output .= '<form id="setrowcount" action="" method="post">';
328
- $output .= '<div>';
329
- $output .= '<label for="row_count">' . __('Results per page', GROUPS_PLUGIN_DOMAIN ) . '</label>';
330
- $output .= '<input name="row_count" type="text" size="2" value="' . esc_attr( $row_count ) .'" />';
331
- $output .= wp_nonce_field( 'admin', GROUPS_ADMIN_GROUPS_NONCE_1, true, false );
332
- $output .= '<input class="button" type="submit" value="' . __( 'Apply', GROUPS_PLUGIN_DOMAIN ) . '"/>';
333
- $output .= '</div>';
334
- $output .= '</form>';
335
  $output .= '</div>';
336
 
337
  $capability_table = _groups_get_tablename( "capability" );
56
  // handle action submit - do it
57
  switch( $_POST['action'] ) {
58
  case 'add' :
59
+ if ( !( $group_id = groups_admin_groups_add_submit() ) ) {
60
  return groups_admin_groups_add();
61
+ } else {
62
+ $group = Groups_Group::read( $group_id );
63
+ Groups_Admin::add_message( sprintf( __( "The <em>%s</em> group has been created.", GROUPS_PLUGIN_DOMAIN ), stripslashes( wp_filter_nohtml_kses( $group->name ) ) ) );
64
  }
65
  break;
66
  case 'edit' :
67
+ if ( !( $group_id = groups_admin_groups_edit_submit() ) ) {
68
  return groups_admin_groups_edit( $_POST['group-id-field'] );
69
+ } else {
70
+ $group = Groups_Group::read( $group_id );
71
+ Groups_Admin::add_message( sprintf( __( 'The <em>%s</em> group has been updated.', GROUPS_PLUGIN_DOMAIN ), stripslashes( wp_filter_nohtml_kses( $group->name ) ) ) );
72
  }
73
  break;
74
  case 'remove' :
75
+ if ( $group_id = groups_admin_groups_remove_submit() ) {
76
+ Groups_Admin::add_message( __( 'The group has been deleted.', GROUPS_PLUGIN_DOMAIN ) );
77
+ }
78
  break;
79
  // bulk actions on groups: add capabilities, remove capabilities, remove groups
80
  case 'groups-action' :
201
  '</h2>' .
202
  '</div>';
203
 
204
+ $output .= Groups_Admin::render_messages();
205
+
206
  $output .=
207
  '<div class="manage">' .
208
  "<a title='" . __( 'Click to add a new group', GROUPS_PLUGIN_DOMAIN ) . "' class='add button' href='" . esc_url( $current_url ) . "&action=add'><img class='icon' alt='" . __( 'Add', GROUPS_PLUGIN_DOMAIN) . "' src='". GROUPS_PLUGIN_URL ."images/add.png'/><span class='label'>" . __( 'New Group', GROUPS_PLUGIN_DOMAIN) . "</span></a>" .
333
  $output .= '</form>';
334
  }
335
 
336
+ $output .= '<div class="page-options right">';
337
+ $output .= '<form id="setrowcount" action="" method="post">';
338
+ $output .= '<div>';
339
+ $output .= '<label for="row_count">' . __('Results per page', GROUPS_PLUGIN_DOMAIN ) . '</label>';
340
+ $output .= '<input name="row_count" type="text" size="2" value="' . esc_attr( $row_count ) .'" />';
341
+ $output .= wp_nonce_field( 'admin', GROUPS_ADMIN_GROUPS_NONCE_1, true, false );
342
+ $output .= '<input class="button" type="submit" value="' . __( 'Apply', GROUPS_PLUGIN_DOMAIN ) . '"/>';
343
+ $output .= '</div>';
344
+ $output .= '</form>';
345
  $output .= '</div>';
346
 
347
  $capability_table = _groups_get_tablename( "capability" );
lib/admin/groups-admin-options.php CHANGED
@@ -181,16 +181,16 @@ function groups_admin_options() {
181
 
182
  $delete_data = Groups_Options::get_option( 'groups_delete_data', false );
183
 
184
- if ( isset( $_GET['dismiss-groups-extensions-box'] ) && isset( $_GET['groups-extensions-box-nonce'] ) && wp_verify_nonce( $_GET['groups-extensions-box-nonce'], 'dismiss-box' ) ) {
185
- Groups_Options::update_user_option( 'show-extensions-box', false );
186
  }
187
  $extensions_box = '';
188
  if ( Groups_Options::get_user_option( 'show-extensions-box', true ) ) {
189
  $dismiss_url = wp_nonce_url( add_query_arg( 'dismiss-groups-extensions-box', '1', admin_url( 'admin.php?page=groups-admin-options' ) ), 'dismiss-box', 'groups-extensions-box-nonce' );
190
  $extensions_box =
191
- '<div id="groups-extensions-box">' .
192
- __( 'Enhanced functionality is available via official <a href="http://www.itthinx.com/plugins/groups/">Extensions</a> for Groups.', GROUPS_PLUGIN_DOMAIN ) .
193
- sprintf( '<a class="close" href="%s">x</a>', esc_url( $dismiss_url ) ) .
194
  '</div>';
195
  }
196
 
181
 
182
  $delete_data = Groups_Options::get_option( 'groups_delete_data', false );
183
 
184
+ if ( isset( $_GET['dismiss-groups-extensions-box'] ) && isset( $_GET['groups-extensions-box-nonce'] ) && wp_verify_nonce( $_GET['groups-extensions-box-nonce'], 'dismiss-box' ) ) {
185
+ Groups_Options::update_user_option( 'show-extensions-box', false );
186
  }
187
  $extensions_box = '';
188
  if ( Groups_Options::get_user_option( 'show-extensions-box', true ) ) {
189
  $dismiss_url = wp_nonce_url( add_query_arg( 'dismiss-groups-extensions-box', '1', admin_url( 'admin.php?page=groups-admin-options' ) ), 'dismiss-box', 'groups-extensions-box-nonce' );
190
  $extensions_box =
191
+ '<div id="groups-extensions-box">' .
192
+ __( 'Enhanced functionality is available via official <a href="http://www.itthinx.com/plugins/groups/">Extensions</a> for Groups.', GROUPS_PLUGIN_DOMAIN ) .
193
+ sprintf( '<a class="close" href="%s">x</a>', esc_url( $dismiss_url ) ) .
194
  '</div>';
195
  }
196
 
lib/core/class-groups-capability.php CHANGED
@@ -73,31 +73,31 @@ class Groups_Capability {
73
  case "description" :
74
  $result = $this->capability->$name;
75
  break;
76
- case 'group_ids' :
77
- $group_capability_table = _groups_get_tablename( "group_capability" );
78
- $rows = $wpdb->get_results( $wpdb->prepare(
79
- "SELECT group_id FROM $group_capability_table WHERE capability_id = %d",
80
- Groups_Utility::id( $this->capability->capability_id )
81
- ) );
82
- if ( $rows ) {
83
- $result = array();
84
- foreach( $rows as $row ) {
85
- $result[] = $row->group_id;
86
- }
87
- }
88
  break;
89
- case 'groups' :
90
- $group_capability_table = _groups_get_tablename( "group_capability" );
91
- $rows = $wpdb->get_results( $wpdb->prepare(
92
- "SELECT group_id FROM $group_capability_table WHERE capability_id = %d",
93
- Groups_Utility::id( $this->capability->capability_id )
94
- ) );
95
- if ( $rows ) {
96
- $result = array();
97
- foreach( $rows as $row ) {
98
- $result[] = new Groups_Group( $row->group_id );
99
- }
100
- }
101
  break;
102
  }
103
  }
@@ -245,7 +245,7 @@ class Groups_Capability {
245
  $old_capability->description,
246
  Groups_Utility::id( $capability_id )
247
  ) );
248
- if ( ( $rows !== false ) && ( $rows > 0 ) ) {
249
  $result = $capability_id;
250
  do_action( "groups_updated_capability", $result );
251
  }
73
  case "description" :
74
  $result = $this->capability->$name;
75
  break;
76
+ case 'group_ids' :
77
+ $group_capability_table = _groups_get_tablename( "group_capability" );
78
+ $rows = $wpdb->get_results( $wpdb->prepare(
79
+ "SELECT group_id FROM $group_capability_table WHERE capability_id = %d",
80
+ Groups_Utility::id( $this->capability->capability_id )
81
+ ) );
82
+ if ( $rows ) {
83
+ $result = array();
84
+ foreach( $rows as $row ) {
85
+ $result[] = $row->group_id;
86
+ }
87
+ }
88
  break;
89
+ case 'groups' :
90
+ $group_capability_table = _groups_get_tablename( "group_capability" );
91
+ $rows = $wpdb->get_results( $wpdb->prepare(
92
+ "SELECT group_id FROM $group_capability_table WHERE capability_id = %d",
93
+ Groups_Utility::id( $this->capability->capability_id )
94
+ ) );
95
+ if ( $rows ) {
96
+ $result = array();
97
+ foreach( $rows as $row ) {
98
+ $result[] = new Groups_Group( $row->group_id );
99
+ }
100
+ }
101
  break;
102
  }
103
  }
245
  $old_capability->description,
246
  Groups_Utility::id( $capability_id )
247
  ) );
248
+ if ( ( $rows !== false ) ) {
249
  $result = $capability_id;
250
  do_action( "groups_updated_capability", $result );
251
  }
lib/core/class-groups-group.php CHANGED
@@ -86,18 +86,18 @@ class Groups_Group implements I_Capable {
86
  }
87
  }
88
  break;
89
- case 'users' :
90
- $user_group_table = _groups_get_tablename( "user_group" );
91
- $users = $wpdb->get_results( $wpdb->prepare(
92
- "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",
93
- Groups_Utility::id( $this->group->group_id )
94
- ) );
95
- if ( $users ) {
96
- $result = array();
97
- foreach( $users as $user ) {
98
- $result[] = new Groups_User( $user->ID );
99
- }
100
- }
101
  break;
102
  }
103
  }
86
  }
87
  }
88
  break;
89
+ case 'users' :
90
+ $user_group_table = _groups_get_tablename( "user_group" );
91
+ $users = $wpdb->get_results( $wpdb->prepare(
92
+ "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",
93
+ Groups_Utility::id( $this->group->group_id )
94
+ ) );
95
+ if ( $users ) {
96
+ $result = array();
97
+ foreach( $users as $user ) {
98
+ $result[] = new Groups_User( $user->ID );
99
+ }
100
+ }
101
  break;
102
  }
103
  }
lib/core/class-groups-user-capability.php CHANGED
@@ -190,18 +190,18 @@ class Groups_User_Capability {
190
  * @param int $capability_id
191
  */
192
  public static function groups_deleted_capability( $capability_id ) {
193
- global $wpdb;
194
-
195
- $user_capability_table = _groups_get_tablename( "user_capability" );
196
- $rows = $wpdb->get_results( $wpdb->prepare(
197
- "SELECT * FROM $user_capability_table WHERE capability_id = %d",
198
- Groups_Utility::id( $capability_id )
199
- ) );
200
- if ( $rows ) {
201
- foreach( $rows as $row ) {
202
- // do NOT 'optimize' (must trigger actions ... same as above)
203
- self::delete( $row->user_id, $row->capability_id );
204
- }
205
  }
206
  }
207
  }
190
  * @param int $capability_id
191
  */
192
  public static function groups_deleted_capability( $capability_id ) {
193
+ global $wpdb;
194
+
195
+ $user_capability_table = _groups_get_tablename( "user_capability" );
196
+ $rows = $wpdb->get_results( $wpdb->prepare(
197
+ "SELECT * FROM $user_capability_table WHERE capability_id = %d",
198
+ Groups_Utility::id( $capability_id )
199
+ ) );
200
+ if ( $rows ) {
201
+ foreach( $rows as $row ) {
202
+ // do NOT 'optimize' (must trigger actions ... same as above)
203
+ self::delete( $row->user_id, $row->capability_id );
204
+ }
205
  }
206
  }
207
  }
lib/core/class-groups-user.php CHANGED
@@ -181,14 +181,14 @@ class Groups_User implements I_Capable {
181
  }
182
  break;
183
 
184
- case 'capabilities_deep' :
185
- if ( $this->user !== null ) {
186
- $capabilities = wp_cache_get( self::CAPABILITIES . $this->user->ID, self::CACHE_GROUP );
187
- if ( $capabilities === false ) {
188
- $this->init_cache( $capability_ids, $capabilities );
189
- }
190
- $result = $capabilities;
191
- }
192
  break;
193
 
194
  case "groups" :
@@ -232,16 +232,16 @@ class Groups_User implements I_Capable {
232
  $capability_id = null;
233
  if ( is_numeric( $capability ) ) {
234
  $capability_id = Groups_Utility::id( $capability );
235
- $capability_ids = wp_cache_get( self::CAPABILITY_IDS . $this->user->ID, self::CACHE_GROUP );
236
- if ( $capability_ids === false ) {
237
- $this->init_cache( $capability_ids );
238
- }
239
  $result = in_array( $capability_id, $capability_ids );
240
  } else if ( is_string( $capability ) ) {
241
- $capabilities = wp_cache_get( self::CAPABILITIES . $this->user->ID, self::CACHE_GROUP );
242
- if ( $capabilities === false ) {
243
- $this->init_cache( $capability_ids, $capabilities );
244
- }
245
  $result = in_array( $capability, $capabilities );
246
  }
247
  }
@@ -322,7 +322,7 @@ class Groups_User implements I_Capable {
322
  }
323
  }
324
 
325
- // Get all groups the user belongs to directly or through
326
  // inheritance along with their capabilities.
327
  if ( $user_groups ) {
328
  foreach( $user_groups as $user_group ) {
@@ -362,8 +362,8 @@ class Groups_User implements I_Capable {
362
 
363
  }
364
  }
365
- wp_cache_set( self::CAPABILITIES . $this->user->ID, $capabilities, self::CACHE_GROUP );
366
- wp_cache_set( self::CAPABILITY_IDS . $this->user->ID, $capability_ids, self::CACHE_GROUP );
367
  wp_cache_set( self::GROUP_IDS . $this->user->ID, $group_ids, self::CACHE_GROUP );
368
  }
369
  }
181
  }
182
  break;
183
 
184
+ case 'capabilities_deep' :
185
+ if ( $this->user !== null ) {
186
+ $capabilities = wp_cache_get( self::CAPABILITIES . $this->user->ID, self::CACHE_GROUP );
187
+ if ( $capabilities === false ) {
188
+ $this->init_cache( $capability_ids, $capabilities );
189
+ }
190
+ $result = $capabilities;
191
+ }
192
  break;
193
 
194
  case "groups" :
232
  $capability_id = null;
233
  if ( is_numeric( $capability ) ) {
234
  $capability_id = Groups_Utility::id( $capability );
235
+ $capability_ids = wp_cache_get( self::CAPABILITY_IDS . $this->user->ID, self::CACHE_GROUP );
236
+ if ( $capability_ids === false ) {
237
+ $this->init_cache( $capability_ids );
238
+ }
239
  $result = in_array( $capability_id, $capability_ids );
240
  } else if ( is_string( $capability ) ) {
241
+ $capabilities = wp_cache_get( self::CAPABILITIES . $this->user->ID, self::CACHE_GROUP );
242
+ if ( $capabilities === false ) {
243
+ $this->init_cache( $capability_ids, $capabilities );
244
+ }
245
  $result = in_array( $capability, $capabilities );
246
  }
247
  }
322
  }
323
  }
324
 
325
+ // Get all groups the user belongs to directly or through
326
  // inheritance along with their capabilities.
327
  if ( $user_groups ) {
328
  foreach( $user_groups as $user_group ) {
362
 
363
  }
364
  }
365
+ wp_cache_set( self::CAPABILITIES . $this->user->ID, $capabilities, self::CACHE_GROUP );
366
+ wp_cache_set( self::CAPABILITY_IDS . $this->user->ID, $capability_ids, self::CACHE_GROUP );
367
  wp_cache_set( self::GROUP_IDS . $this->user->ID, $group_ids, self::CACHE_GROUP );
368
  }
369
  }
lib/views/class-groups-shortcodes.php CHANGED
@@ -98,16 +98,16 @@ class Groups_Shortcodes {
98
  break;
99
  // @todo experimental - could use pagination, sorting, link to profile, ...
100
  case 'users' :
101
- $user_group_table = _groups_get_tablename( "user_group" );
102
- $users = $wpdb->get_results( $wpdb->prepare(
103
- "SELECT * FROM $wpdb->users LEFT JOIN $user_group_table ON $wpdb->users.ID = $user_group_table.user_id WHERE $user_group_table.group_id = %d",
104
- Groups_Utility::id( $current_group->group_id )
105
  ) );
106
  if ( $users ) {
107
  $output .= '<ul>';
108
  foreach( $users as $user ) {
109
  $output .= '<li>' . wp_filter_nohtml_kses( $user->user_login ) . '</li>';
110
- }
111
  $output .= '</ul>';
112
  }
113
 
@@ -142,7 +142,9 @@ class Groups_Shortcodes {
142
  'list_class' => 'groups',
143
  'item_class' => 'name',
144
  'order_by' => 'name',
145
- 'order' => 'ASC'
 
 
146
  ),
147
  $atts
148
  );
@@ -166,7 +168,46 @@ class Groups_Shortcodes {
166
  if ( $user_id !== null ) {
167
  $user = new Groups_User( $user_id );
168
  $groups = $user->groups;
 
169
  if ( !empty( $groups ) ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
  switch( $options['order_by'] ) {
171
  case 'group_id' :
172
  usort( $groups, array( __CLASS__, 'sort_id' ) );
@@ -337,41 +378,41 @@ class Groups_Shortcodes {
337
  */
338
  public static function groups_join( $atts, $content = null ) {
339
  $nonce_action = 'groups_action';
340
- $nonce = 'nonce_join';
341
  $output = "";
342
-
343
- $options = shortcode_atts(
344
- array(
345
  'group' => '',
346
  'display_message' => true,
347
  'display_is_member' => false,
348
- 'submit_text' => __( 'Join the %s group', GROUPS_PLUGIN_DOMAIN )
349
- ),
350
- $atts
351
  );
352
  extract( $options );
353
 
354
  if ( $display_message === 'false' ) {
355
  $display_message = false;
356
  }
357
- if ( $display_is_member === 'true' ) {
358
- $display_is_member = true;
359
  }
360
 
361
- $group = trim( $options['group'] );
362
- $current_group = Groups_Group::read( $group );
363
- if ( !$current_group ) {
364
- $current_group = Groups_Group::read_by_name( $group );
365
- }
366
  if ( $current_group ) {
367
  if ( $user_id = get_current_user_id() ) {
368
  $submitted = false;
369
- $invalid_nonce = false;
370
  if ( !empty( $_POST['groups_action'] ) && $_POST['groups_action'] == 'join' ) {
371
- $submitted = true;
372
- if ( !wp_verify_nonce( $_POST[$nonce], $nonce_action ) ) {
373
- $invalid_nonce = true;
374
- }
375
  }
376
  if ( $submitted && !$invalid_nonce ) {
377
  // add user to group
@@ -402,8 +443,8 @@ class Groups_Shortcodes {
402
  $output .= '</div>';
403
  }
404
  else if ( $display_is_member && isset( $current_group ) && $current_group !== false ) {
405
- $output .= '<div class="groups-join member">';
406
- $output .= sprintf( __( 'You are a member of the %s group.', GROUPS_PLUGIN_DOMAIN ), wp_filter_nohtml_kses( $current_group->name ) );
407
  $output .= '</div>';
408
  }
409
  }
@@ -412,75 +453,75 @@ class Groups_Shortcodes {
412
  return $output;
413
  }
414
 
415
- /**
416
- * Renders a form that lets a user leave a group.
417
- * * Attributes:
418
- * - "group" : (required) group name or id
419
- *
420
- * @param array $atts attributes
421
- * @param string $content not used
422
- */
423
- public static function groups_leave( $atts, $content = null ) {
424
- $nonce_action = 'groups_action';
425
- $nonce = 'nonce_leave';
426
- $output = "";
427
-
428
- $options = shortcode_atts(
429
- array(
430
- 'group' => '',
431
  'display_message' => true,
432
- 'submit_text' => __( 'Leave the %s group', GROUPS_PLUGIN_DOMAIN ),
433
- ),
434
- $atts
435
  );
436
  extract( $options );
437
 
438
- if ( $display_message === 'false' ) {
439
- $display_message = false;
440
- }
441
-
442
- $group = trim( $options['group'] );
443
- $current_group = Groups_Group::read( $group );
444
- if ( !$current_group ) {
445
- $current_group = Groups_Group::read_by_name( $group );
446
- }
447
- if ( $current_group ) {
448
- if ( $user_id = get_current_user_id() ) {
449
- $submitted = false;
450
- $invalid_nonce = false;
451
- if ( !empty( $_POST['groups_action'] ) && $_POST['groups_action'] == 'leave' ) {
452
- $submitted = true;
453
- if ( !wp_verify_nonce( $_POST[$nonce], $nonce_action ) ) {
454
- $invalid_nonce = true;
455
- }
456
- }
457
- if ( $submitted && !$invalid_nonce ) {
458
- // remove user from group
459
- if ( isset( $_POST['group_id'] ) ) {
460
- $leave_group = Groups_Group::read( $_POST['group_id'] );
461
- Groups_User_Group::delete( $user_id, $leave_group->group_id );
462
- }
463
- }
464
  if ( Groups_User_Group::read( $user_id, $current_group->group_id ) ) {
465
- $submit_text = sprintf( $options['submit_text'], wp_filter_nohtml_kses( $current_group->name ) );
466
- $output .= '<div class="groups-join">';
467
- $output .= '<form action="#" method="post">';
468
- $output .= '<input type="hidden" name="groups_action" value="leave" />';
469
- $output .= '<input type="hidden" name="group_id" value="' . esc_attr( $current_group->group_id ) . '" />';
470
- $output .= '<input type="submit" value="' . $submit_text . '" />';
471
- $output .= wp_nonce_field( $nonce_action, $nonce, true, false );
472
- $output .= '</form>';
473
- $output .= '</div>';
474
- } else if ( $display_message ) {
475
- if ( $submitted && !$invalid_nonce && isset( $leave_group ) && $leave_group->group_id === $current_group->group_id ) {
476
- $output .= '<div class="groups-join left">';
477
- $output .= sprintf( __( 'You have left the %s group.', GROUPS_PLUGIN_DOMAIN ), wp_filter_nohtml_kses( $leave_group->name ) );
478
- $output .= '</div>';
479
- }
480
- }
481
- }
482
- }
483
- return $output;
484
  }
485
  }
486
  Groups_Shortcodes::init();
98
  break;
99
  // @todo experimental - could use pagination, sorting, link to profile, ...
100
  case 'users' :
101
+ $user_group_table = _groups_get_tablename( "user_group" );
102
+ $users = $wpdb->get_results( $wpdb->prepare(
103
+ "SELECT * FROM $wpdb->users LEFT JOIN $user_group_table ON $wpdb->users.ID = $user_group_table.user_id WHERE $user_group_table.group_id = %d",
104
+ Groups_Utility::id( $current_group->group_id )
105
  ) );
106
  if ( $users ) {
107
  $output .= '<ul>';
108
  foreach( $users as $user ) {
109
  $output .= '<li>' . wp_filter_nohtml_kses( $user->user_login ) . '</li>';
110
+ }
111
  $output .= '</ul>';
112
  }
113
 
142
  'list_class' => 'groups',
143
  'item_class' => 'name',
144
  'order_by' => 'name',
145
+ 'order' => 'ASC',
146
+ 'group' => null,
147
+ 'exclude_group' => null
148
  ),
149
  $atts
150
  );
168
  if ( $user_id !== null ) {
169
  $user = new Groups_User( $user_id );
170
  $groups = $user->groups;
171
+
172
  if ( !empty( $groups ) ) {
173
+ // group attr
174
+ if ( $options['group'] !== null ) {
175
+ $groups = array();
176
+ $groups_incl = explode( ",", $options['group'] );
177
+ foreach ( $groups_incl as $group_incl ) {
178
+ $group = trim( $group_incl );
179
+ $current_group = Groups_Group::read( $group );
180
+ if ( !$current_group ) {
181
+ $current_group = Groups_Group::read_by_name( $group );
182
+ }
183
+ if ( $current_group ) {
184
+ if ( Groups_User_Group::read( $user_id, $current_group->group_id ) ) {
185
+ $groups[] = $current_group;
186
+ }
187
+ }
188
+ }
189
+ }
190
+ // exclude_group attr
191
+ if ( $options['exclude_group'] !== null ) {
192
+ $groups_excl = explode( ",", $options['exclude_group'] );
193
+ foreach ( $groups_excl as $key => $group_excl ) {
194
+ $group = trim( $group_excl );
195
+ $current_group = Groups_Group::read( $group );
196
+ if ( !$current_group ) {
197
+ $current_group = Groups_Group::read_by_name( $group );
198
+ }
199
+ if ( $current_group ) {
200
+ $groups_excl[$key] = $current_group->group_id;
201
+ } else {
202
+ unset( $groups_excl[$key] );
203
+ }
204
+ }
205
+ foreach ( $groups as $key => $group ) {
206
+ if ( in_array( $group->group_id, $groups_excl ) ) {
207
+ unset( $groups[$key] );
208
+ }
209
+ }
210
+ }
211
  switch( $options['order_by'] ) {
212
  case 'group_id' :
213
  usort( $groups, array( __CLASS__, 'sort_id' ) );
378
  */
379
  public static function groups_join( $atts, $content = null ) {
380
  $nonce_action = 'groups_action';
381
+ $nonce = 'nonce_join';
382
  $output = "";
383
+
384
+ $options = shortcode_atts(
385
+ array(
386
  'group' => '',
387
  'display_message' => true,
388
  'display_is_member' => false,
389
+ 'submit_text' => __( 'Join the %s group', GROUPS_PLUGIN_DOMAIN )
390
+ ),
391
+ $atts
392
  );
393
  extract( $options );
394
 
395
  if ( $display_message === 'false' ) {
396
  $display_message = false;
397
  }
398
+ if ( $display_is_member === 'true' ) {
399
+ $display_is_member = true;
400
  }
401
 
402
+ $group = trim( $options['group'] );
403
+ $current_group = Groups_Group::read( $group );
404
+ if ( !$current_group ) {
405
+ $current_group = Groups_Group::read_by_name( $group );
406
+ }
407
  if ( $current_group ) {
408
  if ( $user_id = get_current_user_id() ) {
409
  $submitted = false;
410
+ $invalid_nonce = false;
411
  if ( !empty( $_POST['groups_action'] ) && $_POST['groups_action'] == 'join' ) {
412
+ $submitted = true;
413
+ if ( !wp_verify_nonce( $_POST[$nonce], $nonce_action ) ) {
414
+ $invalid_nonce = true;
415
+ }
416
  }
417
  if ( $submitted && !$invalid_nonce ) {
418
  // add user to group
443
  $output .= '</div>';
444
  }
445
  else if ( $display_is_member && isset( $current_group ) && $current_group !== false ) {
446
+ $output .= '<div class="groups-join member">';
447
+ $output .= sprintf( __( 'You are a member of the %s group.', GROUPS_PLUGIN_DOMAIN ), wp_filter_nohtml_kses( $current_group->name ) );
448
  $output .= '</div>';
449
  }
450
  }
453
  return $output;
454
  }
455
 
456
+ /**
457
+ * Renders a form that lets a user leave a group.
458
+ * * Attributes:
459
+ * - "group" : (required) group name or id
460
+ *
461
+ * @param array $atts attributes
462
+ * @param string $content not used
463
+ */
464
+ public static function groups_leave( $atts, $content = null ) {
465
+ $nonce_action = 'groups_action';
466
+ $nonce = 'nonce_leave';
467
+ $output = "";
468
+
469
+ $options = shortcode_atts(
470
+ array(
471
+ 'group' => '',
472
  'display_message' => true,
473
+ 'submit_text' => __( 'Leave the %s group', GROUPS_PLUGIN_DOMAIN ),
474
+ ),
475
+ $atts
476
  );
477
  extract( $options );
478
 
479
+ if ( $display_message === 'false' ) {
480
+ $display_message = false;
481
+ }
482
+
483
+ $group = trim( $options['group'] );
484
+ $current_group = Groups_Group::read( $group );
485
+ if ( !$current_group ) {
486
+ $current_group = Groups_Group::read_by_name( $group );
487
+ }
488
+ if ( $current_group ) {
489
+ if ( $user_id = get_current_user_id() ) {
490
+ $submitted = false;
491
+ $invalid_nonce = false;
492
+ if ( !empty( $_POST['groups_action'] ) && $_POST['groups_action'] == 'leave' ) {
493
+ $submitted = true;
494
+ if ( !wp_verify_nonce( $_POST[$nonce], $nonce_action ) ) {
495
+ $invalid_nonce = true;
496
+ }
497
+ }
498
+ if ( $submitted && !$invalid_nonce ) {
499
+ // remove user from group
500
+ if ( isset( $_POST['group_id'] ) ) {
501
+ $leave_group = Groups_Group::read( $_POST['group_id'] );
502
+ Groups_User_Group::delete( $user_id, $leave_group->group_id );
503
+ }
504
+ }
505
  if ( Groups_User_Group::read( $user_id, $current_group->group_id ) ) {
506
+ $submit_text = sprintf( $options['submit_text'], wp_filter_nohtml_kses( $current_group->name ) );
507
+ $output .= '<div class="groups-join">';
508
+ $output .= '<form action="#" method="post">';
509
+ $output .= '<input type="hidden" name="groups_action" value="leave" />';
510
+ $output .= '<input type="hidden" name="group_id" value="' . esc_attr( $current_group->group_id ) . '" />';
511
+ $output .= '<input type="submit" value="' . $submit_text . '" />';
512
+ $output .= wp_nonce_field( $nonce_action, $nonce, true, false );
513
+ $output .= '</form>';
514
+ $output .= '</div>';
515
+ } else if ( $display_message ) {
516
+ if ( $submitted && !$invalid_nonce && isset( $leave_group ) && $leave_group->group_id === $current_group->group_id ) {
517
+ $output .= '<div class="groups-join left">';
518
+ $output .= sprintf( __( 'You have left the %s group.', GROUPS_PLUGIN_DOMAIN ), wp_filter_nohtml_kses( $leave_group->name ) );
519
+ $output .= '</div>';
520
+ }
521
+ }
522
+ }
523
+ }
524
+ return $output;
525
  }
526
  }
527
  Groups_Shortcodes::init();
lib/wp/class-groups-wordpress.php CHANGED
@@ -101,30 +101,30 @@ class Groups_WordPress {
101
  * @return int number of capabilities added
102
  */
103
  public static function refresh_capabilities() {
104
- global $wp_roles;
105
- $capabilities = array();
106
- $count = 0;
107
- if ( !isset( $wp_roles ) ) {
108
- // just trigger initialization
109
- get_role( 'administrator' );
110
- }
111
- $roles = $wp_roles->roles;
112
- if ( is_array( $roles ) ) {
113
- foreach ( $roles as $rolename => $atts ) {
114
- if ( isset( $atts['capabilities'] ) && is_array( $atts['capabilities'] ) ) {
115
- foreach ( $atts['capabilities'] as $capability => $value ) {
116
- if ( !in_array( $capability, $capabilities ) ) {
117
- $capabilities[] = $capability;
118
- }
119
- }
120
- }
121
- }
122
- }
123
- foreach ( $capabilities as $capability ) {
124
- if ( !Groups_Capability::read_by_capability( $capability ) ) {
125
  Groups_Capability::create( array( 'capability' => $capability ) );
126
- $count++;
127
- }
128
  }
129
  return $count;
130
  }
101
  * @return int number of capabilities added
102
  */
103
  public static function refresh_capabilities() {
104
+ global $wp_roles;
105
+ $capabilities = array();
106
+ $count = 0;
107
+ if ( !isset( $wp_roles ) ) {
108
+ // just trigger initialization
109
+ get_role( 'administrator' );
110
+ }
111
+ $roles = $wp_roles->roles;
112
+ if ( is_array( $roles ) ) {
113
+ foreach ( $roles as $rolename => $atts ) {
114
+ if ( isset( $atts['capabilities'] ) && is_array( $atts['capabilities'] ) ) {
115
+ foreach ( $atts['capabilities'] as $capability => $value ) {
116
+ if ( !in_array( $capability, $capabilities ) ) {
117
+ $capabilities[] = $capability;
118
+ }
119
+ }
120
+ }
121
+ }
122
+ }
123
+ foreach ( $capabilities as $capability ) {
124
+ if ( !Groups_Capability::read_by_capability( $capability ) ) {
125
  Groups_Capability::create( array( 'capability' => $capability ) );
126
+ $count++;
127
+ }
128
  }
129
  return $count;
130
  }
readme.txt CHANGED
@@ -4,7 +4,7 @@ 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.5
6
  Tested up to: 3.8.1
7
- Stable tag: 1.4.7
8
  License: GPLv3
9
 
10
  Groups is an efficient and powerful solution, providing group-based user membership management, group-based capabilities and content access control.
@@ -177,6 +177,20 @@ See also [Groups](http://www.itthinx.com/plugins/groups/)
177
 
178
  == Changelog ==
179
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
180
  = 1.4.7 =
181
  * Security improvement: plugin files accessed directly exit
182
 
@@ -373,6 +387,9 @@ Some installations wouldn't work correctly, showing no capabilities and making i
373
 
374
  == Upgrade Notice ==
375
 
 
 
 
376
  = 1.4.7 =
377
  * This update provides a low-priority security improvement and a fix related to output obtained through the_content and get_the_excerpt filters.
378
 
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.5
6
  Tested up to: 3.8.1
7
+ Stable tag: 1.4.8
8
  License: GPLv3
9
 
10
  Groups is an efficient and powerful solution, providing group-based user membership management, group-based capabilities and content access control.
177
 
178
  == Changelog ==
179
 
180
+ = 1.4.8 =
181
+ * Fixed: A closing tag in the group list on the user profile.
182
+ * Fixed: Help wording.
183
+ * Improved: Capabilities in the Access Restrictions column are sorted for more consistent display.
184
+ * Improved: Reduced ID, Edit and Remove column widths on Groups and Capabilities screens.
185
+ * Fixed: Stripping added slashes from groups and capabilities displayed.
186
+ * Added: Feedback when groups and capabilities are created, updated or removed in admin.
187
+ * Added: group and exclude_group attributes for the [groups_user_groups] shortcode.
188
+ * Improved: Replaced remnant CR LF line-endings in code.
189
+ * Fixed: Handling updates to a capability when the capability field is empty.
190
+ * Fixed: Handling updates to a group when the name field is empty.
191
+ * Fixed: Don't allow to use the name of another existing group when updating a group.
192
+ * Fixed: Don't allow to use the name of another existing capability when updating one.
193
+
194
  = 1.4.7 =
195
  * Security improvement: plugin files accessed directly exit
196
 
387
 
388
  == Upgrade Notice ==
389
 
390
+ = 1.4.8 =
391
+ * Several minor fixes and giving more feedback on the admin side for groups and capabilities.
392
+
393
  = 1.4.7 =
394
  * This update provides a low-priority security improvement and a fix related to output obtained through the_content and get_the_excerpt filters.
395