Changeset 6783
- Timestamp:
- 02/16/2018 10:18:00 PM (7 years ago)
- Location:
- trunk/src/includes
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/forums/capabilities.php
r6667 r6783 68 68 } else { 69 69 70 // Get the post 70 // Bail if no post ID 71 if ( empty( $args[0] ) ) { 72 return $caps; 73 } 74 75 // Get the post. 71 76 $_post = get_post( $args[0] ); 72 77 if ( ! empty( $_post ) ) { … … 108 113 case 'moderate_forum' : 109 114 110 // Get the post 115 // Bail if no post ID 116 if ( empty( $args[0] ) ) { 117 return $caps; 118 } 119 120 // Get the post. 111 121 $_post = get_post( $args[0] ); 112 122 if ( ! empty( $_post ) && bbp_allow_forum_mods() ) { … … 151 161 case 'edit_forum' : 152 162 153 // Get the post 163 // Bail if no post ID 164 if ( empty( $args[0] ) ) { 165 return $caps; 166 } 167 168 // Get the post. 154 169 $_post = get_post( $args[0] ); 155 170 if ( ! empty( $_post ) ) { … … 183 198 case 'delete_forum' : 184 199 185 // Get the post 200 // Bail if no post ID 201 if ( empty( $args[0] ) ) { 202 return $caps; 203 } 204 205 // Get the post. 186 206 $_post = get_post( $args[0] ); 187 207 if ( ! empty( $_post ) ) { -
trunk/src/includes/replies/capabilities.php
r6713 r6783 35 35 * @since 2.2.0 bbPress (r4242) 36 36 * 37 * @param array $caps Capabilities for meta capability38 * @param string $cap Capability name39 * @param int $user_id User id40 * @param array $args Arguments37 * @param array $caps Capabilities for meta capability. 38 * @param string $cap Capability name. 39 * @param int $user_id User id. 40 * @param array $args Arguments. 41 41 * 42 42 * @return array Actual capabilities for meta capability … … 58 58 } else { 59 59 60 // Get the post 60 // Bail if no post ID 61 if ( empty( $args[0] ) ) { 62 return $caps; 63 } 64 65 // Get the post. 61 66 $_post = get_post( $args[0] ); 62 67 if ( ! empty( $_post ) ) { … … 126 131 case 'edit_reply' : 127 132 128 // Get the post 133 // Bail if no post ID 134 if ( empty( $args[0] ) ) { 135 return $caps; 136 } 137 138 // Get the post. 129 139 $_post = get_post( $args[0] ); 130 140 if ( ! empty( $_post ) ) { … … 161 171 case 'delete_reply' : 162 172 173 // Bail if no post ID 174 if ( empty( $args[0] ) ) { 175 return $caps; 176 } 177 163 178 // Get the post 164 179 $_post = get_post( $args[0] ); -
trunk/src/includes/topics/capabilities.php
r6720 r6783 55 55 * @since 2.2.0 bbPress (r4242) 56 56 * 57 * @param array $caps Capabilities for meta capability. 58 * @param string $cap Capability name. 59 * @param int $user_id User id. 60 * @param array $args Arguments. 61 * 62 * @return array Actual capabilities for meta capability 63 */ 64 function bbp_map_topic_meta_caps( $caps = array(), $cap = '', $user_id = 0, $args = array() ) { 65 66 // What capability is being checked? 67 switch ( $cap ) { 68 69 /** Reading ***********************************************************/ 70 71 case 'read_topic' : 72 73 // User cannot spectate 74 if ( ! user_can( $user_id, 'spectate' ) ) { 75 $caps = array( 'do_not_allow' ); 76 77 // Do some post ID based logic 78 } else { 79 80 // Bail if no post ID 81 if ( empty( $args[0] ) ) { 82 return $caps; 83 } 84 85 // Get the post. 86 $_post = get_post( $args[0] ); 87 if ( ! empty( $_post ) ) { 88 89 // Get caps for post type object 90 $post_type = get_post_type_object( $_post->post_type ); 91 92 // Post is public 93 if ( bbp_get_public_status_id() === $_post->post_status ) { 94 $caps = array( 'spectate' ); 95 96 // User is author so allow read 97 } elseif ( (int) $user_id === (int) $_post->post_author ) { 98 $caps = array( 'spectate' ); 99 100 // Moderators can always edit forum content 101 } elseif ( user_can( $user_id, 'moderate', $_post->ID ) ) { 102 $caps = array( 'spectate' ); 103 104 // Unknown so map to private posts 105 } else { 106 $caps = array( $post_type->cap->read_private_posts ); 107 } 108 } 109 } 110 111 break; 112 113 /** Publishing ********************************************************/ 114 115 case 'publish_topics' : 116 117 // Moderators can always publish 118 if ( user_can( $user_id, 'moderate' ) ) { 119 $caps = array( 'moderate' ); 120 } 121 122 break; 123 124 /** Editing ***********************************************************/ 125 126 // Used primarily in wp-admin 127 case 'edit_topics' : 128 case 'edit_others_topics' : 129 130 // Moderators can always edit 131 if ( user_can( $user_id, 'moderate' ) ) { 132 $caps = array( $cap ); 133 134 // Otherwise, check forum 135 } else { 136 $forum_id = bbp_get_forum_id(); 137 138 // Moderators can always edit forum content 139 if ( user_can( $user_id, 'moderate', $forum_id ) ) { 140 $caps = array( 'spectate' ); 141 142 // Fallback to do_not_allow 143 } else { 144 $caps = array( 'do_not_allow' ); 145 } 146 } 147 148 break; 149 150 // Used everywhere 151 case 'edit_topic' : 152 153 // Bail if no post ID 154 if ( empty( $args[0] ) ) { 155 return $caps; 156 } 157 158 // Get the post. 159 $_post = get_post( $args[0] ); 160 if ( ! empty( $_post ) ) { 161 162 // Get caps for post type object 163 $post_type = get_post_type_object( $_post->post_type ); 164 165 // Add 'do_not_allow' cap if user is spam or deleted 166 if ( bbp_is_user_inactive( $user_id ) ) { 167 $caps = array( 'do_not_allow' ); 168 169 // Moderators can always edit forum content 170 } elseif ( user_can( $user_id, 'moderate', $_post->ID ) ) { 171 $caps = array( 'spectate' ); 172 173 // User is author so allow edit if not in admin, unless it's past edit lock time 174 } elseif ( ! is_admin() && ( (int) $user_id === (int) $_post->post_author ) ) { 175 176 // Only allow if not past the edit-lock period 177 $caps = ! bbp_past_edit_lock( $_post->post_date_gmt ) 178 ? array( $post_type->cap->edit_posts ) 179 : array( 'do_not_allow' ); 180 181 // Unknown, so map to edit_others_posts 182 } else { 183 $caps = array( $post_type->cap->edit_others_posts ); 184 } 185 } 186 187 break; 188 189 /** Deleting **********************************************************/ 190 191 case 'delete_topic' : 192 193 // Bail if no post ID 194 if ( empty( $args[0] ) ) { 195 return $caps; 196 } 197 198 // Get the post. 199 $_post = get_post( $args[0] ); 200 if ( ! empty( $_post ) ) { 201 202 // Get caps for post type object 203 $post_type = get_post_type_object( $_post->post_type ); 204 205 // Add 'do_not_allow' cap if user is spam or deleted 206 if ( bbp_is_user_inactive( $user_id ) ) { 207 $caps = array( 'do_not_allow' ); 208 209 // Moderators can always edit forum content 210 } elseif ( user_can( $user_id, 'moderate', $_post->ID ) ) { 211 $caps = array( 'spectate' ); 212 213 // User is author so allow delete if not in admin 214 } elseif ( ! is_admin() && ( (int) $user_id === (int) $_post->post_author ) ) { 215 $caps = array( $post_type->cap->delete_posts ); 216 217 // Unknown so map to delete_others_posts 218 } else { 219 $caps = array( $post_type->cap->delete_others_posts ); 220 } 221 } 222 223 break; 224 225 // Moderation override 226 case 'delete_topics' : 227 case 'delete_others_topics' : 228 229 // Moderators can always delete 230 if ( user_can( $user_id, 'moderate' ) ) { 231 $caps = array( $cap ); 232 } 233 234 break; 235 236 /** Admin *************************************************************/ 237 238 case 'bbp_topics_admin' : 239 $caps = array( 'edit_topics' ); 240 break; 241 } 242 243 // Filter & return 244 return (array) apply_filters( 'bbp_map_topic_meta_caps', $caps, $cap, $user_id, $args ); 245 } 246 247 /** 248 * Maps topic tag capabilities 249 * 250 * @since 2.2.0 bbPress (r4242) 251 * 57 252 * @param array $caps Capabilities for meta capability 58 253 * @param string $cap Capability name … … 62 257 * @return array Actual capabilities for meta capability 63 258 */ 64 function bbp_map_topic_meta_caps( $caps = array(), $cap = '', $user_id = 0, $args = array() ) {65 66 // What capability is being checked?67 switch ( $cap ) {68 69 /** Reading ***********************************************************/70 71 case 'read_topic' :72 73 // User cannot spectate74 if ( ! user_can( $user_id, 'spectate' ) ) {75 $caps = array( 'do_not_allow' );76 77 // Do some post ID based logic78 } else {79 80 // Get the post81 $_post = get_post( $args[0] );82 if ( ! empty( $_post ) ) {83 84 // Get caps for post type object85 $post_type = get_post_type_object( $_post->post_type );86 87 // Post is public88 if ( bbp_get_public_status_id() === $_post->post_status ) {89 $caps = array( 'spectate' );90 91 // User is author so allow read92 } elseif ( (int) $user_id === (int) $_post->post_author ) {93 $caps = array( 'spectate' );94 95 // Moderators can always edit forum content96 } elseif ( user_can( $user_id, 'moderate', $_post->ID ) ) {97 $caps = array( 'spectate' );98 99 // Unknown so map to private posts100 } else {101 $caps = array( $post_type->cap->read_private_posts );102 }103 }104 }105 106 break;107 108 /** Publishing ********************************************************/109 110 case 'publish_topics' :111 112 // Moderators can always publish113 if ( user_can( $user_id, 'moderate' ) ) {114 $caps = array( 'moderate' );115 }116 117 break;118 119 /** Editing ***********************************************************/120 121 // Used primarily in wp-admin122 case 'edit_topics' :123 case 'edit_others_topics' :124 125 // Moderators can always edit126 if ( user_can( $user_id, 'moderate' ) ) {127 $caps = array( $cap );128 129 // Otherwise, check forum130 } else {131 $forum_id = bbp_get_forum_id();132 133 // Moderators can always edit forum content134 if ( user_can( $user_id, 'moderate', $forum_id ) ) {135 $caps = array( 'spectate' );136 137 // Fallback to do_not_allow138 } else {139 $caps = array( 'do_not_allow' );140 }141 }142 143 break;144 145 // Used everywhere146 case 'edit_topic' :147 148 // Get the post149 $_post = get_post( $args[0] );150 if ( ! empty( $_post ) ) {151 152 // Get caps for post type object153 $post_type = get_post_type_object( $_post->post_type );154 155 // Add 'do_not_allow' cap if user is spam or deleted156 if ( bbp_is_user_inactive( $user_id ) ) {157 $caps = array( 'do_not_allow' );158 159 // Moderators can always edit forum content160 } elseif ( user_can( $user_id, 'moderate', $_post->ID ) ) {161 $caps = array( 'spectate' );162 163 // User is author so allow edit if not in admin, unless it's past edit lock time164 } elseif ( ! is_admin() && ( (int) $user_id === (int) $_post->post_author ) ) {165 166 // Only allow if not past the edit-lock period167 $caps = ! bbp_past_edit_lock( $_post->post_date_gmt )168 ? array( $post_type->cap->edit_posts )169 : array( 'do_not_allow' );170 171 // Unknown, so map to edit_others_posts172 } else {173 $caps = array( $post_type->cap->edit_others_posts );174 }175 }176 177 break;178 179 /** Deleting **********************************************************/180 181 case 'delete_topic' :182 183 // Get the post184 $_post = get_post( $args[0] );185 if ( ! empty( $_post ) ) {186 187 // Get caps for post type object188 $post_type = get_post_type_object( $_post->post_type );189 190 // Add 'do_not_allow' cap if user is spam or deleted191 if ( bbp_is_user_inactive( $user_id ) ) {192 $caps = array( 'do_not_allow' );193 194 // Moderators can always edit forum content195 } elseif ( user_can( $user_id, 'moderate', $_post->ID ) ) {196 $caps = array( 'spectate' );197 198 // User is author so allow delete if not in admin199 } elseif ( ! is_admin() && ( (int) $user_id === (int) $_post->post_author ) ) {200 $caps = array( $post_type->cap->delete_posts );201 202 // Unknown so map to delete_others_posts203 } else {204 $caps = array( $post_type->cap->delete_others_posts );205 }206 }207 208 break;209 210 // Moderation override211 case 'delete_topics' :212 case 'delete_others_topics' :213 214 // Moderators can always delete215 if ( user_can( $user_id, 'moderate' ) ) {216 $caps = array( $cap );217 }218 219 break;220 221 /** Admin *************************************************************/222 223 case 'bbp_topics_admin' :224 $caps = array( 'edit_topics' );225 break;226 }227 228 // Filter & return229 return (array) apply_filters( 'bbp_map_topic_meta_caps', $caps, $cap, $user_id, $args );230 }231 232 /**233 * Maps topic tag capabilities234 *235 * @since 2.2.0 bbPress (r4242)236 *237 * @param array $caps Capabilities for meta capability238 * @param string $cap Capability name239 * @param int $user_id User id240 * @param array $args Arguments241 *242 * @return array Actual capabilities for meta capability243 */244 259 function bbp_map_topic_tag_meta_caps( $caps, $cap, $user_id, $args ) { 245 260
Note: See TracChangeset
for help on using the changeset viewer.