Changeset 6384 for trunk/src/includes/forums/functions.php
- Timestamp:
- 03/20/2017 10:44:00 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/forums/functions.php
r6341 r6384 142 142 143 143 // User cannot create forums 144 if ( ! current_user_can( 'publish_forums' ) ) {144 if ( ! current_user_can( 'publish_forums' ) ) { 145 145 bbp_add_error( 'bbp_forum_permission', __( '<strong>ERROR</strong>: You do not have permission to create new forums.', 'bbpress' ) ); 146 146 return; … … 208 208 209 209 // Forum is closed and user cannot access 210 if ( bbp_is_forum_closed( $forum_parent_id ) && ! current_user_can( 'edit_forum', $forum_parent_id ) ) {210 if ( bbp_is_forum_closed( $forum_parent_id ) && ! current_user_can( 'edit_forum', $forum_parent_id ) ) { 211 211 bbp_add_error( 'bbp_new_forum_forum_closed', __( '<strong>ERROR</strong>: This forum has been closed to new forums.', 'bbpress' ) ); 212 212 } 213 213 214 214 // Forum is private and user cannot access 215 if ( bbp_is_forum_private( $forum_parent_id ) && ! current_user_can( 'read_private_forums') ) {215 if ( bbp_is_forum_private( $forum_parent_id ) && ! current_user_can( 'read_forum', $forum_parent_id ) ) { 216 216 bbp_add_error( 'bbp_new_forum_forum_private', __( '<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new forums in it.', 'bbpress' ) ); 217 217 } 218 218 219 219 // Forum is hidden and user cannot access 220 if ( bbp_is_forum_hidden( $forum_parent_id ) && ! current_user_can( 'read_hidden_forums') ) {220 if ( bbp_is_forum_hidden( $forum_parent_id ) && ! current_user_can( 'read_forum', $forum_parent_id ) ) { 221 221 bbp_add_error( 'bbp_new_forum_forum_hidden', __( '<strong>ERROR</strong>: This forum is hidden and you do not have the capability to read or create new forums in it.', 'bbpress' ) ); 222 222 } … … 422 422 423 423 // User cannot edit this forum 424 } elseif ( ! current_user_can( 'edit_forum', $forum_id ) ) {424 } elseif ( ! current_user_can( 'edit_forum', $forum_id ) ) { 425 425 bbp_add_error( 'bbp_edit_forum_permission', __( '<strong>ERROR</strong>: You do not have permission to edit that forum.', 'bbpress' ) ); 426 426 return; … … 448 448 449 449 // Forum is closed and user cannot access 450 if ( bbp_is_forum_closed( $forum_parent_id ) && ! current_user_can( 'edit_forum', $forum_parent_id ) ) {450 if ( bbp_is_forum_closed( $forum_parent_id ) && ! current_user_can( 'edit_forum', $forum_parent_id ) ) { 451 451 bbp_add_error( 'bbp_edit_forum_forum_closed', __( '<strong>ERROR</strong>: This forum has been closed to new forums.', 'bbpress' ) ); 452 452 } 453 453 454 454 // Forum is private and user cannot access 455 if ( bbp_is_forum_private( $forum_parent_id ) && ! current_user_can( 'read_private_forums') ) {455 if ( bbp_is_forum_private( $forum_parent_id ) && ! current_user_can( 'read_forum', $forum_parent_id ) ) { 456 456 bbp_add_error( 'bbp_edit_forum_forum_private', __( '<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new forums in it.', 'bbpress' ) ); 457 457 } 458 458 459 459 // Forum is hidden and user cannot access 460 if ( bbp_is_forum_hidden( $forum_parent_id ) && ! current_user_can( 'read_hidden_forums') ) {460 if ( bbp_is_forum_hidden( $forum_parent_id ) && ! current_user_can( 'read_forum', $forum_parent_id ) ) { 461 461 bbp_add_error( 'bbp_edit_forum_forum_hidden', __( '<strong>ERROR</strong>: This forum is hidden and you do not have the capability to read or create new forums in it.', 'bbpress' ) ); 462 462 } … … 2089 2089 */ 2090 2090 function bbp_exclude_forum_ids( $type = 'string' ) { 2091 static $types = array(); 2091 2092 2092 2093 // Setup arrays 2093 2094 $private = $hidden = $meta_query = $forum_ids = array(); 2094 2095 2095 // Default return value 2096 switch ( $type ) { 2097 case 'string' : 2098 $retval = ''; 2099 break; 2100 2101 case 'array' : 2102 $retval = array(); 2103 break; 2104 2105 case 'meta_query' : 2106 $retval = array( array() ) ; 2107 break; 2108 } 2109 2110 // Exclude for everyone but keymasters 2111 if ( ! bbp_is_user_keymaster() ) { 2112 2113 // Private forums 2114 if ( !current_user_can( 'read_private_forums' ) ) { 2115 $private = bbp_get_private_forum_ids(); 2116 } 2117 2118 // Hidden forums 2119 if ( !current_user_can( 'read_hidden_forums' ) ) { 2120 $hidden = bbp_get_hidden_forum_ids(); 2121 } 2122 2123 // Merge private and hidden forums together 2124 $forum_ids = (array) array_filter( wp_parse_id_list( array_merge( $private, $hidden ) ) ); 2125 2126 // There are forums that need to be excluded 2127 if ( ! empty( $forum_ids ) ) { 2128 2129 switch ( $type ) { 2130 2131 // Separate forum ID's into a comma separated string 2132 case 'string' : 2133 $retval = implode( ',', $forum_ids ); 2134 break; 2135 2136 // Use forum_ids array 2137 case 'array' : 2138 $retval = $forum_ids; 2139 break; 2140 2141 // Build a meta_query 2142 case 'meta_query' : 2143 $retval = array( 2144 'key' => '_bbp_forum_id', 2145 'value' => implode( ',', $forum_ids ), 2146 'type' => 'NUMERIC', 2147 'compare' => ( 1 < count( $forum_ids ) ) ? 'NOT IN' : '!=' 2148 ); 2149 break; 2096 // Capability performance optimization 2097 if ( ! empty( $types[ $type ] ) ) { 2098 $retval = $types[ $type ]; 2099 2100 // Populate forum exclude type 2101 } else { 2102 2103 // Default return value 2104 switch ( $type ) { 2105 case 'string' : 2106 $retval = ''; 2107 break; 2108 2109 case 'array' : 2110 $retval = array(); 2111 break; 2112 2113 case 'meta_query' : 2114 $retval = array( array() ) ; 2115 break; 2116 } 2117 2118 // Exclude for everyone but keymasters 2119 if ( ! bbp_is_user_keymaster() ) { 2120 2121 // Private forums 2122 if ( ! current_user_can( 'read_private_forums' ) ) { 2123 $private = bbp_get_private_forum_ids(); 2150 2124 } 2151 } 2125 2126 // Hidden forums 2127 if ( ! current_user_can( 'read_hidden_forums' ) ) { 2128 $hidden = bbp_get_hidden_forum_ids(); 2129 } 2130 2131 // Merge private and hidden forums together 2132 $forum_ids = (array) array_filter( wp_parse_id_list( array_merge( $private, $hidden ) ) ); 2133 2134 // There are forums that need to be excluded 2135 if ( ! empty( $forum_ids ) ) { 2136 2137 switch ( $type ) { 2138 2139 // Separate forum ID's into a comma separated string 2140 case 'string' : 2141 $retval = implode( ',', $forum_ids ); 2142 break; 2143 2144 // Use forum_ids array 2145 case 'array' : 2146 $retval = $forum_ids; 2147 break; 2148 2149 // Build a meta_query 2150 case 'meta_query' : 2151 $retval = array( 2152 'key' => '_bbp_forum_id', 2153 'value' => implode( ',', $forum_ids ), 2154 'type' => 'NUMERIC', 2155 'compare' => ( 1 < count( $forum_ids ) ) ? 'NOT IN' : '!=' 2156 ); 2157 break; 2158 } 2159 } 2160 } 2161 2162 // Store return value in static types array 2163 $types[ $type ] = $retval; 2152 2164 } 2153 2165 … … 2399 2411 2400 2412 // If forum is explicitly hidden and user not capable, set 404 2401 if ( ! empty( $forum_id ) && bbp_is_forum_hidden( $forum_id ) && ! current_user_can( 'read_hidden_forums') ) {2413 if ( ! empty( $forum_id ) && bbp_is_forum_hidden( $forum_id ) && ! current_user_can( 'read_forum', $forum_id ) ) { 2402 2414 bbp_set_404(); 2403 2415 } … … 2454 2466 2455 2467 // If forum is explicitly hidden and user not capable, set 404 2456 if ( ! empty( $forum_id ) && bbp_is_forum_private( $forum_id ) && ! current_user_can( 'read_private_forums') ) {2468 if ( ! empty( $forum_id ) && bbp_is_forum_private( $forum_id ) && ! current_user_can( 'read_forum', $forum_id ) ) { 2457 2469 bbp_set_404(); 2458 2470 } … … 2462 2474 2463 2475 /** 2464 * Redirect if una thorized user is attempting to edit a forum2476 * Redirect if unauthorized user is attempting to edit a forum 2465 2477 * 2466 2478 * @since 2.1.0 bbPress (r3607)
Note: See TracChangeset
for help on using the changeset viewer.