| 1 | Index: includes/forums/template.php |
|---|
| 2 | =================================================================== |
|---|
| 3 | --- includes/forums/template.php (revision 5212) |
|---|
| 4 | +++ includes/forums/template.php (working copy) |
|---|
| 5 | @@ -16,6 +16,7 @@ |
|---|
| 6 | * Output the unique id of the custom post type for forums |
|---|
| 7 | * |
|---|
| 8 | * @since bbPress (r2857) |
|---|
| 9 | + * |
|---|
| 10 | * @uses bbp_get_forum_post_type() To get the forum post type |
|---|
| 11 | */ |
|---|
| 12 | function bbp_forum_post_type() { |
|---|
| 13 | @@ -447,6 +448,7 @@ |
|---|
| 14 | * Allow forum rows to have adminstrative actions |
|---|
| 15 | * |
|---|
| 16 | * @since bbPress (r3653) |
|---|
| 17 | + * |
|---|
| 18 | * @uses do_action() |
|---|
| 19 | * @todo Links and filter |
|---|
| 20 | */ |
|---|
| 21 | @@ -1559,47 +1561,105 @@ |
|---|
| 22 | * Is the forum open? |
|---|
| 23 | * |
|---|
| 24 | * @since bbPress (r2746) |
|---|
| 25 | - * @param int $forum_id Optional. Forum id |
|---|
| 26 | * |
|---|
| 27 | * @param int $forum_id Optional. Forum id |
|---|
| 28 | - * @uses bbp_is_forum_closed() To check if the forum is closed or not |
|---|
| 29 | + * @param bool $check_ancestors Check if the ancestors are open (only |
|---|
| 30 | + * if they're a category) |
|---|
| 31 | + * @uses bbp_is_forum_closed() To check if the forum is closed |
|---|
| 32 | * @return bool Whether the forum is open or not |
|---|
| 33 | */ |
|---|
| 34 | -function bbp_is_forum_open( $forum_id = 0 ) { |
|---|
| 35 | - return !bbp_is_forum_closed( $forum_id ); |
|---|
| 36 | +function bbp_is_forum_open( $forum_id = 0, $check_ancestors = true ) { |
|---|
| 37 | + return !bbp_is_forum_closed( $forum_id, $check_ancestors ); |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | - /** |
|---|
| 41 | - * Is the forum closed? |
|---|
| 42 | - * |
|---|
| 43 | - * @since bbPress (r2746) |
|---|
| 44 | - * |
|---|
| 45 | - * @param int $forum_id Optional. Forum id |
|---|
| 46 | - * @param bool $check_ancestors Check if the ancestors are closed (only |
|---|
| 47 | - * if they're a category) |
|---|
| 48 | - * @uses bbp_get_forum_status() To get the forum status |
|---|
| 49 | - * @uses bbp_get_forum_ancestors() To get the forum ancestors |
|---|
| 50 | - * @uses bbp_is_forum_category() To check if the forum is a category |
|---|
| 51 | - * @uses bbp_is_forum_closed() To check if the forum is closed |
|---|
| 52 | - * @return bool True if closed, false if not |
|---|
| 53 | - */ |
|---|
| 54 | - function bbp_is_forum_closed( $forum_id = 0, $check_ancestors = true ) { |
|---|
| 55 | +/** |
|---|
| 56 | +* Is the forum closed? |
|---|
| 57 | + * |
|---|
| 58 | + * @since bbPress (r2746) |
|---|
| 59 | + * |
|---|
| 60 | + * @param int $forum_id Optional. Forum id |
|---|
| 61 | + * @param bool $check_ancestors Check if the ancestors are closed (only |
|---|
| 62 | + * if they're a category) |
|---|
| 63 | + * @uses bbp_get_forum_id() To get the forum ID |
|---|
| 64 | + * @uses bbp_is_forum_status_id() To check the forum status |
|---|
| 65 | + * @return bool True if closed, false if not |
|---|
| 66 | + */ |
|---|
| 67 | +function bbp_is_forum_closed( $forum_id = 0, $check_ancestors = true ) { |
|---|
| 68 | |
|---|
| 69 | - $forum_id = bbp_get_forum_id( $forum_id ); |
|---|
| 70 | - $retval = ( bbp_get_closed_status_id() === bbp_get_forum_status( $forum_id ) ); |
|---|
| 71 | + // Get the forum ID |
|---|
| 72 | + $forum_id = bbp_get_forum_id( $forum_id ); |
|---|
| 73 | |
|---|
| 74 | - if ( !empty( $check_ancestors ) ) { |
|---|
| 75 | - $ancestors = bbp_get_forum_ancestors( $forum_id ); |
|---|
| 76 | + // Check if the forum or one of it's ancestors is closed |
|---|
| 77 | + $retval = bbp_is_forum_status_id( $forum_id, bbp_get_closed_status_id(), $check_ancestors, 'OR' ); |
|---|
| 78 | |
|---|
| 79 | - foreach ( (array) $ancestors as $ancestor ) { |
|---|
| 80 | - if ( bbp_is_forum_category( $ancestor, false ) && bbp_is_forum_closed( $ancestor, false ) ) { |
|---|
| 81 | - $retval = true; |
|---|
| 82 | + return (bool) apply_filters( 'bbp_is_forum_closed', (bool) $retval, $forum_id, $check_ancestors ); |
|---|
| 83 | +} |
|---|
| 84 | + |
|---|
| 85 | +/** |
|---|
| 86 | + * Check the forum status ID |
|---|
| 87 | + * |
|---|
| 88 | + * @since bbPress (rX) |
|---|
| 89 | + * |
|---|
| 90 | + * @param bool $status_name The forum status name to check |
|---|
| 91 | + * @param bool $check_ancestors Check the forum ancestors |
|---|
| 92 | + * @param string $operator The logical operation to perform. |
|---|
| 93 | + * 'OR' means only one forum from the tree needs to match; |
|---|
| 94 | + * 'AND' means all forums must match. The default is 'AND'. |
|---|
| 95 | + * @uses bbp_get_forum_id() To get the forum ID |
|---|
| 96 | + * @uses bbp_get_forum_status() To get the forum status |
|---|
| 97 | + * @uses bbp_get_forum_ancestors() To get the forum ancestors |
|---|
| 98 | + * @uses bbp_is_forum_category() To check the forum type |
|---|
| 99 | + * @return bool True if match, false if not |
|---|
| 100 | + */ |
|---|
| 101 | +function bbp_is_forum_status_id( $forum_id, $status_name, $check_ancestors = true, $operator = 'AND' ) { |
|---|
| 102 | + |
|---|
| 103 | + $count = 0; |
|---|
| 104 | + $retval = false; |
|---|
| 105 | + $operator = strtoupper( $operator ); |
|---|
| 106 | + $forum_id = bbp_get_forum_id( $forum_id ); |
|---|
| 107 | + $forum_status = bbp_get_forum_status( $forum_id ); |
|---|
| 108 | + |
|---|
| 109 | + if ( $status_name == $forum_status ){ |
|---|
| 110 | + $retval = true; |
|---|
| 111 | + $count++; |
|---|
| 112 | + } |
|---|
| 113 | + |
|---|
| 114 | + if ( !empty( $check_ancestors ) ) { |
|---|
| 115 | + switch( $operator ) { |
|---|
| 116 | + |
|---|
| 117 | + default: |
|---|
| 118 | + case 'AND': |
|---|
| 119 | + $check_ancestors = ( $count > 0 ); |
|---|
| 120 | + break; |
|---|
| 121 | + |
|---|
| 122 | + case 'OR': |
|---|
| 123 | + $check_ancestors = ( $count < 1 ); |
|---|
| 124 | + break; |
|---|
| 125 | + } |
|---|
| 126 | + |
|---|
| 127 | + if ( $check_ancestors ) { |
|---|
| 128 | + |
|---|
| 129 | + // Loop through the forum ancestors |
|---|
| 130 | + foreach ( (array) bbp_get_forum_ancestors( $forum_id ) as $ancestor ) { |
|---|
| 131 | + |
|---|
| 132 | + // Check the post type |
|---|
| 133 | + if ( bbp_is_forum_category( $ancestor ) ) { |
|---|
| 134 | + |
|---|
| 135 | + // Check the ancestor forum status |
|---|
| 136 | + $retval = bbp_is_forum_status_id( $ancestor, $status_name, false ); |
|---|
| 137 | + |
|---|
| 138 | + if ( $retval ) |
|---|
| 139 | + $count++; |
|---|
| 140 | } |
|---|
| 141 | + |
|---|
| 142 | + // Break when it reach the max count |
|---|
| 143 | + if ( $operator == 'OR' && $count >= 1 ) |
|---|
| 144 | + break; |
|---|
| 145 | } |
|---|
| 146 | } |
|---|
| 147 | - |
|---|
| 148 | - return (bool) apply_filters( 'bbp_is_forum_closed', (bool) $retval, $forum_id, $check_ancestors ); |
|---|
| 149 | } |
|---|
| 150 | + return (bool) $retval; |
|---|
| 151 | +} |
|---|
| 152 | |
|---|
| 153 | /** |
|---|
| 154 | * Is the forum public? |
|---|
| 155 | @@ -1607,33 +1667,19 @@ |
|---|
| 156 | * @since bbPress (r2997) |
|---|
| 157 | * |
|---|
| 158 | * @param int $forum_id Optional. Forum id |
|---|
| 159 | - * @param bool $check_ancestors Check if the ancestors are public (only if |
|---|
| 160 | - * they're a category) |
|---|
| 161 | - * @uses get_post_meta() To get the forum public meta |
|---|
| 162 | - * @uses bbp_get_forum_ancestors() To get the forum ancestors |
|---|
| 163 | - * @uses bbp_is_forum_category() To check if the forum is a category |
|---|
| 164 | - * @uses bbp_is_forum_closed() To check if the forum is closed |
|---|
| 165 | + * @param bool $check_ancestors Check if the ancestors are public |
|---|
| 166 | + * @uses bbp_get_forum_id() To get the forum ID |
|---|
| 167 | + * @uses bbp_is_forum_visibility_id() To check the forum visibility ID |
|---|
| 168 | * @return bool True if closed, false if not |
|---|
| 169 | */ |
|---|
| 170 | function bbp_is_forum_public( $forum_id = 0, $check_ancestors = true ) { |
|---|
| 171 | |
|---|
| 172 | - $forum_id = bbp_get_forum_id( $forum_id ); |
|---|
| 173 | - $visibility = bbp_get_forum_visibility( $forum_id ); |
|---|
| 174 | + // Get the forum ID |
|---|
| 175 | + $forum_id = bbp_get_forum_id( $forum_id ); |
|---|
| 176 | |
|---|
| 177 | - // If post status is public, return true |
|---|
| 178 | - $retval = ( bbp_get_public_status_id() === $visibility ); |
|---|
| 179 | + // Check if the forum and all of it's ancestors are public |
|---|
| 180 | + $retval = bbp_is_forum_visibility_id( $forum_id, bbp_get_public_status_id(), $check_ancestors ); |
|---|
| 181 | |
|---|
| 182 | - // Check ancestors and inherit their privacy setting for display |
|---|
| 183 | - if ( !empty( $check_ancestors ) ) { |
|---|
| 184 | - $ancestors = bbp_get_forum_ancestors( $forum_id ); |
|---|
| 185 | - |
|---|
| 186 | - foreach ( (array) $ancestors as $ancestor ) { |
|---|
| 187 | - if ( bbp_is_forum( $ancestor ) && bbp_is_forum_public( $ancestor, false ) ) { |
|---|
| 188 | - $retval = true; |
|---|
| 189 | - } |
|---|
| 190 | - } |
|---|
| 191 | - } |
|---|
| 192 | - |
|---|
| 193 | return (bool) apply_filters( 'bbp_is_forum_public', (bool) $retval, $forum_id, $check_ancestors ); |
|---|
| 194 | } |
|---|
| 195 | |
|---|
| 196 | @@ -1643,33 +1689,19 @@ |
|---|
| 197 | * @since bbPress (r2746) |
|---|
| 198 | * |
|---|
| 199 | * @param int $forum_id Optional. Forum id |
|---|
| 200 | - * @param bool $check_ancestors Check if the ancestors are private (only if |
|---|
| 201 | - * they're a category) |
|---|
| 202 | - * @uses get_post_meta() To get the forum private meta |
|---|
| 203 | - * @uses bbp_get_forum_ancestors() To get the forum ancestors |
|---|
| 204 | - * @uses bbp_is_forum_category() To check if the forum is a category |
|---|
| 205 | - * @uses bbp_is_forum_closed() To check if the forum is closed |
|---|
| 206 | - * @return bool True if closed, false if not |
|---|
| 207 | + * @param bool $check_ancestors Check if the ancestors are private |
|---|
| 208 | + * @uses bbp_get_forum_id() To get the forum ID |
|---|
| 209 | + * @uses bbp_is_forum_visibility_id() To check the forum visibility ID |
|---|
| 210 | + * @return bool True if private, false if not |
|---|
| 211 | */ |
|---|
| 212 | function bbp_is_forum_private( $forum_id = 0, $check_ancestors = true ) { |
|---|
| 213 | |
|---|
| 214 | - $forum_id = bbp_get_forum_id( $forum_id ); |
|---|
| 215 | - $visibility = bbp_get_forum_visibility( $forum_id ); |
|---|
| 216 | + // Get the forum ID |
|---|
| 217 | + $forum_id = bbp_get_forum_id( $forum_id ); |
|---|
| 218 | |
|---|
| 219 | - // If post status is private, return true |
|---|
| 220 | - $retval = ( bbp_get_private_status_id() === $visibility ); |
|---|
| 221 | + // Check if the forum or one of it's ancestors is private |
|---|
| 222 | + $retval = bbp_is_forum_visibility_id( $forum_id, bbp_get_private_status_id(), $check_ancestors, 'OR' ); |
|---|
| 223 | |
|---|
| 224 | - // Check ancestors and inherit their privacy setting for display |
|---|
| 225 | - if ( !empty( $check_ancestors ) ) { |
|---|
| 226 | - $ancestors = bbp_get_forum_ancestors( $forum_id ); |
|---|
| 227 | - |
|---|
| 228 | - foreach ( (array) $ancestors as $ancestor ) { |
|---|
| 229 | - if ( bbp_is_forum( $ancestor ) && bbp_is_forum_private( $ancestor, false ) ) { |
|---|
| 230 | - $retval = true; |
|---|
| 231 | - } |
|---|
| 232 | - } |
|---|
| 233 | - } |
|---|
| 234 | - |
|---|
| 235 | return (bool) apply_filters( 'bbp_is_forum_private', (bool) $retval, $forum_id, $check_ancestors ); |
|---|
| 236 | } |
|---|
| 237 | |
|---|
| 238 | @@ -1681,32 +1713,88 @@ |
|---|
| 239 | * @param int $forum_id Optional. Forum id |
|---|
| 240 | * @param bool $check_ancestors Check if the ancestors are private (only if |
|---|
| 241 | * they're a category) |
|---|
| 242 | - * @uses get_post_meta() To get the forum private meta |
|---|
| 243 | - * @uses bbp_get_forum_ancestors() To get the forum ancestors |
|---|
| 244 | - * @uses bbp_is_forum_category() To check if the forum is a category |
|---|
| 245 | - * @uses bbp_is_forum_closed() To check if the forum is closed |
|---|
| 246 | - * @return bool True if closed, false if not |
|---|
| 247 | + * @uses bbp_get_forum_id() To get the forum ID |
|---|
| 248 | + * @uses bbp_is_forum_visibility_id() To check the forum visibility ID |
|---|
| 249 | + * @return bool True if hidden, false if not |
|---|
| 250 | */ |
|---|
| 251 | function bbp_is_forum_hidden( $forum_id = 0, $check_ancestors = true ) { |
|---|
| 252 | |
|---|
| 253 | + // Get the forum ID |
|---|
| 254 | + $forum_id = bbp_get_forum_id( $forum_id ); |
|---|
| 255 | + |
|---|
| 256 | + // Check if the forum or one of it's ancestors is hidden |
|---|
| 257 | + $retval = bbp_is_forum_visibility_id( $forum_id, bbp_get_hidden_status_id(), $check_ancestors, 'OR' ); |
|---|
| 258 | + |
|---|
| 259 | + return (bool) apply_filters( 'bbp_is_forum_hidden', (bool) $retval, $forum_id, $check_ancestors ); |
|---|
| 260 | +} |
|---|
| 261 | + |
|---|
| 262 | +/** |
|---|
| 263 | + * Check the forum visibility ID |
|---|
| 264 | + * |
|---|
| 265 | + * @since bbPress (rX) |
|---|
| 266 | + * |
|---|
| 267 | + * @param int $forum_id Optional. Forum id |
|---|
| 268 | + * @param bool $status_name The post status name to check |
|---|
| 269 | + * @param bool $check_ancestors Check the forum ancestors |
|---|
| 270 | + * @param string $operator The logical operation to perform. |
|---|
| 271 | + * 'OR' means only one forum from the tree needs to match; |
|---|
| 272 | + * 'AND' means all forums must match. The default is 'AND'. |
|---|
| 273 | + * @uses bbp_get_forum_id() To get the forum ID |
|---|
| 274 | + * @uses bbp_get_forum_visibility() To get the forum visibility |
|---|
| 275 | + * @uses bbp_get_forum_ancestors() To get the forum ancestors |
|---|
| 276 | + * @uses bbp_is_forum() To check the post type |
|---|
| 277 | + * @return bool True if match, false if not |
|---|
| 278 | + */ |
|---|
| 279 | +function bbp_is_forum_visibility_id( $forum_id, $status_name, $check_ancestors = true, $operator = 'AND' ) { |
|---|
| 280 | + |
|---|
| 281 | + $count = 0; |
|---|
| 282 | + $retval = false; |
|---|
| 283 | + $operator = strtoupper( $operator ); |
|---|
| 284 | $forum_id = bbp_get_forum_id( $forum_id ); |
|---|
| 285 | $visibility = bbp_get_forum_visibility( $forum_id ); |
|---|
| 286 | |
|---|
| 287 | - // If post status is private, return true |
|---|
| 288 | - $retval = ( bbp_get_hidden_status_id() === $visibility ); |
|---|
| 289 | + if ( $status_name == $visibility ){ |
|---|
| 290 | + $retval = true; |
|---|
| 291 | + $count++; |
|---|
| 292 | + } |
|---|
| 293 | |
|---|
| 294 | - // Check ancestors and inherit their privacy setting for display |
|---|
| 295 | if ( !empty( $check_ancestors ) ) { |
|---|
| 296 | - $ancestors = bbp_get_forum_ancestors( $forum_id ); |
|---|
| 297 | |
|---|
| 298 | - foreach ( (array) $ancestors as $ancestor ) { |
|---|
| 299 | - if ( bbp_is_forum( $ancestor ) && bbp_is_forum_hidden( $ancestor, false ) ) { |
|---|
| 300 | - $retval = true; |
|---|
| 301 | + switch( $operator ) { |
|---|
| 302 | + |
|---|
| 303 | + default: |
|---|
| 304 | + case 'AND': |
|---|
| 305 | + $check_ancestors = ( $count > 0 ); |
|---|
| 306 | + break; |
|---|
| 307 | + |
|---|
| 308 | + case 'OR': |
|---|
| 309 | + $check_ancestors = ( $count < 1 ); |
|---|
| 310 | + break; |
|---|
| 311 | + } |
|---|
| 312 | + |
|---|
| 313 | + if ( $check_ancestors ) { |
|---|
| 314 | + |
|---|
| 315 | + // Loop through the forum ancestors |
|---|
| 316 | + foreach ( (array) bbp_get_forum_ancestors( $forum_id ) as $ancestor ) { |
|---|
| 317 | + |
|---|
| 318 | + // Check the post type |
|---|
| 319 | + if ( bbp_is_forum( $ancestor ) ) { |
|---|
| 320 | + |
|---|
| 321 | + // Check the forum visibility |
|---|
| 322 | + $retval = bbp_is_forum_visibility_id( $ancestor, $status_name, false ); |
|---|
| 323 | + |
|---|
| 324 | + if ( $retval ) |
|---|
| 325 | + $count++; |
|---|
| 326 | + } |
|---|
| 327 | + |
|---|
| 328 | + // Break when it reach the max count |
|---|
| 329 | + if ( $operator == 'OR' && $count >= 1 ) |
|---|
| 330 | + break; |
|---|
| 331 | } |
|---|
| 332 | } |
|---|
| 333 | } |
|---|
| 334 | |
|---|
| 335 | - return (bool) apply_filters( 'bbp_is_forum_hidden', (bool) $retval, $forum_id, $check_ancestors ); |
|---|
| 336 | + return (bool) $retval; |
|---|
| 337 | } |
|---|
| 338 | |
|---|
| 339 | /** |
|---|
| 340 | @@ -2226,7 +2314,7 @@ |
|---|
| 341 | |
|---|
| 342 | return apply_filters( 'bbp_get_form_forum_visibility', esc_attr( $forum_visibility ) ); |
|---|
| 343 | } |
|---|
| 344 | - |
|---|
| 345 | + |
|---|
| 346 | /** |
|---|
| 347 | * Output checked value of forum subscription |
|---|
| 348 | * |
|---|