Groups - Version 1.3.13

Version Description

  • Fixed duplicate postmeta creaed when saving access restriction capabilities for a post.
  • [groups_can] and [groups_can_not] now accept multiple capabilities separated by comma.
  • WordPress 3.6.1 compatibility checked.
Download this release

Release Info

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

Code changes from version 1.3.12 to 1.3.13

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.12
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.12' );
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.13
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.13' );
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-shortcodes.php CHANGED
@@ -115,8 +115,9 @@ class Groups_Access_Shortcodes {
115
  }
116
 
117
  /**
118
- * Takes one attribute "capability" that must be a valid capability label.
119
- * The content is shown if the current user has the capability.
 
120
  *
121
  * @param array $atts attributes
122
  * @param string $content content to render
@@ -127,7 +128,15 @@ class Groups_Access_Shortcodes {
127
  if ( $content !== null ) {
128
  $groups_user = new Groups_User( get_current_user_id() );
129
  $capability = $options['capability'];
130
- if ( $groups_user->can( $capability ) ) {
 
 
 
 
 
 
 
 
131
  remove_shortcode( 'groups_can' );
132
  $content = do_shortcode( $content );
133
  add_shortcode( 'groups_can', array( __CLASS__, 'groups_can' ) );
@@ -138,8 +147,9 @@ class Groups_Access_Shortcodes {
138
  }
139
 
140
  /**
141
- * Takes one attribute "capability" that must be a valid capability label.
142
- * The content is shown if the current user does NOT have the capability.
 
143
  *
144
  * @param array $atts attributes
145
  * @param string $content content to render
@@ -150,7 +160,15 @@ class Groups_Access_Shortcodes {
150
  if ( $content !== null ) {
151
  $groups_user = new Groups_User( get_current_user_id() );
152
  $capability = $options['capability'];
153
- if ( !$groups_user->can( $capability ) ) {
 
 
 
 
 
 
 
 
154
  remove_shortcode( 'groups_can_not' );
155
  $content = do_shortcode( $content );
156
  add_shortcode( 'groups_can_not', array( __CLASS__, 'groups_can_not' ) );
115
  }
116
 
117
  /**
118
+ * Takes one attribute "capability" that must be a valid capability label
119
+ * or a list of capabilities separated by comma.
120
+ * The content is shown if the current user has one of the capabilities.
121
  *
122
  * @param array $atts attributes
123
  * @param string $content content to render
128
  if ( $content !== null ) {
129
  $groups_user = new Groups_User( get_current_user_id() );
130
  $capability = $options['capability'];
131
+ $capabilities = array_map( 'trim', explode( ',', $capability ) );
132
+ $show_content = false;
133
+ foreach( $capabilities as $capability ) {
134
+ if ( $groups_user->can( $capability ) ) {
135
+ $show_content = true;
136
+ break;
137
+ }
138
+ }
139
+ if ( $show_content ) {
140
  remove_shortcode( 'groups_can' );
141
  $content = do_shortcode( $content );
142
  add_shortcode( 'groups_can', array( __CLASS__, 'groups_can' ) );
147
  }
148
 
149
  /**
150
+ * Takes one attribute "capability" that must be a valid capability label,
151
+ * or a comma-separaed list of those.
152
+ * The content is shown if the current user has none of the capabilities.
153
  *
154
  * @param array $atts attributes
155
  * @param string $content content to render
160
  if ( $content !== null ) {
161
  $groups_user = new Groups_User( get_current_user_id() );
162
  $capability = $options['capability'];
163
+ $capabilities = array_map( 'trim', explode( ',', $capability ) );
164
+ $show_content = true;
165
+ foreach( $capabilities as $capability ) {
166
+ if ( $groups_user->can( $capability ) ) {
167
+ $show_content = false;
168
+ break;
169
+ }
170
+ }
171
+ if ( $show_content ) {
172
  remove_shortcode( 'groups_can_not' );
173
  $content = do_shortcode( $content );
174
  add_shortcode( 'groups_can_not', array( __CLASS__, 'groups_can_not' ) );
lib/access/class-groups-post-access.php CHANGED
@@ -255,11 +255,18 @@ class Groups_Post_Access {
255
  /**
256
  * Adds an access capability requirement.
257
  *
258
- * $map must contain 'post_id'
259
  *
260
  * For now this only should be used to add the READ_POST_CAPABILITY which
261
  * it does automatically. Nothing else is checked for granting access.
262
  *
 
 
 
 
 
 
 
263
  * @param array $map
264
  * @return true if the capability could be added to the post, otherwis false
265
  */
