bbp_map_topic_meta_caps( array $caps = array(), string $cap = '', int $user_id, mixed $args = array() )
Maps topic capabilities
Description
Parameters
- $caps
-
(Optional) Capabilities for meta capability
Default value: array()
- $cap
-
(Optional) Capability name
Default value: ''
- $user_id
-
(Required) User id
- $args
-
(Optional) Arguments
Default value: array()
Return
(array) Actual capabilities for meta capability
Source
File: bp-forums/topics/capabilities.php
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | function bbp_map_topic_meta_caps( $caps = array (), $cap = '' , $user_id = 0, $args = array () ) { // What capability is being checked? switch ( $cap ) { /** Reading ***********************************************************/ case 'read_topic' : // User cannot spectate if ( ! user_can( $user_id , 'spectate' ) ) { $caps = array ( 'do_not_allow' ); // Do some post ID based logic } else { // Get the post $_post = get_post( $args [0] ); if ( ! empty ( $_post ) ) { // Get caps for post type object $post_type = get_post_type_object( $_post ->post_type ); // Post is public if ( bbp_get_public_status_id() === $_post ->post_status ) { $caps = array ( 'spectate' ); // User is author so allow read } elseif ( (int) $user_id === (int) $_post ->post_author ) { $caps = array ( 'spectate' ); // Unknown so map to private posts } else { $caps = array ( $post_type ->cap->read_private_posts ); } } } break ; /** Publishing ********************************************************/ case 'publish_topics' : // Moderators can always publish if ( user_can( $user_id , 'moderate' ) ) { $caps = array ( 'moderate' ); } break ; /** Editing ***********************************************************/ // Used primarily in wp-admin case 'edit_topics' : case 'edit_others_topics' : // Moderators can always edit if ( user_can( $user_id , 'moderate' ) ) { $caps = array ( $cap ); // Otherwise, block } else { $caps = array ( 'do_not_allow' ); } break ; // Used everywhere case 'edit_topic' : // Get the post $_post = get_post( $args [0] ); if ( ! empty ( $_post ) ) { // Get caps for post type object $post_type = get_post_type_object( $_post ->post_type ); $caps = array (); // Add 'do_not_allow' cap if user is spam or deleted if ( bbp_is_user_inactive( $user_id ) ) { $caps [] = 'do_not_allow' ; // User is author so allow edit if not in admin } elseif ( !is_admin() && ( (int) $user_id === (int) $_post ->post_author ) ) { $caps [] = $post_type ->cap->edit_posts; // Unknown, so map to edit_others_posts } else { $caps [] = $post_type ->cap->edit_others_posts; } } break ; /** Deleting **********************************************************/ case 'delete_topic' : // Get the post $_post = get_post( $args [0] ); if ( ! empty ( $_post ) ) { // Get caps for post type object $post_type = get_post_type_object( $_post ->post_type ); $caps = array (); // Add 'do_not_allow' cap if user is spam or deleted if ( bbp_is_user_inactive( $user_id ) ) { $caps [] = 'do_not_allow' ; // Moderators can always edit forum content } elseif ( user_can( $user_id , 'moderate' ) ) { $caps [] = 'moderate' ; // Unknown so map to delete_others_posts } else { $caps [] = $post_type ->cap->delete_others_posts; } } break ; // Moderation override case 'delete_topics' : case 'delete_others_topics' : // Moderators can always delete if ( user_can( $user_id , 'moderate' ) ) { $caps = array ( $cap ); } break ; /** Admin *************************************************************/ case 'bbp_topics_admin' : $caps = array ( 'moderate' ); break ; } return apply_filters( 'bbp_map_topic_meta_caps' , $caps , $cap , $user_id , $args ); } |
Changelog
Version | Description |
---|---|
bbPress (r4242) | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.