Groups - Version 1.3.0

Version Description

  • Added feature that allows to show access restrictions depending on post type
  • Added support for access restrictions on Media
  • Fixed issue, removed access restrictions offered on Links
Download this release

Release Info

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

Code changes from version 1.2.5 to 1.3.0

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.2.5
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.2.5' );
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.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' );
lib/access/class-groups-access-meta-boxes.php CHANGED
@@ -35,36 +35,45 @@ class Groups_Access_Meta_Boxes {
35
  * Hooks for capabilities meta box and saving options.
36
  */
37
  public static function init() {
38
- add_action( 'add_meta_boxes', array( __CLASS__, "add_meta_boxes" ) );
39
  add_action( 'save_post', array( __CLASS__, "save_post" ) );
 
 
 
40
  }
41
-
42
  /**
43
  * Triggered by init() to add capability meta box.
44
  */
45
- public static function add_meta_boxes() {
46
  global $wp_version;
47
- if ( $wp_version < 3.3 ) {
48
- $post_types = get_post_types();
49
- foreach ( $post_types as $post_type ) {
50
- add_meta_box(
51
- "groups-access",
52
- __( "Access restrictions", GROUPS_PLUGIN_DOMAIN ),
53
- array( __CLASS__, "capability" ),
54
- $post_type,
55
- "side",
56
- "high"
57
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  }
59
- } else {
60
- add_meta_box(
61
- "groups-access",
62
- __( "Access restrictions", GROUPS_PLUGIN_DOMAIN ),
63
- array( __CLASS__, "capability" ),
64
- null,
65
- "side",
66
- "high"
67
- );
68
  }
69
  }
70
 
@@ -78,8 +87,6 @@ class Groups_Access_Meta_Boxes {
78
  */
79
  public static function capability( $object = null, $box = null ) {
80
 
81
- global $wpdb;
82
-
83
  $output = "";
84
 
85
  $post_id = isset( $object->ID ) ? $object->ID : null;
@@ -118,6 +125,7 @@ class Groups_Access_Meta_Boxes {
118
  $output .= sprintf( __( "Only groups or users that have one of the selected capabilities are allowed to read this %s.", GROUPS_PLUGIN_DOMAIN ), $post_singular_name );
119
  $output .= '</p>';
120
  $output .= wp_nonce_field( self::SET_CAPABILITY, self::NONCE, true, false );
 
121
  echo $output;
122
  }
123
 
@@ -130,18 +138,25 @@ class Groups_Access_Meta_Boxes {
130
  public static function save_post( $post_id = null, $post = null ) {
131
  if ( ( defined( "DOING_AUTOSAVE" ) && DOING_AUTOSAVE ) ) {
132
  } else {
133
- if ( isset( $_POST[self::NONCE] ) && wp_verify_nonce( $_POST[self::NONCE], self::SET_CAPABILITY ) ) {
134
- $post_type = isset( $_POST["post_type"] ) ? $_POST["post_type"] : null;
135
- if ( $post_type !== null ) {
136
- if ( current_user_can( 'edit_'.$post_type ) ) {
137
- Groups_Post_Access::delete( $post_id, null );
138
- if ( !empty( $_POST[self::CAPABILITY] ) ) {
139
- foreach ( $_POST[self::CAPABILITY] as $capability_id ) {
140
- if ( $capability = Groups_Capability::read( $capability_id ) ) {
141
- Groups_Post_Access::create( array(
142
- 'post_id' => $post_id,
143
- 'capability' => $capability->capability
144
- ) );
 
 
 
 
 
 
 
145
  }
146
  }
147
  }
@@ -151,5 +166,78 @@ class Groups_Access_Meta_Boxes {
151
  }
152
  }
153
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
  }
155
  Groups_Access_Meta_Boxes::init();
35
  * Hooks for capabilities meta box and saving options.
36
  */
37
  public static function init() {
38
+ add_action( 'add_meta_boxes', array( __CLASS__, "add_meta_boxes" ), 10, 2 );
39
  add_action( 'save_post', array( __CLASS__, "save_post" ) );
40
+
41
+ add_action( 'attachment_fields_to_edit', array( __CLASS__, 'attachment_fields_to_edit' ), 10, 2 );
42
+ add_action( 'attachment_fields_to_save', array( __CLASS__, 'attachment_fields_to_save' ), 10, 2 );
43
  }
44
+
45
  /**
46
  * Triggered by init() to add capability meta box.
47
  */
48
+ public static function add_meta_boxes( $post_type, $post ) {
49
  global $wp_version;
50
+ $post_type_object = get_post_type_object( $post_type );
51
+ if ( $post_type_object ) {
52
+ $post_types_option = Groups_Options::get_option( Groups_Post_Access::POST_TYPES, array() );
53
+ if ( !isset( $post_types_option[$post_type]['add_meta_box'] ) || $post_types_option[$post_type]['add_meta_box'] ) {
54
+ if ( $wp_version < 3.3 ) {
55
+ $post_types = get_post_types();
56
+ foreach ( $post_types as $post_type ) {
57
+ add_meta_box(
58
+ "groups-access",
59
+ __( "Access restrictions", GROUPS_PLUGIN_DOMAIN ),
60
+ array( __CLASS__, "capability" ),
61
+ $post_type,
62
+ "side",
63
+ "high"
64
+ );
65
+ }
66
+ } else {
67
+ add_meta_box(
68
+ "groups-access",
69
+ __( "Access restrictions", GROUPS_PLUGIN_DOMAIN ),
70
+ array( __CLASS__, "capability" ),
71
+ null,
72
+ "side",
73
+ "high"
74
+ );
75
+ }
76
  }
 
 
 
 
 
 
 
 
 
77
  }
78
  }
79
 
87
  */
88
  public static function capability( $object = null, $box = null ) {
89
 
 
 
90
  $output = "";
91
 
92
  $post_id = isset( $object->ID ) ? $object->ID : null;
125
  $output .= sprintf( __( "Only groups or users that have one of the selected capabilities are allowed to read this %s.", GROUPS_PLUGIN_DOMAIN ), $post_singular_name );
126
  $output .= '</p>';
127
  $output .= wp_nonce_field( self::SET_CAPABILITY, self::NONCE, true, false );
128
+
129
  echo $output;
130
  }
131
 
138
  public static function save_post( $post_id = null, $post = null ) {
139
  if ( ( defined( "DOING_AUTOSAVE" ) && DOING_AUTOSAVE ) ) {
140
  } else {
141
+ $post_type = get_post_type( $post_id );
142
+ $post_type_object = get_post_type_object( $post_type );
143
+ if ( $post_type_object ) {
144
+ $post_types_option = Groups_Options::get_option( Groups_Post_Access::POST_TYPES, array() );
145
+ if ( !isset( $post_types_option[$post_type]['add_meta_box'] ) || $post_types_option[$post_type]['add_meta_box'] ) {
146
+ if ( isset( $_POST[self::NONCE] ) && wp_verify_nonce( $_POST[self::NONCE], self::SET_CAPABILITY ) ) {
147
+ $post_type = isset( $_POST["post_type"] ) ? $_POST["post_type"] : null;
148
+ if ( $post_type !== null ) {
149
+ if ( current_user_can( 'edit_'.$post_type ) ) {
150
+ Groups_Post_Access::delete( $post_id, null );
151
+ if ( !empty( $_POST[self::CAPABILITY] ) ) {
152
+ foreach ( $_POST[self::CAPABILITY] as $capability_id ) {
153
+ if ( $capability = Groups_Capability::read( $capability_id ) ) {
154
+ Groups_Post_Access::create( array(
155
+ 'post_id' => $post_id,
156
+ 'capability' => $capability->capability
157
+ ) );
158
+ }
159
+ }
160
  }
161
  }
162
  }
166
  }
167
  }
168
 
169
+ /**
170
+ * Render capabilities box for attachment post type (Media).
171
+ * @param array $form_fields
172
+ * @param object $post
173
+ * @return array
174
+ */
175
+ public static function attachment_fields_to_edit( $form_fields, $post ) {
176
+
177
+ $post_types_option = Groups_Options::get_option( Groups_Post_Access::POST_TYPES, array() );
178
+ if ( !isset( $post_types_option['attachment']['add_meta_box'] ) || $post_types_option['attachment']['add_meta_box'] ) {
179
+
180
+ $output = "";
181
+ $post_singular_name = __( 'Media', GROUPS_PLUGIN_DOMAIN );
182
+
183
+ $output .= __( "Enforce read access", GROUPS_PLUGIN_DOMAIN );
184
+ $read_caps = get_post_meta( $post->ID, Groups_Post_Access::POSTMETA_PREFIX . Groups_Post_Access::READ_POST_CAPABILITY );
185
+ $valid_read_caps = Groups_Options::get_option( Groups_Post_Access::READ_POST_CAPABILITIES, array( Groups_Post_Access::READ_POST_CAPABILITY ) );
186
+ $output .= '<div style="padding:0 1em;margin:1em 0;border:1px solid #ccc;border-radius:4px;">';
187
+ $output .= '<ul>';
188
+ foreach( $valid_read_caps as $valid_read_cap ) {
189
+ if ( $capability = Groups_Capability::read_by_capability( $valid_read_cap ) ) {
190
+ $checked = in_array( $capability->capability, $read_caps ) ? ' checked="checked" ' : '';
191
+ $output .= '<li>';
192
+ $output .= '<label>';
193
+ $output .= '<input name="attachments[' . $post->ID . '][' . self::CAPABILITY . '][]" ' . $checked . ' type="checkbox" value="' . esc_attr( $capability->capability_id ) . '" />';
194
+ $output .= wp_filter_nohtml_kses( $capability->capability );
195
+ $output .= '</label>';
196
+ $output .= '</li>';
197
+ }
198
+ }
199
+ $output .= '</ul>';
200
+ $output .= '</div>';
201
+
202
+ $output .= '<p class="description">';
203
+ $output .= sprintf( __( "Only groups or users that have one of the selected capabilities are allowed to read this %s.", GROUPS_PLUGIN_DOMAIN ), $post_singular_name );
204
+ $output .= '</p>';
205
+
206
+ $form_fields['groups_access'] = array(
207
+ 'label' => __( 'Access restrictions', GROUPS_PLUGIN_DOMAIN ),
208
+ 'input' => 'html',
209
+ 'html' => $output
210
+ );
211
+ }
212
+ return $form_fields;
213
+ }
214
+
215
+ /**
216
+ * Save capabilities for attachment post type (Media).
217
+ * When multiple attachments are saved, this is called once for each.
218
+ * @param array $post post data
219
+ * @param array $attachment attachment field data
220
+ * @return array
221
+ */
222
+ public static function attachment_fields_to_save( $post, $attachment ) {
223
+ $post_types_option = Groups_Options::get_option( Groups_Post_Access::POST_TYPES, array() );
224
+ if ( !isset( $post_types_option['attachment']['add_meta_box'] ) || $post_types_option['attachment']['add_meta_box'] ) {
225
+ if ( current_user_can( 'edit_attachment' ) ) {
226
+ Groups_Post_Access::delete( $post['ID'], null );
227
+ if ( !empty( $attachment[self::CAPABILITY] ) ) {
228
+ foreach ( $attachment[self::CAPABILITY] as $capability_id ) {
229
+ if ( $capability = Groups_Capability::read( $capability_id ) ) {
230
+ Groups_Post_Access::create( array(
231
+ 'post_id' => $post['ID'],
232
+ 'capability' => $capability->capability
233
+ ) );
234
+ }
235
+ }
236
+ }
237
+ }
238
+ }
239
+ return $post;
240
+ }
241
+
242
  }
243
  Groups_Access_Meta_Boxes::init();
lib/access/class-groups-post-access.php CHANGED
@@ -29,6 +29,7 @@ class Groups_Post_Access {
29
  const READ_POST_CAPABILITY = "groups_read_post";
30
  const READ_POST_CAPABILITY_NAME = "Read Post";
31
  const READ_POST_CAPABILITIES = 'read_post_capabilities';
 
32
 
33
  /**
34
  * Create needed capabilities on plugin activation.
29
  const READ_POST_CAPABILITY = "groups_read_post";
30
  const READ_POST_CAPABILITY_NAME = "Read Post";
31
  const READ_POST_CAPABILITIES = 'read_post_capabilities';
32
+ const POST_TYPES = 'post_types';
33
 
34
  /**
35
  * Create needed capabilities on plugin activation.
lib/admin/groups-admin-options.php CHANGED
@@ -73,6 +73,13 @@ function groups_admin_options() {
73
  add_option( GROUPS_ADMINISTRATOR_ACCESS_OVERRIDE, $admin_override ); // WP 3.3.1 : update alone wouldn't create the option when value is false
74
  update_option( GROUPS_ADMINISTRATOR_ACCESS_OVERRIDE, $admin_override );
75
 
 
 
 
 
 
 
 
76
  $valid_read_caps = array( Groups_Post_Access::READ_POST_CAPABILITY );
77
  if ( !empty( $_POST[GROUPS_READ_POST_CAPABILITIES] ) ) {
78
  $read_caps = $_POST[GROUPS_READ_POST_CAPABILITIES];
@@ -167,7 +174,12 @@ function groups_admin_options() {
167
  // print the options form
168
  //
169
  echo
170
- '<form action="" name="options" method="post">' .
 
 
 
 
 
171
  '<div>' .
172
  '<h3>' . __( 'Administrator Access Override', GROUPS_PLUGIN_DOMAIN ) . '</h3>' .
173
  '<p>' .
@@ -179,6 +191,39 @@ function groups_admin_options() {
179
 
180
  echo '<h3>' . __( 'Access restricions', GROUPS_PLUGIN_DOMAIN ) . '</h3>';
181
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182
  echo '<p class="description">' .
183
  __( 'Include these capabilities to enforce read access on posts. The selected capabilities will be offered to restrict access to posts.', GROUPS_PLUGIN_DOMAIN ) .
184
  '</p>';
73
  add_option( GROUPS_ADMINISTRATOR_ACCESS_OVERRIDE, $admin_override ); // WP 3.3.1 : update alone wouldn't create the option when value is false
74
  update_option( GROUPS_ADMINISTRATOR_ACCESS_OVERRIDE, $admin_override );
75
 
76
+ $post_types_option = Groups_Options::get_option( Groups_Post_Access::POST_TYPES, array() );
77
+ $post_types = get_post_types( array( 'public' => true ) );
78
+ foreach( $post_types as $post_type ) {
79
+ $post_types_option[$post_type]['add_meta_box'] = in_array( $post_type, $_POST['add_meta_boxes'] );
80
+ }
81
+ Groups_Options::update_option( Groups_Post_Access::POST_TYPES, $post_types_option );
82
+
83
  $valid_read_caps = array( Groups_Post_Access::READ_POST_CAPABILITY );
84
  if ( !empty( $_POST[GROUPS_READ_POST_CAPABILITIES] ) ) {
85
  $read_caps = $_POST[GROUPS_READ_POST_CAPABILITIES];
174
  // print the options form
175
  //
176
  echo
177
+ '<form action="" name="options" method="post">' .
178
+
179
+ '<p>' .
180
+ '<input class="button" type="submit" name="submit" value="' . __( 'Save', GROUPS_PLUGIN_DOMAIN ) . '"/>' .
181
+ '</p>' .
182
+
183
  '<div>' .
184
  '<h3>' . __( 'Administrator Access Override', GROUPS_PLUGIN_DOMAIN ) . '</h3>' .
185
  '<p>' .
191
 
192
  echo '<h3>' . __( 'Access restricions', GROUPS_PLUGIN_DOMAIN ) . '</h3>';
193
 
194
+ echo '<h4>' . __( 'Post types', GROUPS_PLUGIN_DOMAIN ) . '</h4>';
195
+
196
+ echo
197
+ '<p class="description">' . __( 'Show access restrictions for these post types.', GROUPS_PLUGIN_DOMAIN ) . '</p>';
198
+
199
+ $post_types_option = Groups_Options::get_option( Groups_Post_Access::POST_TYPES, array() );
200
+ $post_types = get_post_types( array( 'public' => true ) );
201
+ echo '<ul>';
202
+ foreach( $post_types as $post_type ) {
203
+ $post_type_object = get_post_type_object( $post_type );
204
+ echo '<li>';
205
+ echo '<label>';
206
+ $label = $post_type;
207
+ $labels = isset( $post_type_object->labels ) ? $post_type_object->labels : null;
208
+ if ( ( $labels !== null ) && isset( $labels->singular_name ) ) {
209
+ $label = __( $labels->singular_name );
210
+ }
211
+ $checked = ( !isset( $post_types_option[$post_type]['add_meta_box'] ) || $post_types_option[$post_type]['add_meta_box'] ) ? ' checked="checked" ' : '';
212
+ echo '<input name="add_meta_boxes[]" type="checkbox" value="' . esc_attr( $post_type ) . '" ' . $checked . '/>';
213
+ echo $label;
214
+ echo '</label>';
215
+ echo '</li>';
216
+ }
217
+ echo '<ul>';
218
+ echo
219
+ '<p class="description">' .
220
+ __( 'This determines for which post types access restriction settings are offered.', GROUPS_PLUGIN_DOMAIN ) . '<br/>' .
221
+ __( 'Disabling this setting for a post type does not remove existing access restrictions on individual posts of that type.', GROUPS_PLUGIN_DOMAIN ) . '<br/>' .
222
+ '</p>';
223
+
224
+
225
+ echo '<h4>' . __( 'Capabilities', GROUPS_PLUGIN_DOMAIN ) . '</h4>';
226
+
227
  echo '<p class="description">' .
228
  __( 'Include these capabilities to enforce read access on posts. The selected capabilities will be offered to restrict access to posts.', GROUPS_PLUGIN_DOMAIN ) .
229
  '</p>';
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, permission, permissions
5
  Requires at least: 3.3
6
  Tested up to: 3.4.2
7
- Stable tag: 1.2.5
8
  License: GPLv3
9
 
10
  Groups provides group-based user membership management, group-based capabilities and content access control.
@@ -319,6 +319,11 @@ See also [Groups](http://www.itthinx.com/plugins/groups/)
319
 
320
  == Changelog ==
321
 
 
 
 
 
 
322
  = 1.2.5 =
323
  * Added Spanish translation
324
 
@@ -394,6 +399,9 @@ Some installations wouldn't work correctly, showing no capabilities and making i
394
 
395
  == Upgrade Notice ==
396
 
 
 
 
397
  = 1.2.5 =
398
  * Added Spanish translation
399
 
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.
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
325
+ * Fixed issue, removed access restrictions offered on Links
326
+
327
  = 1.2.5 =
328
  * Added Spanish translation
329
 
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
+
405
  = 1.2.5 =
406
  * Added Spanish translation
407