Changeset 6384
- Timestamp:
- 03/20/2017 10:44:00 AM (8 years ago)
- Location:
- trunk/src
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/admin/replies.php
r6312 r6384 426 426 427 427 // Current user cannot edit this reply 428 if ( ! current_user_can( 'edit_reply', $reply_id ) ) {428 if ( ! current_user_can( 'edit_reply', $reply_id ) ) { 429 429 return $reply_id; 430 430 } … … 487 487 488 488 // What is the user doing here? 489 if ( ! current_user_can( 'moderate', $reply->ID ) ) {489 if ( ! current_user_can( 'moderate', $reply->ID ) ) { 490 490 wp_die( __( 'You do not have permission to do that.', 'bbpress' ) ); 491 491 } -
trunk/src/includes/admin/topics.php
r6334 r6384 550 550 551 551 // Bail if current user cannot edit this topic 552 if ( ! current_user_can( 'edit_topic', $topic_id ) ) {552 if ( ! current_user_can( 'edit_topic', $topic_id ) ) { 553 553 return $topic_id; 554 554 } … … 617 617 618 618 // What is the user doing here? 619 if ( ! current_user_can( 'moderate', $topic->ID ) ) {619 if ( ! current_user_can( 'moderate', $topic->ID ) ) { 620 620 wp_die( __( 'You do not have permission to do that.', 'bbpress' ) ); 621 621 } … … 979 979 // Close 980 980 // Show the 'close' and 'open' link on published and closed posts only 981 if ( in_array( $topic->post_status, array( bbp_get_public_status_id(), bbp_get_closed_status_id() )) ) {981 if ( bbp_is_topic_public( $topic->ID ) ) { 982 982 $close_uri = wp_nonce_url( add_query_arg( array( 'topic_id' => $topic->ID, 'action' => 'bbp_toggle_topic_close' ), remove_query_arg( array( 'bbp_topic_toggle_notice', 'topic_id', 'failed', 'super' ) ) ), 'close-topic_' . $topic->ID ); 983 983 if ( bbp_is_topic_open( $topic->ID ) ) { -
trunk/src/includes/common/classes.php
r6317 r6384 255 255 && ( bbp_get_forum_post_type() === $object->post_type ) 256 256 && ( bbp_is_forum_category( $object->ID ) 257 || ( ! current_user_can( 'edit_forum', $object->ID ) && bbp_is_forum_closed( $object->ID )257 || ( ! current_user_can( 'edit_forum', $object->ID ) && bbp_is_forum_closed( $object->ID ) 258 258 ) 259 259 ) ) { -
trunk/src/includes/common/functions.php
r6298 r6384 564 564 $last_posted = get_transient( '_bbp_' . bbp_current_author_ip() . '_last_posted' ); 565 565 566 if ( ! empty( $last_posted ) && time() < $last_posted + $throttle_time) {566 if ( ! empty( $last_posted ) && ( time() < ( $last_posted + $throttle_time ) ) ) { 567 567 return false; 568 568 } … … 573 573 $last_posted = bbp_get_user_last_posted( $author_id ); 574 574 575 if ( isset( $last_posted ) && time() < $last_posted + $throttle_time && !current_user_can('throttle' ) ) {575 if ( isset( $last_posted ) && ( time() < ( $last_posted + $throttle_time ) ) && ! user_can( $author_id, 'throttle' ) ) { 576 576 return false; 577 577 } … … 1775 1775 'post_type' => bbp_get_reply_post_type(), 1776 1776 'post_parent' => 'any', 1777 'post_status' => array( bbp_get_public_status_id(), bbp_get_closed_status_id()),1777 'post_status' => bbp_get_public_topic_statuses(), 1778 1778 'posts_per_page' => bbp_get_replies_per_rss_page(), 1779 1779 'order' => 'DESC', … … 1793 1793 'post_type' => bbp_get_topic_post_type(), 1794 1794 'post_parent' => bbp_get_forum_id(), 1795 'post_status' => array( bbp_get_public_status_id(), bbp_get_closed_status_id()),1795 'post_status' => bbp_get_public_topic_statuses(), 1796 1796 'posts_per_page' => bbp_get_topics_per_rss_page(), 1797 1797 'order' => 'DESC' … … 1815 1815 'post_type' => array( bbp_get_reply_post_type(), bbp_get_topic_post_type() ), 1816 1816 'post_parent' => 'any', 1817 'post_status' => array( bbp_get_public_status_id(), bbp_get_closed_status_id()),1817 'post_status' => bbp_get_public_topic_statuses(), 1818 1818 'posts_per_page' => bbp_get_replies_per_rss_page(), 1819 1819 'order' => 'DESC', -
trunk/src/includes/common/widgets.php
r6196 r6384 746 746 'post_parent' => $settings['parent_forum'], 747 747 'posts_per_page' => (int) $settings['max_shown'], 748 'post_status' => array( bbp_get_public_status_id(), bbp_get_closed_status_id()),748 'post_status' => bbp_get_public_topic_statuses(), 749 749 'ignore_sticky_posts' => true, 750 750 'no_found_rows' => true, … … 762 762 'post_parent' => $settings['parent_forum'], 763 763 'posts_per_page' => (int) $settings['max_shown'], 764 'post_status' => array( bbp_get_public_status_id(), bbp_get_closed_status_id()),764 'post_status' => bbp_get_public_topic_statuses(), 765 765 'ignore_sticky_posts' => true, 766 766 'no_found_rows' => true, … … 779 779 'post_parent' => $settings['parent_forum'], 780 780 'posts_per_page' => (int) $settings['max_shown'], 781 'post_status' => array( bbp_get_public_status_id(), bbp_get_closed_status_id()),781 'post_status' => bbp_get_public_topic_statuses(), 782 782 'ignore_sticky_posts' => true, 783 783 'no_found_rows' => true, … … 1131 1131 $widget_query = new WP_Query( array( 1132 1132 'post_type' => bbp_get_reply_post_type(), 1133 'post_status' => array( bbp_get_public_status_id(), bbp_get_closed_status_id()),1133 'post_status' => bbp_get_public_topic_statuses(), 1134 1134 'posts_per_page' => (int) $settings['max_shown'], 1135 1135 'ignore_sticky_posts' => true, -
trunk/src/includes/extend/buddypress/activity.php
r6372 r6384 448 448 449 449 // Validate activity data 450 $user_id = (int) $topic_author_id;450 $user_id = bbp_get_user_id( $topic_author_id ); 451 451 $topic_id = bbp_get_topic_id( $topic_id ); 452 452 $forum_id = bbp_get_forum_id( $forum_id ); … … 548 548 549 549 // Action based on new status 550 if ( in_array( $post->post_status, array( bbp_get_public_status_id(), bbp_get_closed_status_id() )) ) {550 if ( bbp_is_topic_public( $post->ID ) ) { 551 551 552 552 // Validate topic data … … 597 597 598 598 // Validate activity data 599 $user_id = (int) $reply_author_id;599 $user_id = bbp_get_user_id( $reply_author_id ); 600 600 $reply_id = bbp_get_reply_id( $reply_id ); 601 601 $topic_id = bbp_get_topic_id( $topic_id ); -
trunk/src/includes/extend/buddypress/notifications.php
r6262 r6384 196 196 197 197 // Check current user's ability to edit the user 198 } elseif ( ! current_user_can( 'edit_user', $user_id ) ) {198 } elseif ( ! current_user_can( 'edit_user', $user_id ) ) { 199 199 bbp_add_error( 'bbp_notification_permission', __( '<strong>ERROR</strong>: You do not have permission to mark notifications for that user.', 'bbpress' ) ); 200 200 } -
trunk/src/includes/forums/capabilities.php
r6221 r6384 85 85 $caps = array( 'spectate' ); 86 86 87 // Unknown so map to private posts 87 // Moderators can always read forum content 88 } elseif ( user_can( $user_id, 'moderate', $_post->ID ) ) { 89 $caps = array( 'spectate' ); 90 91 // Private 92 } elseif ( bbp_get_hidden_status_id() === $_post->post_status ) { 93 $caps = array( $post_type->cap->read_hidden_posts ); 94 95 // Hidden 96 } elseif ( bbp_get_private_status_id() === $_post->post_status ) { 97 $caps = array( $post_type->cap->read_private_posts ); 98 99 // Unknown, so map to private 88 100 } else { 89 101 $caps = array( $post_type->cap->read_private_posts ); … … 131 143 // Get caps for post type object 132 144 $post_type = get_post_type_object( $_post->post_type ); 133 $caps = array();134 145 135 146 // Add 'do_not_allow' cap if user is spam or deleted 136 147 if ( bbp_is_user_inactive( $user_id ) ) { 137 $caps [] = 'do_not_allow';148 $caps = array( 'do_not_allow' ); 138 149 139 150 // User is author so allow edit if not in admin 140 151 } elseif ( ! is_admin() && ( (int) $user_id === (int) $_post->post_author ) ) { 141 $caps[] = $post_type->cap->edit_posts; 152 $caps = array( $post_type->cap->edit_posts ); 153 154 // Moderators can always read forum content 155 } elseif ( user_can( $user_id, 'moderate', $_post->ID ) ) { 156 $caps = array( 'spectate' ); 142 157 143 158 // Unknown, so map to edit_others_posts 144 159 } else { 145 $caps [] = $post_type->cap->edit_others_posts;160 $caps = array( $post_type->cap->edit_others_posts ); 146 161 } 147 162 } … … 160 175 // Get caps for post type object 161 176 $post_type = get_post_type_object( $_post->post_type ); 162 $caps = array();163 177 164 178 // Add 'do_not_allow' cap if user is spam or deleted 165 179 if ( bbp_is_user_inactive( $user_id ) ) { 166 $caps [] = 'do_not_allow';180 $caps = array( 'do_not_allow' ); 167 181 168 182 // User is author so allow to delete 169 183 } elseif ( (int) $user_id === (int) $_post->post_author ) { 170 $caps [] = $post_type->cap->delete_posts;184 $caps = array( $post_type->cap->delete_posts ); 171 185 172 186 // Unknown so map to delete_others_posts 173 187 } else { 174 $caps [] = $post_type->cap->delete_others_posts;188 $caps = array( $post_type->cap->delete_others_posts ); 175 189 } 176 190 } -
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) -
trunk/src/includes/forums/template.php
r6357 r6384 694 694 // Use passed integer as post_parent 695 695 if ( is_numeric( $args ) ) { 696 $args = array( 'post_parent' => $args);696 $args = array( 'post_parent' => bbp_get_forum_id( $args ) ); 697 697 } 698 698 … … 729 729 'no_found_rows' => true 730 730 ), 'forum_get_subforums' ); 731 732 // Ensure post_parent is properly set 731 733 $r['post_parent'] = bbp_get_forum_id( $r['post_parent'] ); 732 734 … … 735 737 736 738 // No forum passed 737 $sub_forums = ! empty( $r['post_parent'] ) ? $get_posts->query( $r ) : array(); 739 $sub_forums = ! empty( $r['post_parent'] ) 740 ? $get_posts->query( $r ) 741 : array(); 738 742 739 743 return (array) apply_filters( 'bbp_forum_get_subforums', $sub_forums, $r, $args ); … … 1301 1305 1302 1306 // Hidden link 1303 $retval .= ! bbp_get_view_all( )1307 $retval .= ! bbp_get_view_all( 'edit_others_topics' ) 1304 1308 ? " <a href='" . esc_url( bbp_add_view_all( $link, true ) ) . "'>" . esc_html( $extra ) . "</a>" 1305 1309 : " {$extra}"; … … 1944 1948 */ 1945 1949 function bbp_suppress_private_forum_meta( $retval, $forum_id ) { 1946 if ( bbp_is_forum_private( $forum_id, false ) && ! current_user_can( 'read_ private_forums') ) {1950 if ( bbp_is_forum_private( $forum_id, false ) && ! current_user_can( 'read_forum', $forum_id ) ) { 1947 1951 $retval = '-'; 1948 1952 } … … 1978 1982 1979 1983 // What post type are we looking at? 1980 $post_type = get_post_field( 'post_type', $args['post_id'] ); 1981 1982 switch ( $post_type ) { 1984 switch ( get_post_type( $args['post_id'] ) ) { 1983 1985 1984 1986 // Topic 1985 1987 case bbp_get_topic_post_type() : 1986 if ( bbp_is_forum_private( bbp_get_topic_forum_id( $args['post_id'] ) ) ) { 1987 $retval = ''; 1988 } 1989 1988 $forum_id = bbp_get_topic_forum_id( $args['post_id'] ); 1990 1989 break; 1991 1990 1992 1991 // Reply 1993 1992 case bbp_get_reply_post_type() : 1994 if ( bbp_is_forum_private( bbp_get_reply_forum_id( $args['post_id'] ) ) ) { 1995 $retval = ''; 1996 } 1997 1993 $forum_id = bbp_get_reply_forum_id( $args['post_id'] ); 1998 1994 break; 1999 1995 2000 1996 // Post 2001 1997 default : 2002 if ( bbp_is_forum_private( $args['post_id'] ) ) { 2003 $retval = ''; 2004 } 2005 1998 $forum_id = bbp_get_forum_id( $args['post_id'] ); 2006 1999 break; 2007 2000 } 2008 } 2009 2010 return apply_filters( 'bbp_suppress_private_author_link', $retval ); 2001 2002 // Hide if forum is private 2003 if ( bbp_is_forum_private( $forum_id ) ) { 2004 $retval = ''; 2005 } 2006 } 2007 2008 return apply_filters( 'bbp_suppress_private_author_link', $retval, $author_link, $args ); 2011 2009 } 2012 2010 -
trunk/src/includes/replies/capabilities.php
r6265 r6384 78 78 $caps = array( 'spectate' ); 79 79 80 // Moderators can always edit forum content 81 } elseif ( user_can( $user_id, 'moderate', $_post->ID ) ) { 82 $caps = array( 'spectate' ); 83 80 84 // Unknown so map to private posts 81 85 } else { … … 108 112 $caps = array( 'moderate' ); 109 113 110 // Otherwise, block114 // Otherwise, check forum 111 115 } else { 112 $caps = array( 'do_not_allow' ); 116 $forum_id = bbp_get_forum_id(); 117 118 // Moderators can always edit forum content 119 if ( user_can( $user_id, 'moderate', $forum_id ) ) { 120 $caps = array( 'spectate' ); 121 122 // Fallback to do_not_allow 123 } else { 124 $caps = array( 'do_not_allow' ); 125 } 113 126 } 114 127 … … 124 137 // Get post type object 125 138 $post_type = get_post_type_object( $_post->post_type ); 126 $caps = array();127 139 128 140 // Add 'do_not_allow' cap if user is spam or deleted 129 141 if ( bbp_is_user_inactive( $user_id ) ) { 130 $caps [] = 'do_not_allow';142 $caps = array( 'do_not_allow' ); 131 143 132 144 // User is author so allow edit if not in admin 133 145 } elseif ( ! is_admin() && ( (int) $user_id === (int) $_post->post_author ) ) { 134 $caps [] = $post_type->cap->edit_posts;135 136 // User is a per-forum moderator, make sure they can spectate.137 } elseif ( bbp_is_user_forum_moderator( $user_id, bbp_get_reply_forum_id( $_post->ID )) ) {146 $caps = array( $post_type->cap->edit_posts ); 147 148 // Moderators can always edit forum content 149 } elseif ( user_can( $user_id, 'moderate', $_post->ID ) ) { 138 150 $caps = array( 'spectate' ); 139 151 140 152 // Fallback to edit_others_posts. 141 153 } else { 142 $caps [] = $post_type->cap->edit_others_posts;154 $caps = array( $post_type->cap->edit_others_posts ); 143 155 } 144 156 } … … 156 168 // Get post type object 157 169 $post_type = get_post_type_object( $_post->post_type ); 158 $caps = array();159 170 160 171 // Add 'do_not_allow' cap if user is spam or deleted 161 172 if ( bbp_is_user_inactive( $user_id ) ) { 162 $caps[] = 'do_not_allow'; 163 164 // Moderators can always edit forum content 165 } elseif ( user_can( $user_id, 'moderate' ) ) { 166 $caps[] = 'moderate'; 173 $caps = array( 'do_not_allow' ); 167 174 168 175 // User is author so allow delete if not in admin 169 176 } elseif ( ! is_admin() && ( (int) $user_id === (int) $_post->post_author ) ) { 170 $caps[] = $post_type->cap->delete_posts; 177 $caps = array( $post_type->cap->delete_posts ); 178 179 // Moderators can always edit forum content 180 } elseif ( user_can( $user_id, 'moderate', $_post->ID ) ) { 181 $caps = array( 'spectate' ); 171 182 172 183 // Unknown so map to delete_others_posts 173 184 } else { 174 $caps [] = $post_type->cap->delete_others_posts;185 $caps = array( $post_type->cap->delete_others_posts ); 175 186 } 176 187 } -
trunk/src/includes/replies/functions.php
r6369 r6384 179 179 180 180 // User cannot create replies 181 if ( ! current_user_can( 'publish_replies' ) ) {181 if ( ! current_user_can( 'publish_replies' ) ) { 182 182 bbp_add_error( 'bbp_reply_permission', __( '<strong>ERROR</strong>: You do not have permission to reply.', 'bbpress' ) ); 183 183 } … … 271 271 272 272 // Forum is closed and user cannot access 273 if ( bbp_is_forum_closed( $forum_id ) && ! current_user_can( 'edit_forum', $forum_id ) ) {273 if ( bbp_is_forum_closed( $forum_id ) && ! current_user_can( 'edit_forum', $forum_id ) ) { 274 274 bbp_add_error( 'bbp_new_reply_forum_closed', __( '<strong>ERROR</strong>: This forum has been closed to new replies.', 'bbpress' ) ); 275 275 } 276 276 277 277 // Forum is private and user cannot access 278 if ( bbp_is_forum_private( $forum_id ) ) { 279 if ( !current_user_can( 'read_private_forums' ) ) { 280 bbp_add_error( 'bbp_new_reply_forum_private', __( '<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new replies in it.', 'bbpress' ) ); 281 } 278 if ( bbp_is_forum_private( $forum_id ) && ! current_user_can( 'read_forum', $forum_id ) ) { 279 bbp_add_error( 'bbp_new_reply_forum_private', __( '<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new replies in it.', 'bbpress' ) ); 282 280 283 281 // Forum is hidden and user cannot access 284 } elseif ( bbp_is_forum_hidden( $forum_id ) ) { 285 if ( !current_user_can( 'read_hidden_forums' ) ) { 286 bbp_add_error( 'bbp_new_reply_forum_hidden', __( '<strong>ERROR</strong>: This forum is hidden and you do not have the capability to read or create new replies in it.', 'bbpress' ) ); 287 } 282 } elseif ( bbp_is_forum_hidden( $forum_id ) && ! current_user_can( 'read_forum', $forum_id ) ) { 283 bbp_add_error( 'bbp_new_reply_forum_hidden', __( '<strong>ERROR</strong>: This forum is hidden and you do not have the capability to read or create new replies in it.', 'bbpress' ) ); 288 284 } 289 285 } … … 572 568 573 569 // User cannot edit this reply 574 if ( ! current_user_can( 'edit_reply', $reply_id ) ) {570 if ( ! current_user_can( 'edit_reply', $reply_id ) ) { 575 571 bbp_add_error( 'bbp_edit_reply_permission', __( '<strong>ERROR</strong>: You do not have permission to edit that reply.', 'bbpress' ) ); 576 572 return; … … 614 610 615 611 // Forum is closed and user cannot access 616 if ( bbp_is_forum_closed( $forum_id ) && ! current_user_can( 'edit_forum', $forum_id ) ) {612 if ( bbp_is_forum_closed( $forum_id ) && ! current_user_can( 'edit_forum', $forum_id ) ) { 617 613 bbp_add_error( 'bbp_edit_reply_forum_closed', __( '<strong>ERROR</strong>: This forum has been closed to new replies.', 'bbpress' ) ); 618 614 } 619 615 620 616 // Forum is private and user cannot access 621 if ( bbp_is_forum_private( $forum_id ) ) { 622 if ( !current_user_can( 'read_private_forums' ) ) { 623 bbp_add_error( 'bbp_edit_reply_forum_private', __( '<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new replies in it.', 'bbpress' ) ); 624 } 617 if ( bbp_is_forum_private( $forum_id ) && ! current_user_can( 'read_forum', $forum_id ) ) { 618 bbp_add_error( 'bbp_edit_reply_forum_private', __( '<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new replies in it.', 'bbpress' ) ); 625 619 626 620 // Forum is hidden and user cannot access 627 } elseif ( bbp_is_forum_hidden( $forum_id ) ) { 628 if ( !current_user_can( 'read_hidden_forums' ) ) { 629 bbp_add_error( 'bbp_edit_reply_forum_hidden', __( '<strong>ERROR</strong>: This forum is hidden and you do not have the capability to read or create new replies in it.', 'bbpress' ) ); 630 } 621 } elseif ( bbp_is_forum_hidden( $forum_id ) && ! current_user_can( 'read_forum', $forum_id ) ) { 622 bbp_add_error( 'bbp_edit_reply_forum_hidden', __( '<strong>ERROR</strong>: This forum is hidden and you do not have the capability to read or create new replies in it.', 'bbpress' ) ); 631 623 } 632 624 } … … 889 881 890 882 } else { 891 if ( empty( $is_edit ) && ! current_user_can( 'throttle' ) ) {883 if ( empty( $is_edit ) && ! current_user_can( 'throttle' ) ) { 892 884 bbp_update_user_last_posted( $author_id ); 893 885 } … … 1362 1354 1363 1355 // Use cannot edit topic 1364 if ( ! current_user_can( 'edit_topic', $source_topic->ID ) ) {1356 if ( ! current_user_can( 'edit_topic', $source_topic->ID ) ) { 1365 1357 bbp_add_error( 'bbp_move_reply_source_permission', __( '<strong>ERROR</strong>: You do not have permission to edit the source topic.', 'bbpress' ) ); 1366 1358 } … … 1400 1392 1401 1393 // User cannot edit the destination topic 1402 if ( ! current_user_can( 'edit_topic', $destination_topic->ID ) ) {1394 if ( ! current_user_can( 'edit_topic', $destination_topic->ID ) ) { 1403 1395 bbp_add_error( 'bbp_move_reply_destination_permission', __( '<strong>ERROR</strong>: You do not have permission to edit the destination topic.', 'bbpress' ) ); 1404 1396 } -
trunk/src/includes/replies/template.php
r6363 r6384 151 151 152 152 // What are the default allowed statuses (based on user caps) 153 if ( bbp_get_view_all( ) ) {153 if ( bbp_get_view_all( 'edit_others_replies' ) ) { 154 154 155 155 // Default view=all statuses -
trunk/src/includes/topics/capabilities.php
r6265 r6384 96 96 $caps = array( 'spectate' ); 97 97 98 // Moderators can always edit forum content 99 } elseif ( user_can( $user_id, 'moderate', $_post->ID ) ) { 100 $caps = array( 'spectate' ); 101 98 102 // Unknown so map to private posts 99 103 } else { … … 126 130 $caps = array( $cap ); 127 131 128 // Otherwise, block132 // Otherwise, check forum 129 133 } else { 130 $caps = array( 'do_not_allow' ); 134 $forum_id = bbp_get_forum_id(); 135 136 // Moderators can always edit forum content 137 if ( user_can( $user_id, 'moderate', $forum_id ) ) { 138 $caps = array( 'spectate' ); 139 140 // Fallback to do_not_allow 141 } else { 142 $caps = array( 'do_not_allow' ); 143 } 131 144 } 132 145 … … 142 155 // Get caps for post type object 143 156 $post_type = get_post_type_object( $_post->post_type ); 144 $caps = array();145 157 146 158 // Add 'do_not_allow' cap if user is spam or deleted 147 159 if ( bbp_is_user_inactive( $user_id ) ) { 148 $caps [] = 'do_not_allow';160 $caps = array( 'do_not_allow' ); 149 161 150 162 // User is author so allow edit if not in admin 151 163 } elseif ( ! is_admin() && ( (int) $user_id === (int) $_post->post_author ) ) { 152 $caps[] = $post_type->cap->edit_posts; 164 $caps = array( $post_type->cap->edit_posts ); 165 166 // Moderators can always edit forum content 167 } elseif ( user_can( $user_id, 'moderate', $_post->ID ) ) { 168 $caps = array( 'spectate' ); 153 169 154 170 // Unknown, so map to edit_others_posts 155 171 } else { 156 157 // If user is a per-forum moderator, make sure they can spectate. 158 if ( bbp_is_user_forum_moderator( $user_id, bbp_get_topic_forum_id( $_post->ID ) ) ) { 159 $caps = array( 'spectate' ); 160 161 // Fallback to edit_others_posts. 162 } else { 163 $caps[] = $post_type->cap->edit_others_posts; 164 } 172 $caps = array( $post_type->cap->edit_others_posts ); 165 173 } 166 174 } … … 178 186 // Get caps for post type object 179 187 $post_type = get_post_type_object( $_post->post_type ); 180 $caps = array();181 188 182 189 // Add 'do_not_allow' cap if user is spam or deleted 183 190 if ( bbp_is_user_inactive( $user_id ) ) { 184 $caps [] = 'do_not_allow';191 $caps = array( 'do_not_allow' ); 185 192 186 193 // Moderators can always edit forum content 187 } elseif ( user_can( $user_id, 'moderate' ) ) {188 $caps [] = 'moderate';194 } elseif ( user_can( $user_id, 'moderate', $_post->ID ) ) { 195 $caps = array( 'spectate' ); 189 196 190 197 // User is author so allow delete if not in admin 191 198 } elseif ( ! is_admin() && ( (int) $user_id === (int) $_post->post_author ) ) { 192 $caps [] = $post_type->cap->delete_posts;199 $caps = array( $post_type->cap->delete_posts ); 193 200 194 201 // Unknown so map to delete_others_posts 195 202 } else { 196 $caps [] = $post_type->cap->delete_others_posts;203 $caps = array( $post_type->cap->delete_others_posts ); 197 204 } 198 205 } -
trunk/src/includes/topics/functions.php
r6341 r6384 260 260 261 261 // Forum is private and user cannot access 262 if ( bbp_is_forum_private( $forum_id ) ) { 263 if ( ! current_user_can( 'read_private_forums' ) ) { 264 bbp_add_error( 'bbp_new_topic_forum_private', __( '<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new topics in it.', 'bbpress' ) ); 265 } 262 if ( bbp_is_forum_private( $forum_id ) && ! current_user_can( 'read_forum', $forum_id ) ) { 263 bbp_add_error( 'bbp_new_topic_forum_private', __( '<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new topics in it.', 'bbpress' ) ); 266 264 267 265 // Forum is hidden and user cannot access 268 } elseif ( bbp_is_forum_hidden( $forum_id ) ) { 269 if ( ! current_user_can( 'read_hidden_forums' ) ) { 270 bbp_add_error( 'bbp_new_topic_forum_hidden', __( '<strong>ERROR</strong>: This forum is hidden and you do not have the capability to read or create new topics in it.', 'bbpress' ) ); 271 } 266 } elseif ( bbp_is_forum_hidden( $forum_id ) && ! current_user_can( 'read_forum', $forum_id ) ) { 267 bbp_add_error( 'bbp_new_topic_forum_hidden', __( '<strong>ERROR</strong>: This forum is hidden and you do not have the capability to read or create new topics in it.', 'bbpress' ) ); 272 268 } 273 269 } … … 562 558 563 559 // Forum is private and user cannot access 564 if ( bbp_is_forum_private( $forum_id ) ) { 565 if ( ! current_user_can( 'read_private_forums' ) ) { 566 bbp_add_error( 'bbp_edit_topic_forum_private', __( '<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new topics in it.', 'bbpress' ) ); 567 } 560 if ( bbp_is_forum_private( $forum_id ) && ! current_user_can( 'read_forum', $forum_id ) ) { 561 bbp_add_error( 'bbp_edit_topic_forum_private', __( '<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new topics in it.', 'bbpress' ) ); 568 562 569 563 // Forum is hidden and user cannot access 570 } elseif ( bbp_is_forum_hidden( $forum_id ) ) { 571 if ( ! current_user_can( 'read_hidden_forums' ) ) { 572 bbp_add_error( 'bbp_edit_topic_forum_hidden', __( '<strong>ERROR</strong>: This forum is hidden and you do not have the capability to read or create new topics in it.', 'bbpress' ) ); 573 } 564 } elseif ( bbp_is_forum_hidden( $forum_id ) && ! current_user_can( 'read_forum', $forum_id ) ) { 565 bbp_add_error( 'bbp_edit_topic_forum_hidden', __( '<strong>ERROR</strong>: This forum is hidden and you do not have the capability to read or create new topics in it.', 'bbpress' ) ); 574 566 } 575 567 } … … 619 611 620 612 // Set post status to pending if public or closed 621 if ( in_array( $topic->post_status, array( bbp_get_public_status_id(), bbp_get_closed_status_id() )) ) {613 if ( bbp_is_topic_public( $topic->ID ) ) { 622 614 $topic_status = bbp_get_pending_status_id(); 623 615 } … … 746 738 747 739 // View all? 748 $view_all = bbp_get_view_all( );740 $view_all = bbp_get_view_all( 'edit_others_replies' ); 749 741 750 742 // Get the topic URL -
trunk/src/includes/topics/template.php
r6362 r6384 173 173 174 174 // What are the default allowed statuses (based on user caps) 175 if ( bbp_get_view_all( ) ) {175 if ( bbp_get_view_all( 'edit_others_topics' ) ) { 176 176 177 177 // Default view=all statuses … … 310 310 311 311 // What are the default allowed statuses (based on user caps) 312 if ( bbp_get_view_all( ) ) {312 if ( bbp_get_view_all( 'edit_others_topics' ) ) { 313 313 $sticky_query['post_status'] = $r['post_status']; 314 314 … … 900 900 } 901 901 902 // Maybe add view-all args 903 $add_args = bbp_get_view_all( 'edit_others_replies' ) 904 ? array( 'view' => 'all' ) 905 : false; 906 902 907 // Add pagination to query object 903 908 $pagination_links = paginate_links( array( … … 909 914 'mid_size' => 2, 910 915 'end_size' => 3, 911 'add_args' => ( bbp_get_view_all() ) ? array( 'view' => 'all' ) : false916 'add_args' => $add_args 912 917 ) ); 913 918 … … 1163 1168 1164 1169 /** 1170 * Return array of public topic statuses. 1171 * 1172 * @since 2.6.0 bbPress (r6383) 1173 * 1174 * @uses bbp_get_public_status_id() 1175 * @uses bbp_get_closed_status_id() 1176 * 1177 * @return array 1178 */ 1179 function bbp_get_public_topic_statuses() { 1180 $statuses = bbp_get_public_topic_statuses(); 1181 1182 return (array) apply_filters( 'bbp_get_public_topic_statuses', $statuses ); 1183 } 1184 1185 /** 1165 1186 * Is the topic closed to new replies? 1166 1187 * … … 1197 1218 1198 1219 /** 1199 * Is the topic not spam or deleted? 1220 * Is the topic publicly viewable? 1221 * 1222 * @since 2.6.0 bbPress (r6383) 1223 * 1224 * @param int $topic_id Optional. Topic id 1225 * @uses bbp_get_topic_id() To get the topic id 1226 * @uses bbp_get_topic_status() To get the topic status 1227 * @uses apply_filters() Calls 'bbp_is_topic_public' with the topic id 1228 * @return bool True if public, false if not. 1229 */ 1230 function bbp_is_topic_public( $topic_id = 0 ) { 1231 $topic_id = bbp_get_topic_id( $topic_id ); 1232 $status = bbp_get_topic_status( $topic_id ); 1233 $public = bbp_get_public_topic_statuses(); 1234 $is_public = in_array( $status, $public, true ); 1235 1236 return (bool) apply_filters( 'bbp_is_topic_public', (bool) $is_public, $topic_id ); 1237 } 1238 1239 /** 1240 * Does the topic have a published status? 1200 1241 * 1201 1242 * @since 2.0.0 bbPress (r3496) … … 2241 2282 2242 2283 // Hidden link 2243 $retval .= ! bbp_get_view_all( )2284 $retval .= ! bbp_get_view_all( 'edit_others_replies' ) 2244 2285 ? " <a href='" . esc_url( bbp_add_view_all( $link, true ) ) . "'>" . esc_html( $extra ) . "</a>" 2245 2286 : " {$extra}"; -
trunk/src/includes/users/capabilities.php
r6294 r6384 85 85 // Forum. 86 86 case bbp_get_forum_post_type() : 87 $forum_id = $_post->ID;87 $forum_id = bbp_get_forum_id( $_post->ID ); 88 88 break; 89 89 -
trunk/src/includes/users/template.php
r6335 r6384 2153 2153 2154 2154 // Forum is private, and user can see it 2155 } elseif ( bbp_is_forum_private( $forum_id, $r['check_ancestors'] ) && user_can( $user_id, 'read_ private_forums') ) {2155 } elseif ( bbp_is_forum_private( $forum_id, $r['check_ancestors'] ) && user_can( $user_id, 'read_forum', $forum_id ) ) { 2156 2156 $retval = true; 2157 2157 2158 2158 // Forum is hidden, and user can see it 2159 } elseif ( bbp_is_forum_hidden ( $forum_id, $r['check_ancestors'] ) && user_can( $user_id, 'read_ hidden_forums') ) {2159 } elseif ( bbp_is_forum_hidden ( $forum_id, $r['check_ancestors'] ) && user_can( $user_id, 'read_forum', $forum_id ) ) { 2160 2160 $retval = true; 2161 2161 } -
trunk/src/templates/default/bbpress/form-topic-merge.php
r6258 r6384 53 53 'post_type' => bbp_get_topic_post_type(), 54 54 'post_parent' => bbp_get_topic_forum_id( bbp_get_topic_id() ), 55 'post_status' => array( bbp_get_public_status_id(), bbp_get_closed_status_id()),55 'post_status' => bbp_get_public_topic_statuses(), 56 56 'selected' => -1, 57 57 'exclude' => bbp_get_topic_id(), -
trunk/src/templates/default/bbpress/form-topic-split.php
r6258 r6384 60 60 'post_type' => bbp_get_topic_post_type(), 61 61 'post_parent' => bbp_get_topic_forum_id( bbp_get_topic_id() ), 62 'post_status' => array( bbp_get_public_status_id(), bbp_get_closed_status_id()),62 'post_status' => bbp_get_public_topic_statuses(), 63 63 'selected' => -1, 64 64 'exclude' => bbp_get_topic_id(),
Note: See TracChangeset
for help on using the changeset viewer.