Version Description
- Fix role mapping for non-WordPress roles
- Fix issue with private forums being blocked
- Allow moderators to see hidden forums
Download this release
Release Info
Developer | johnjamesjacoby |
Plugin | bbPress |
Version | 2.2.1 |
Comparing to | |
See all releases |
Code changes from version 2.2 to 2.2.1
- bbpress.php +3 -4
- includes/admin/tools.php +8 -4
- includes/core/capabilities.php +1 -20
- includes/forums/capabilities.php +1 -1
- includes/replies/capabilities.php +1 -1
- includes/topics/capabilities.php +1 -1
- includes/topics/functions.php +25 -9
- includes/users/capabilities.php +59 -26
- readme.txt +6 -2
bbpress.php
CHANGED
@@ -5,7 +5,7 @@
|
|
5 |
*
|
6 |
* bbPress is forum software with a twist from the creators of WordPress.
|
7 |
*
|
8 |
-
* $Id: bbpress.php
|
9 |
*
|
10 |
* @package bbPress
|
11 |
* @subpackage Main
|
@@ -17,7 +17,7 @@
|
|
17 |
* Description: bbPress is forum software with a twist from the creators of WordPress.
|
18 |
* Author: The bbPress Community
|
19 |
* Author URI: http://bbpress.org
|
20 |
-
* Version: 2.2
|
21 |
* Text Domain: bbpress
|
22 |
* Domain Path: /languages/
|
23 |
*/
|
@@ -180,7 +180,7 @@ final class bbPress {
|
|
180 |
|
181 |
/** Versions **********************************************************/
|
182 |
|
183 |
-
$this->version = '2.2';
|
184 |
$this->db_version = '220';
|
185 |
|
186 |
/** Paths *************************************************************/
|
@@ -946,4 +946,3 @@ if ( defined( 'BBPRESS_LATE_LOAD' ) ) {
|
|
946 |
}
|
947 |
|
948 |
endif; // class_exists check
|
949 |
-
|
5 |
*
|
6 |
* bbPress is forum software with a twist from the creators of WordPress.
|
7 |
*
|
8 |
+
* $Id: bbpress.php 4455 2012-11-21 03:05:43Z johnjamesjacoby $
|
9 |
*
|
10 |
* @package bbPress
|
11 |
* @subpackage Main
|
17 |
* Description: bbPress is forum software with a twist from the creators of WordPress.
|
18 |
* Author: The bbPress Community
|
19 |
* Author URI: http://bbpress.org
|
20 |
+
* Version: 2.2.1
|
21 |
* Text Domain: bbpress
|
22 |
* Domain Path: /languages/
|
23 |
*/
|
180 |
|
181 |
/** Versions **********************************************************/
|
182 |
|
183 |
+
$this->version = '2.2.1';
|
184 |
$this->db_version = '220';
|
185 |
|
186 |
/** Paths *************************************************************/
|
946 |
}
|
947 |
|
948 |
endif; // class_exists check
|
|
includes/admin/tools.php
CHANGED
@@ -680,9 +680,10 @@ function bbp_admin_repair_user_subscriptions() {
|
|
680 |
*/
|
681 |
function bbp_admin_repair_user_roles() {
|
682 |
|
683 |
-
$statement
|
684 |
-
$changed
|
685 |
-
$role_map
|
|
|
686 |
|
687 |
// Bail if no role map exists
|
688 |
if ( empty( $role_map ) )
|
@@ -694,6 +695,9 @@ function bbp_admin_repair_user_roles() {
|
|
694 |
// Reset the offset
|
695 |
$offset = 0;
|
696 |
|
|
|
|
|
|
|
697 |
// Get users of this site, limited to 1000
|
698 |
while ( $users = get_users( array(
|
699 |
'role' => $role,
|
@@ -704,7 +708,7 @@ function bbp_admin_repair_user_roles() {
|
|
704 |
|
705 |
// Iterate through each user of $role and try to set it
|
706 |
foreach ( (array) $users as $user_id ) {
|
707 |
-
if ( bbp_set_user_role( $user_id, $
|
708 |
++$changed; // Keep a count to display at the end
|
709 |
}
|
710 |
}
|
680 |
*/
|
681 |
function bbp_admin_repair_user_roles() {
|
682 |
|
683 |
+
$statement = __( 'Remapping forum role for each user on this site… %s', 'bbpress' );
|
684 |
+
$changed = 0;
|
685 |
+
$role_map = bbp_get_user_role_map();
|
686 |
+
$default_role = bbp_get_default_role();
|
687 |
|
688 |
// Bail if no role map exists
|
689 |
if ( empty( $role_map ) )
|
695 |
// Reset the offset
|
696 |
$offset = 0;
|
697 |
|
698 |
+
// If no role map exists, give the default forum role (bbp-participant)
|
699 |
+
$new_role = isset( $role_map[$role] ) ? $role_map[$role] : $default_role;
|
700 |
+
|
701 |
// Get users of this site, limited to 1000
|
702 |
while ( $users = get_users( array(
|
703 |
'role' => $role,
|
708 |
|
709 |
// Iterate through each user of $role and try to set it
|
710 |
foreach ( (array) $users as $user_id ) {
|
711 |
+
if ( bbp_set_user_role( $user_id, $new_role ) ) {
|
712 |
++$changed; // Keep a count to display at the end
|
713 |
}
|
714 |
}
|
includes/core/capabilities.php
CHANGED
@@ -99,7 +99,7 @@ function bbp_get_caps_for_role( $role = '' ) {
|
|
99 |
'delete_forums' => false,
|
100 |
'delete_others_forums' => false,
|
101 |
'read_private_forums' => true,
|
102 |
-
'read_hidden_forums' =>
|
103 |
|
104 |
// Topic caps
|
105 |
'publish_topics' => true,
|
@@ -217,7 +217,6 @@ function bbp_get_caps_for_role( $role = '' ) {
|
|
217 |
break;
|
218 |
|
219 |
// Participant/Default
|
220 |
-
case bbp_get_visitor_role() :
|
221 |
case bbp_get_participant_role() :
|
222 |
default :
|
223 |
$caps = array(
|
@@ -426,12 +425,6 @@ function bbp_get_dynamic_roles() {
|
|
426 |
'capabilities' => bbp_get_caps_for_role( bbp_get_spectator_role() )
|
427 |
),
|
428 |
|
429 |
-
// Visitor
|
430 |
-
bbp_get_visitor_role() => array(
|
431 |
-
'name' => __( 'Visitor', 'bbpress' ),
|
432 |
-
'capabilities' => bbp_get_caps_for_role( bbp_get_visitor_role() )
|
433 |
-
),
|
434 |
-
|
435 |
// Blocked
|
436 |
bbp_get_blocked_role() => array(
|
437 |
'name' => __( 'Blocked', 'bbpress' ),
|
@@ -517,18 +510,6 @@ function bbp_get_spectator_role() {
|
|
517 |
return apply_filters( 'bbp_get_spectator_role', 'bbp_spectator' );
|
518 |
}
|
519 |
|
520 |
-
/**
|
521 |
-
* The visitor role for any registered user without a set forum role.
|
522 |
-
*
|
523 |
-
* @since bbPress (r3860)
|
524 |
-
*
|
525 |
-
* @uses apply_filters() Allow override of hardcoded visitor role
|
526 |
-
* @return string
|
527 |
-
*/
|
528 |
-
function bbp_get_visitor_role() {
|
529 |
-
return apply_filters( 'bbp_get_visitor_role', 'bbp_visitor' );
|
530 |
-
}
|
531 |
-
|
532 |
/**
|
533 |
* The blocked role is for registered users that cannot spectate or participate
|
534 |
*
|
99 |
'delete_forums' => false,
|
100 |
'delete_others_forums' => false,
|
101 |
'read_private_forums' => true,
|
102 |
+
'read_hidden_forums' => true,
|
103 |
|
104 |
// Topic caps
|
105 |
'publish_topics' => true,
|
217 |
break;
|
218 |
|
219 |
// Participant/Default
|
|
|
220 |
case bbp_get_participant_role() :
|
221 |
default :
|
222 |
$caps = array(
|
425 |
'capabilities' => bbp_get_caps_for_role( bbp_get_spectator_role() )
|
426 |
),
|
427 |
|
|
|
|
|
|
|
|
|
|
|
|
|
428 |
// Blocked
|
429 |
bbp_get_blocked_role() => array(
|
430 |
'name' => __( 'Blocked', 'bbpress' ),
|
510 |
return apply_filters( 'bbp_get_spectator_role', 'bbp_spectator' );
|
511 |
}
|
512 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
513 |
/**
|
514 |
* The blocked role is for registered users that cannot spectate or participate
|
515 |
*
|
includes/forums/capabilities.php
CHANGED
@@ -86,7 +86,7 @@ function bbp_map_forum_meta_caps( $caps = array(), $cap = '', $user_id = 0, $arg
|
|
86 |
|
87 |
// Unknown so map to private posts
|
88 |
} else {
|
89 |
-
$caps = array( $post_type->cap->
|
90 |
}
|
91 |
}
|
92 |
}
|
86 |
|
87 |
// Unknown so map to private posts
|
88 |
} else {
|
89 |
+
$caps = array( $post_type->cap->read_private_posts );
|
90 |
}
|
91 |
}
|
92 |
}
|
includes/replies/capabilities.php
CHANGED
@@ -75,7 +75,7 @@ function bbp_map_reply_meta_caps( $caps = array(), $cap = '', $user_id = 0, $arg
|
|
75 |
|
76 |
// Unknown so map to private posts
|
77 |
} else {
|
78 |
-
$caps = array( $post_type->cap->
|
79 |
}
|
80 |
}
|
81 |
}
|
75 |
|
76 |
// Unknown so map to private posts
|
77 |
} else {
|
78 |
+
$caps = array( $post_type->cap->read_private_posts );
|
79 |
}
|
80 |
}
|
81 |
}
|
includes/topics/capabilities.php
CHANGED
@@ -93,7 +93,7 @@ function bbp_map_topic_meta_caps( $caps = array(), $cap = '', $user_id = 0, $arg
|
|
93 |
|
94 |
// Unknown so map to private posts
|
95 |
} else {
|
96 |
-
$caps = array( $post_type->cap->
|
97 |
}
|
98 |
}
|
99 |
}
|
93 |
|
94 |
// Unknown so map to private posts
|
95 |
} else {
|
96 |
+
$caps = array( $post_type->cap->read_private_posts );
|
97 |
}
|
98 |
}
|
99 |
}
|
includes/topics/functions.php
CHANGED
@@ -2827,8 +2827,12 @@ function bbp_unspam_topic( $topic_id = 0 ) {
|
|
2827 |
function bbp_stick_topic( $topic_id = 0, $super = false ) {
|
2828 |
$topic_id = bbp_get_topic_id( $topic_id );
|
2829 |
|
2830 |
-
//
|
2831 |
-
|
|
|
|
|
|
|
|
|
2832 |
bbp_unstick_topic( $topic_id );
|
2833 |
|
2834 |
$forum_id = empty( $super ) ? bbp_get_topic_forum_id( $topic_id ) : 0;
|
@@ -2836,18 +2840,29 @@ function bbp_stick_topic( $topic_id = 0, $super = false ) {
|
|
2836 |
|
2837 |
do_action( 'bbp_stick_topic', $topic_id, $super );
|
2838 |
|
2839 |
-
if ( !is_array( $stickies ) )
|
2840 |
$stickies = array( $topic_id );
|
2841 |
-
else
|
2842 |
$stickies[] = $topic_id;
|
|
|
2843 |
|
|
|
2844 |
$stickies = array_unique( array_filter( $stickies ) );
|
2845 |
|
2846 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2847 |
|
2848 |
do_action( 'bbp_sticked_topic', $topic_id, $super, $success );
|
2849 |
|
2850 |
-
return $success;
|
2851 |
}
|
2852 |
|
2853 |
/**
|
@@ -2885,15 +2900,16 @@ function bbp_unstick_topic( $topic_id = 0 ) {
|
|
2885 |
$success = true;
|
2886 |
} else {
|
2887 |
array_splice( $stickies, $offset, 1 );
|
2888 |
-
if ( empty( $stickies ) )
|
2889 |
$success = !empty( $super ) ? delete_option( '_bbp_super_sticky_topics' ) : delete_post_meta( $forum_id, '_bbp_sticky_topics' );
|
2890 |
-
else
|
2891 |
$success = !empty( $super ) ? update_option( '_bbp_super_sticky_topics', $stickies ) : update_post_meta( $forum_id, '_bbp_sticky_topics', $stickies );
|
|
|
2892 |
}
|
2893 |
|
2894 |
do_action( 'bbp_unsticked_topic', $topic_id, $success );
|
2895 |
|
2896 |
-
return
|
2897 |
}
|
2898 |
|
2899 |
/** Before Delete/Trash/Untrash ***********************************************/
|
2827 |
function bbp_stick_topic( $topic_id = 0, $super = false ) {
|
2828 |
$topic_id = bbp_get_topic_id( $topic_id );
|
2829 |
|
2830 |
+
// Bail if a topic is not a topic (prevents revisions as stickies)
|
2831 |
+
if ( ! bbp_is_topic( $topic_id ) )
|
2832 |
+
return false;
|
2833 |
+
|
2834 |
+
// We may have a super sticky to which we want to convert into a normal
|
2835 |
+
// sticky and vice versa; unstick the topic first to avoid any possible error.
|
2836 |
bbp_unstick_topic( $topic_id );
|
2837 |
|
2838 |
$forum_id = empty( $super ) ? bbp_get_topic_forum_id( $topic_id ) : 0;
|
2840 |
|
2841 |
do_action( 'bbp_stick_topic', $topic_id, $super );
|
2842 |
|
2843 |
+
if ( !is_array( $stickies ) ) {
|
2844 |
$stickies = array( $topic_id );
|
2845 |
+
} else {
|
2846 |
$stickies[] = $topic_id;
|
2847 |
+
}
|
2848 |
|
2849 |
+
// Pull out duplicates and empties
|
2850 |
$stickies = array_unique( array_filter( $stickies ) );
|
2851 |
|
2852 |
+
// Unset incorrectly stuck revisions
|
2853 |
+
foreach ( (array) $stickies as $key => $id ) {
|
2854 |
+
if ( ! bbp_is_topic( $id ) ) {
|
2855 |
+
unset( $stickies[$key] );
|
2856 |
+
}
|
2857 |
+
}
|
2858 |
+
|
2859 |
+
// Reset keys
|
2860 |
+
$stickies = array_values( $stickies );
|
2861 |
+
$success = !empty( $super ) ? update_option( '_bbp_super_sticky_topics', $stickies ) : update_post_meta( $forum_id, '_bbp_sticky_topics', $stickies );
|
2862 |
|
2863 |
do_action( 'bbp_sticked_topic', $topic_id, $super, $success );
|
2864 |
|
2865 |
+
return (bool) $success;
|
2866 |
}
|
2867 |
|
2868 |
/**
|
2900 |
$success = true;
|
2901 |
} else {
|
2902 |
array_splice( $stickies, $offset, 1 );
|
2903 |
+
if ( empty( $stickies ) ) {
|
2904 |
$success = !empty( $super ) ? delete_option( '_bbp_super_sticky_topics' ) : delete_post_meta( $forum_id, '_bbp_sticky_topics' );
|
2905 |
+
} else {
|
2906 |
$success = !empty( $super ) ? update_option( '_bbp_super_sticky_topics', $stickies ) : update_post_meta( $forum_id, '_bbp_sticky_topics', $stickies );
|
2907 |
+
}
|
2908 |
}
|
2909 |
|
2910 |
do_action( 'bbp_unsticked_topic', $topic_id, $success );
|
2911 |
|
2912 |
+
return (bool) $success;
|
2913 |
}
|
2914 |
|
2915 |
/** Before Delete/Trash/Untrash ***********************************************/
|
includes/users/capabilities.php
CHANGED
@@ -94,7 +94,7 @@ function bbp_set_user_role( $user_id = 0, $new_role = '' ) {
|
|
94 |
}
|
95 |
|
96 |
/**
|
97 |
-
* Return a user's
|
98 |
*
|
99 |
* @since bbPress (r3860)
|
100 |
*
|
@@ -124,6 +124,44 @@ function bbp_get_user_role( $user_id = 0 ) {
|
|
124 |
return apply_filters( 'bbp_get_user_role', $role, $user_id, $user );
|
125 |
}
|
126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
/**
|
128 |
* Helper function hooked to 'bbp_edit_user_profile_update' action to save or
|
129 |
* update user roles and capabilities.
|
@@ -208,36 +246,32 @@ function bbp_set_current_user_default_role() {
|
|
208 |
$add_to_site = bbp_allow_global_access();
|
209 |
|
210 |
// Get the current user's WordPress role. Set to empty string if none found.
|
211 |
-
$user_role =
|
212 |
|
213 |
-
//
|
214 |
-
|
215 |
|
216 |
-
|
217 |
-
if ( $user_role == $wp_role ) {
|
218 |
|
219 |
-
|
220 |
-
|
|
|
221 |
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
// Add the mapped forums role to the user's account
|
228 |
-
$bbp->current_user->add_role( $bbp_role );
|
229 |
|
230 |
-
|
231 |
-
//$bbp->current_user->add_role( get_option( 'default_role' ) );
|
232 |
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
$bbp->current_user->get_role_caps();
|
237 |
-
}
|
238 |
|
239 |
-
|
240 |
-
|
|
|
|
|
241 |
}
|
242 |
}
|
243 |
|
@@ -261,8 +295,7 @@ function bbp_get_user_role_map() {
|
|
261 |
'editor' => $default_role,
|
262 |
'author' => $default_role,
|
263 |
'contributor' => $default_role,
|
264 |
-
'subscriber' => $default_role
|
265 |
-
'' => bbp_get_visitor_role()
|
266 |
) );
|
267 |
}
|
268 |
|
94 |
}
|
95 |
|
96 |
/**
|
97 |
+
* Return a user's forums role
|
98 |
*
|
99 |
* @since bbPress (r3860)
|
100 |
*
|
124 |
return apply_filters( 'bbp_get_user_role', $role, $user_id, $user );
|
125 |
}
|
126 |
|
127 |
+
/**
|
128 |
+
* Return a user's blog role
|
129 |
+
*
|
130 |
+
* @since bbPress (r4446)
|
131 |
+
*
|
132 |
+
* @param int $user_id
|
133 |
+
* @uses bbp_get_user_id() To get the user id
|
134 |
+
* @uses get_userdata() To get the user data
|
135 |
+
* @uses apply_filters() Calls 'bbp_get_user_blog_role' with the role and user id
|
136 |
+
* @return string
|
137 |
+
*/
|
138 |
+
function bbp_get_user_blog_role( $user_id = 0 ) {
|
139 |
+
global $wp_roles;
|
140 |
+
|
141 |
+
// This really shold not be necessary anymore, and will likely be removed
|
142 |
+
// at a later date. If roles aren't loaded yet, something else is wrong.
|
143 |
+
if ( ! isset( $wp_roles ) )
|
144 |
+
$wp_roles = new WP_Roles();
|
145 |
+
|
146 |
+
// Validate user id
|
147 |
+
$user_id = bbp_get_user_id( $user_id, false, false );
|
148 |
+
$user = get_userdata( $user_id );
|
149 |
+
$role = false;
|
150 |
+
$all_roles = apply_filters( 'editable_roles', $wp_roles->roles );
|
151 |
+
|
152 |
+
// User has roles so lets
|
153 |
+
if ( ! empty( $user->roles ) ) {
|
154 |
+
$roles = array_intersect( array_values( $user->roles ), array_keys( $all_roles ) );
|
155 |
+
|
156 |
+
// If there's a role in the array, use the first one
|
157 |
+
if ( !empty( $roles ) ) {
|
158 |
+
$role = array_shift( array_values( $roles ) );
|
159 |
+
}
|
160 |
+
}
|
161 |
+
|
162 |
+
return apply_filters( 'bbp_get_user_blog_role', $role, $user_id, $user );
|
163 |
+
}
|
164 |
+
|
165 |
/**
|
166 |
* Helper function hooked to 'bbp_edit_user_profile_update' action to save or
|
167 |
* update user roles and capabilities.
|
246 |
$add_to_site = bbp_allow_global_access();
|
247 |
|
248 |
// Get the current user's WordPress role. Set to empty string if none found.
|
249 |
+
$user_role = bbp_get_user_blog_role( $user_id );
|
250 |
|
251 |
+
// Get the role map
|
252 |
+
$role_map = bbp_get_user_role_map();
|
253 |
|
254 |
+
/** Forum Role ************************************************************/
|
|
|
255 |
|
256 |
+
// Use a mapped role
|
257 |
+
if ( isset( $role_map[$user_role] ) ) {
|
258 |
+
$new_role = $role_map[$user_role];
|
259 |
|
260 |
+
// Use the default role
|
261 |
+
} else {
|
262 |
+
$new_role = bbp_get_default_role();
|
263 |
+
}
|
|
|
|
|
|
|
264 |
|
265 |
+
/** Add or Map ************************************************************/
|
|
|
266 |
|
267 |
+
// Add the user to the site
|
268 |
+
if ( true == $add_to_site ) {
|
269 |
+
$bbp->current_user->add_role( $new_role );
|
|
|
|
|
270 |
|
271 |
+
// Don't add the user, but still give them the correct caps dynamically
|
272 |
+
} else {
|
273 |
+
$bbp->current_user->caps[$new_role] = true;
|
274 |
+
$bbp->current_user->get_role_caps();
|
275 |
}
|
276 |
}
|
277 |
|
295 |
'editor' => $default_role,
|
296 |
'author' => $default_role,
|
297 |
'contributor' => $default_role,
|
298 |
+
'subscriber' => $default_role
|
|
|
299 |
) );
|
300 |
}
|
301 |
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: matt, johnjamesjacoby
|
|
3 |
Tags: forums, discussion, support, theme, akismet, multisite
|
4 |
Requires at least: 3.4
|
5 |
Tested up to: 3.5
|
6 |
-
Stable tag: 2.2
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
@@ -26,6 +26,11 @@ We're keeping things as small and light as possible while still allowing for gre
|
|
26 |
|
27 |
== Changelog ==
|
28 |
|
|
|
|
|
|
|
|
|
|
|
29 |
= 2.2 =
|
30 |
* Improved user roles and capabilities
|
31 |
* Improved theme compatibility
|
@@ -149,4 +154,3 @@ We're keeping things as small and light as possible while still allowing for gre
|
|
149 |
|
150 |
= 2.0-beta-1 =
|
151 |
* In development
|
152 |
-
t
|
3 |
Tags: forums, discussion, support, theme, akismet, multisite
|
4 |
Requires at least: 3.4
|
5 |
Tested up to: 3.5
|
6 |
+
Stable tag: 2.2.1
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
26 |
|
27 |
== Changelog ==
|
28 |
|
29 |
+
= 2.2.1 =
|
30 |
+
* Fix role mapping for non-WordPress roles
|
31 |
+
* Fix issue with private forums being blocked
|
32 |
+
* Allow moderators to see hidden forums
|
33 |
+
|
34 |
= 2.2 =
|
35 |
* Improved user roles and capabilities
|
36 |
* Improved theme compatibility
|
154 |
|
155 |
= 2.0-beta-1 =
|
156 |
* In development
|
|