@@ -273,6 +280,9 @@ class Groups_Post_Access {
273
 
274
  if ( !empty( $post_id ) && !empty( $capability) ) {
275
  if ( Groups_Capability::read_by_capability( $capability ) ) {
 
 
 
276
  if ( !in_array( $capability, get_post_meta( $post_id, self::POSTMETA_PREFIX . self::READ_POST_CAPABILITY ) ) ) {
277
  $result = add_post_meta( $post_id, self::POSTMETA_PREFIX . self::READ_POST_CAPABILITY, $capability );
278
  }
255
  /**
256
  * Adds an access capability requirement.
257
  *
258
+ * $map must contain 'post_id' (*)
259
  *
260
  * For now this only should be used to add the READ_POST_CAPABILITY which
261
  * it does automatically. Nothing else is checked for granting access.
262
  *
263
+ * (*) Revisions : As of Groups 1.3.13 and at WordPress 3.6.1, as
264
+ * add_post_meta stores postmeta for the revision's parent, we retrieve
265
+ * the parent's post ID if it applies and check against that to see if
266
+ * that capability is already present. This is to avoid duplicating
267
+ * the already existing postmeta entry (which ocurred in previous
268
+ * versions).
269
+ *
270
  * @param array $map
271
  * @return true if the capability could be added to the post, otherwis false
272
  */
280
 
281
  if ( !empty( $post_id ) && !empty( $capability) ) {
282
  if ( Groups_Capability::read_by_capability( $capability ) ) {
283
+ if ( $revision_parent_id = wp_is_post_revision( $post_id ) ) {
284
+ $post_id = $revision_parent_id;
285
+ }
286
  if ( !in_array( $capability, get_post_meta( $post_id, self::POSTMETA_PREFIX . self::READ_POST_CAPABILITY ) ) ) {
287
  $result = add_post_meta( $post_id, self::POSTMETA_PREFIX . self::READ_POST_CAPABILITY, $capability );
288
  }
readme.txt CHANGED
@@ -3,8 +3,8 @@ 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.6
7
- Stable tag: 1.3.12
8
  License: GPLv3
9
 
10
  Groups provides group-based user membership management, group-based capabilities and content access control.
@@ -360,6 +360,11 @@ See also [Groups](http://www.itthinx.com/plugins/groups/)
360
 
361
  == Changelog ==
362
 
 
 
 
 
 
363
  = 1.3.12 =
364
  * WordPress 3.6 compatibility checked.
365
  * Fixed table appearance for capabilities and groups admin sections when there are no results.
@@ -497,6 +502,9 @@ Some installations wouldn't work correctly, showing no capabilities and making i
497
 
498
  == Upgrade Notice ==
499
 
 
 
 
500
  = 1.3.12 =
501
  * WordPress 3.6 compatibility checked and minor fixes.
502
 
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.6.1
7
+ Stable tag: 1.3.13
8
  License: GPLv3
9
 
10
  Groups provides group-based user membership management, group-based capabilities and content access control.
360
 
361
  == Changelog ==
362
 
363
+ = 1.3.13 =
364
+ * Fixed duplicate postmeta creaed when saving access restriction capabilities for a post.
365
+ * [groups_can] and [groups_can_not] now accept multiple capabilities separated by comma.
366
+ * WordPress 3.6.1 compatibility checked.
367
+
368
  = 1.3.12 =
369
  * WordPress 3.6 compatibility checked.
370
  * Fixed table appearance for capabilities and groups admin sections when there are no results.
502
 
503
  == Upgrade Notice ==
504
 
505
+ = 1.3.13 =
506
+ * Minor fixes (also tested WordPress 3.6.1 compatibility).
507
+
508
  = 1.3.12 =
509
  * WordPress 3.6 compatibility checked and minor fixes.
510