Version Description
- New shortcode [groups_join group="..."] lets a user join the given group
- New shortcode [groups_leave group="..."] lets a user leave the given group
Download this release
Release Info
Developer | itthinx |
Plugin | Groups |
Version | 1.2.3 |
Comparing to | |
See all releases |
Code changes from version 1.2.2 to 1.2.3
- groups.php +2 -2
- lib/views/class-groups-shortcodes.php +160 -0
- readme.txt +38 -2
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.
|
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.
|
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.2.3
|
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.3' );
|
31 |
define( 'GROUPS_FILE', __FILE__ );
|
32 |
if ( !defined( 'GROUPS_CORE_DIR' ) ) {
|
33 |
define( 'GROUPS_CORE_DIR', WP_PLUGIN_DIR . '/groups' );
|
lib/views/class-groups-shortcodes.php
CHANGED
@@ -34,6 +34,10 @@ class Groups_Shortcodes {
|
|
34 |
add_shortcode( 'groups_user_groups', array( __CLASS__, 'groups_user_groups' ) );
|
35 |
// groups
|
36 |
add_shortcode( 'groups_groups', array( __CLASS__, 'groups_groups' ) );
|
|
|
|
|
|
|
|
|
37 |
}
|
38 |
|
39 |
/**
|
@@ -299,5 +303,161 @@ class Groups_Shortcodes {
|
|
299 |
}
|
300 |
return $output;
|
301 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
302 |
}
|
303 |
Groups_Shortcodes::init();
|
34 |
add_shortcode( 'groups_user_groups', array( __CLASS__, 'groups_user_groups' ) );
|
35 |
// groups
|
36 |
add_shortcode( 'groups_groups', array( __CLASS__, 'groups_groups' ) );
|
37 |
+
// join a group
|
38 |
+
add_shortcode( 'groups_join', array( __CLASS__, 'groups_join' ) );
|
39 |
+
// leave a group
|
40 |
+
add_shortcode( 'groups_leave', array( __CLASS__, 'groups_leave' ) );
|
41 |
}
|
42 |
|
43 |
/**
|
303 |
}
|
304 |
return $output;
|
305 |
}
|
306 |
+
|
307 |
+
/**
|
308 |
+
* Renders a form that lets a user join a group.
|
309 |
+
* * Attributes:
|
310 |
+
* - "group" : (required) group name or id
|
311 |
+
*
|
312 |
+
* @param array $atts attributes
|
313 |
+
* @param string $content not used
|
314 |
+
*/
|
315 |
+
public static function groups_join( $atts, $content = null ) {
|
316 |
+
$nonce_action = 'groups_action';
|
317 |
+
$nonce = 'nonce_join';
|
318 |
+
$output = "";
|
319 |
+
|
320 |
+
$options = shortcode_atts(
|
321 |
+
array(
|
322 |
+
'group' => '',
|
323 |
+
'display_message' => true,
|
324 |
+
'display_is_member' => false,
|
325 |
+
'submit_text' => __( 'Join the %s group', GROUPS_PLUGIN_DOMAIN )
|
326 |
+
),
|
327 |
+
$atts
|
328 |
+
);
|
329 |
+
extract( $options );
|
330 |
+
|
331 |
+
if ( $display_message === 'false' ) {
|
332 |
+
$display_message = false;
|
333 |
+
}
|
334 |
+
if ( $display_is_member === 'true' ) {
|
335 |
+
$display_is_member = true;
|
336 |
+
}
|
337 |
+
|
338 |
+
$group = trim( $options['group'] );
|
339 |
+
$current_group = Groups_Group::read( $group );
|
340 |
+
if ( !$current_group ) {
|
341 |
+
$current_group = Groups_Group::read_by_name( $group );
|
342 |
+
}
|
343 |
+
if ( $current_group ) {
|
344 |
+
if ( $user_id = get_current_user_id() ) {
|
345 |
+
$submitted = false;
|
346 |
+
$invalid_nonce = false;
|
347 |
+
if ( !empty( $_POST['groups_action'] ) && $_POST['groups_action'] == 'join' ) {
|
348 |
+
$submitted = true;
|
349 |
+
if ( !wp_verify_nonce( $_POST[$nonce], $nonce_action ) ) {
|
350 |
+
$invalid_nonce = true;
|
351 |
+
}
|
352 |
+
}
|
353 |
+
if ( $submitted && !$invalid_nonce ) {
|
354 |
+
// add user to group
|
355 |
+
if ( isset( $_POST['group_id'] ) ) {
|
356 |
+
$join_group = Groups_Group::read( $_POST['group_id'] );
|
357 |
+
Groups_User_Group::create(
|
358 |
+
array(
|
359 |
+
'group_id' => $join_group->group_id,
|
360 |
+
'user_id' => $user_id
|
361 |
+
)
|
362 |
+
);
|
363 |
+
}
|
364 |
+
}
|
365 |
+
if ( !Groups_User_Group::read( $user_id, $current_group->group_id ) ) {
|
366 |
+
$submit_text = sprintf( $options['submit_text'], wp_filter_nohtml_kses( $current_group->name ) );
|
367 |
+
$output .= '<div class="groups-join">';
|
368 |
+
$output .= '<form action="#" method="post">';
|
369 |
+
$output .= '<input type="hidden" name="groups_action" value="join" />';
|
370 |
+
$output .= '<input type="hidden" name="group_id" value="' . esc_attr( $current_group->group_id ) . '" />';
|
371 |
+
$output .= '<input type="submit" value="' . $submit_text . '" />';
|
372 |
+
$output .= wp_nonce_field( $nonce_action, $nonce, true, false );
|
373 |
+
$output .= '</form>';
|
374 |
+
$output .= '</div>';
|
375 |
+
} else if ( $display_message ) {
|
376 |
+
if ( $submitted && !$invalid_nonce && isset( $join_group ) && $join_group->group_id === $current_group->group_id ) {
|
377 |
+
$output .= '<div class="groups-join joined">';
|
378 |
+
$output .= sprintf( __( 'You have joined the %s group.', GROUPS_PLUGIN_DOMAIN ), wp_filter_nohtml_kses( $join_group->name ) );
|
379 |
+
$output .= '</div>';
|
380 |
+
}
|
381 |
+
else if ( $display_is_member && isset( $current_group ) && $current_group !== false ) {
|
382 |
+
$output .= '<div class="groups-join member">';
|
383 |
+
$output .= sprintf( __( 'You are a member of the %s group.', GROUPS_PLUGIN_DOMAIN ), wp_filter_nohtml_kses( $current_group->name ) );
|
384 |
+
$output .= '</div>';
|
385 |
+
}
|
386 |
+
}
|
387 |
+
}
|
388 |
+
}
|
389 |
+
return $output;
|
390 |
+
}
|
391 |
+
|
392 |
+
/**
|
393 |
+
* Renders a form that lets a user leave a group.
|
394 |
+
* * Attributes:
|
395 |
+
* - "group" : (required) group name or id
|
396 |
+
*
|
397 |
+
* @param array $atts attributes
|
398 |
+
* @param string $content not used
|
399 |
+
*/
|
400 |
+
public static function groups_leave( $atts, $content = null ) {
|
401 |
+
$nonce_action = 'groups_action';
|
402 |
+
$nonce = 'nonce_leave';
|
403 |
+
$output = "";
|
404 |
+
|
405 |
+
$options = shortcode_atts(
|
406 |
+
array(
|
407 |
+
'group' => '',
|
408 |
+
'display_message' => true,
|
409 |
+
'submit_text' => __( 'Leave the %s group', GROUPS_PLUGIN_DOMAIN ),
|
410 |
+
),
|
411 |
+
$atts
|
412 |
+
);
|
413 |
+
extract( $options );
|
414 |
+
|
415 |
+
if ( $display_message === 'false' ) {
|
416 |
+
$display_message = false;
|
417 |
+
}
|
418 |
+
|
419 |
+
$group = trim( $options['group'] );
|
420 |
+
$current_group = Groups_Group::read( $group );
|
421 |
+
if ( !$current_group ) {
|
422 |
+
$current_group = Groups_Group::read_by_name( $group );
|
423 |
+
}
|
424 |
+
if ( $current_group ) {
|
425 |
+
if ( $user_id = get_current_user_id() ) {
|
426 |
+
$submitted = false;
|
427 |
+
$invalid_nonce = false;
|
428 |
+
if ( !empty( $_POST['groups_action'] ) && $_POST['groups_action'] == 'leave' ) {
|
429 |
+
$submitted = true;
|
430 |
+
if ( !wp_verify_nonce( $_POST[$nonce], $nonce_action ) ) {
|
431 |
+
$invalid_nonce = true;
|
432 |
+
}
|
433 |
+
}
|
434 |
+
if ( $submitted && !$invalid_nonce ) {
|
435 |
+
// remove user from group
|
436 |
+
if ( isset( $_POST['group_id'] ) ) {
|
437 |
+
$leave_group = Groups_Group::read( $_POST['group_id'] );
|
438 |
+
Groups_User_Group::delete( $user_id, $leave_group->group_id );
|
439 |
+
}
|
440 |
+
}
|
441 |
+
if ( Groups_User_Group::read( $user_id, $current_group->group_id ) ) {
|
442 |
+
$submit_text = sprintf( $options['submit_text'], wp_filter_nohtml_kses( $current_group->name ) );
|
443 |
+
$output .= '<div class="groups-join">';
|
444 |
+
$output .= '<form action="#" method="post">';
|
445 |
+
$output .= '<input type="hidden" name="groups_action" value="leave" />';
|
446 |
+
$output .= '<input type="hidden" name="group_id" value="' . esc_attr( $current_group->group_id ) . '" />';
|
447 |
+
$output .= '<input type="submit" value="' . $submit_text . '" />';
|
448 |
+
$output .= wp_nonce_field( $nonce_action, $nonce, true, false );
|
449 |
+
$output .= '</form>';
|
450 |
+
$output .= '</div>';
|
451 |
+
} else if ( $display_message ) {
|
452 |
+
if ( $submitted && !$invalid_nonce && isset( $leave_group ) && $leave_group->group_id === $current_group->group_id ) {
|
453 |
+
$output .= '<div class="groups-join left">';
|
454 |
+
$output .= sprintf( __( 'You have left the %s group.', GROUPS_PLUGIN_DOMAIN ), wp_filter_nohtml_kses( $leave_group->name ) );
|
455 |
+
$output .= '</div>';
|
456 |
+
}
|
457 |
+
}
|
458 |
+
}
|
459 |
+
}
|
460 |
+
return $output;
|
461 |
+
}
|
462 |
}
|
463 |
Groups_Shortcodes::init();
|
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, permission, permissions
|
5 |
Requires at least: 3.3
|
6 |
-
Tested up to: 3.4
|
7 |
-
Stable tag: 1.2.
|
8 |
License: GPLv3
|
9 |
|
10 |
Groups provides group-based user membership management, group-based capabilities and content access control.
|
@@ -214,6 +214,35 @@ Examples:
|
|
214 |
|
215 |
* There [groups_group_info group="1" show="count" single="is one member" plural="are %d members"] in the [groups_group_info group="1" show="name"] group.
|
216 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
217 |
#### Show user groups ####
|
218 |
|
219 |
- [groups_user_groups]
|
@@ -287,6 +316,10 @@ See also [Groups](http://www.itthinx.com/plugins/groups/)
|
|
287 |
|
288 |
== Changelog ==
|
289 |
|
|
|
|
|
|
|
|
|
290 |
= 1.2.2 =
|
291 |
* Revised styles
|
292 |
* WordPress 3.4 compatibility
|
@@ -351,6 +384,9 @@ Some installations wouldn't work correctly, showing no capabilities and making i
|
|
351 |
|
352 |
== Upgrade Notice ==
|
353 |
|
|
|
|
|
|
|
354 |
= 1.2.2 =
|
355 |
* Revised styles on admin UI.
|
356 |
|
3 |
Donate link: http://www.itthinx.com/plugins/groups
|
4 |
Tags: access, access control, capability, capabilities, content, download, downloads, file, file access, files, group, groups, member, members, membership, permission, permissions
|
5 |
Requires at least: 3.3
|
6 |
+
Tested up to: 3.4.1
|
7 |
+
Stable tag: 1.2.3
|
8 |
License: GPLv3
|
9 |
|
10 |
Groups provides group-based user membership management, group-based capabilities and content access control.
|
214 |
|
215 |
* There [groups_group_info group="1" show="count" single="is one member" plural="are %d members"] in the [groups_group_info group="1" show="name"] group.
|
216 |
|
217 |
+
#### Let a user join a group ####
|
218 |
+
|
219 |
+
- [groups_join]
|
220 |
+
|
221 |
+
This shortcode takes the following attributes to let a user join a specific group:
|
222 |
+
|
223 |
+
- _group_ : (required) the group ID or name
|
224 |
+
- _display_message_ : (optional) whether to show a confirmation after joining the group; accepted values: _true_, _false_; defaults to _true_
|
225 |
+
- _display_is_member_ : (optional) whether to show that the user is a member of the group; accepted values: _true_, _false_; defaults to _false_
|
226 |
+
- _submit_text_ : (optional) specify to change the button text; must contain %s to show the group name
|
227 |
+
|
228 |
+
Example:
|
229 |
+
|
230 |
+
* [group_join group="Cool"]
|
231 |
+
|
232 |
+
#### Let a user leave a group ####
|
233 |
+
|
234 |
+
- [groups_leave]
|
235 |
+
|
236 |
+
This shortcode takes the following attributes to let a user leave a specific group:
|
237 |
+
|
238 |
+
- _group_ : (required) the group ID or name
|
239 |
+
- _display_message_ : (optional) whether to show a confirmation after leaving the group; accepted values: _true_, _false_; defaults to _true_
|
240 |
+
- _submit_text_ : (optional) specify to change the button text; must contain %s to show the group name
|
241 |
+
|
242 |
+
Example:
|
243 |
+
|
244 |
+
* [groups_leave group="Cool"]
|
245 |
+
|
246 |
#### Show user groups ####
|
247 |
|
248 |
- [groups_user_groups]
|
316 |
|
317 |
== Changelog ==
|
318 |
|
319 |
+
= 1.2.3 =
|
320 |
+
* New shortcode [groups_join group="..."] lets a user join the given group
|
321 |
+
* New shortcode [groups_leave group="..."] lets a user leave the given group
|
322 |
+
|
323 |
= 1.2.2 =
|
324 |
* Revised styles
|
325 |
* WordPress 3.4 compatibility
|
384 |
|
385 |
== Upgrade Notice ==
|
386 |
|
387 |
+
= 1.2.3 =
|
388 |
+
* This release provides new shortcodes to let users join or leave groups by clicking a button.
|
389 |
+
|
390 |
= 1.2.2 =
|
391 |
* Revised styles on admin UI.
|
392 |
|