PluginProbe
Private groups / trunk
Private groups vtrunk
trunk 1.5 1.6 1.7 1.8 1.8.1 1.9.1 1.9.2 2.0 2.0.1 2.2 2.3 2.4 2.5 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 All 116 releases
bbp-private-groups / includes / user-profile.php

user-profile.php in Private groups trunk, at includes/user-profile.php

121 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // User profile edit/display actions
4 add_action( 'edit_user_profile', 'rpg_user_profile_field', 50,2 ) ;
5 add_action( 'edit_user_profile_update', 'bbp_edit_user_pg' );
6
7
8 function rpg_user_profile_field() {
9 global $current_user;
10 global $rpg_groups ;
11 global $rpg_disable_groups ;
12
13
14 if (isset($_REQUEST['user_id'])) {
15 $user_id = $_REQUEST['user_id'];
16 } else {
17 $user_id = bbp_get_displayed_user_id();
18 }
19 ?>
20 <table class="form-table">
21 <tbody>
22 <tr>
23 <th><label for="bbp-private-groups"><?php esc_html_e( 'Private Groups', 'bbp-private-groups' ); ?></label></th>
24 <td>
25
26 <?php global $rpg_groups ;
27 if (empty( $rpg_groups ) ) : ?>
28
29 <option value=""><?php esc_html_e( '&mdash; No groups yet set up &mdash;', 'bbp-private-groups' ); ?></option>
30
31 <?php
32 else : ?>
33
34
35 <!-- checkbox to activate -->
36 <?php $private_group = get_user_meta($user_id, 'private_group', true); ?>
37
38
39 <?php
40 foreach ( $rpg_groups as $group => $details ) : ?>
41 <?php
42 //if not disabled then show...
43 if (empty($rpg_disable_groups[$group])) {
44 ?>
45 <tr valign="top">
46 <?php $groupname=__('Group','bbp-private-groups').substr($group,5,strlen($group)) ; ?>
47 <th>
48 <?php echo $groupname." ".$details ; ?>
49 </th>
50
51 <td>
52 <?php
53 $check=0 ;
54 if (strpos($private_group, '*'.$group.'*') !== FALSE) $check=1 ;
55 elseif($private_group == $group) $check=1 ;
56 echo '<input name="'.$group.'" id="group" type="checkbox" ' ;
57 if( $check ) echo 'checked="checked"';
58 echo ' />' ;
59 _e ('Click to add this group', 'bbp-private-groups' );
60 ?>
61 </td>
62 </tr>
63 <?php
64 }
65 endforeach; ?>
66 <?php
67 endif;
68 ?>
69
70
71 </select>
72 </td>
73 </tr>
74
75 </tbody>
76 </table>
77 <?php
78
79
80 }
81
82
83
84 function bbp_edit_user_pg( $user_id ) {
85 global $rpg_groups ;
86 $string='*' ;
87 foreach ( (array) $rpg_groups as $pggroup => $details) {
88 $item='private_group_'.$pggroup ;
89 $data = (!empty ($_POST[$pggroup]) ? $_POST[$pggroup] : '' );
90 //$data = ($_POST[$pggroup] );
91 if ($data=='on') {
92 $string=$string.$pggroup.'*' ;
93 }
94 }
95 if ($string=='*') $string = '' ;
96 update_user_meta( $user_id, 'private_group', $string);
97 //then update subscriptions
98 if (get_option( '_bbp_enable_subscriptions' )) rpg_amend_subscriptions ($user_id) ;
99 }
100
101 Function rpg_amend_subscriptions ($user_id){
102 //this function removes forums and topics subscription on group changes
103 //eg on a group change, a user may have subscriptions to forums or topics which they no longer should have access to.
104
105 //first forums
106 $bbp_subscription_forums = bbp_get_user_subscribed_forum_ids ($user_id) ;
107 foreach ($bbp_subscription_forums as $forum_id) {
108 if (!private_groups_can_user_view_post( $user_id, $forum_id)) {
109 bbp_remove_user_forum_subscription( $user_id, $forum_id );
110 }
111 }
112 //then topics
113 $bbp_subscription_topics = bbp_get_user_subscribed_topic_ids ($user_id) ;
114 foreach ($bbp_subscription_topics as $topic_id) {
115 $forum_id = private_groups_get_forum_id_from_post_id($topic_id ) ;
116 if (!private_groups_can_user_view_post( $user_id, $forum_id)) {
117 bbp_remove_user_topic_subscription( $user_id, $topic_id );
118 }
119 }
120
121 }