Changeset 3085
- Timestamp:
- 05/03/2011 08:01:48 AM (14 years ago)
- Location:
- branches/plugin
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/plugin/bbp-admin/bbp-admin.php
r3078 r3085 446 446 } 447 447 448 // Private?449 if ( !empty( $_POST['bbp_forum_visibility'] ) && in_array( $_POST['bbp_forum_visibility'], array( 'publi c', 'private', 'hidden' ) ) ) {448 // Visibility 449 if ( !empty( $_POST['bbp_forum_visibility'] ) && in_array( $_POST['bbp_forum_visibility'], array( 'publish', 'private', 'hidden' ) ) ) { 450 450 451 451 // Get forums current visibility … … 468 468 break; 469 469 470 // Publi c(default)471 case 'publi c' :470 // Publish (default) 471 case 'publish' : 472 472 default : 473 473 bbp_publicize_forum( $forum_id, $visibility ); … … 2143 2143 2144 2144 $forum['visibility'] = array( 2145 'publi c'=> __( 'Public', 'bbpress' ),2145 'publish' => __( 'Public', 'bbpress' ), 2146 2146 'private' => __( 'Private', 'bbpress' ), 2147 2147 'hidden' => __( 'Hidden', 'bbpress' ) -
branches/plugin/bbp-includes/bbp-forum-functions.php
r3055 r3085 174 174 175 175 // Only run queries if visibility is changing 176 if ( 'publi c' != $current_visibility ) {176 if ( 'publish' != $current_visibility ) { 177 177 178 178 // Remove from _bbp_private_forums site option … … 214 214 } 215 215 216 // Update forums visibility setting 217 update_post_meta( $forum_id, '_bbp_visibility', 'public' ); 216 // Update forum post_status 217 global $wpdb; 218 $wpdb->update( $wpdb->posts, array( 'post_status' => 'publish' ), array( 'ID' => $forum_id ) ); 219 wp_transition_post_status( 'publish', $current_visibility, get_post( $forum_id ) ); 218 220 } 219 221 … … 266 268 267 269 // Update forums visibility setting 268 update_post_meta( $forum_id, '_bbp_visibility', 'private' ); 270 global $wpdb; 271 $wpdb->update( $wpdb->posts, array( 'post_status' => 'private' ), array( 'ID' => $forum_id ) ); 272 wp_transition_post_status( 'private', $current_visibility, get_post( $forum_id ) ); 269 273 } 270 274 … … 317 321 318 322 // Update forums visibility setting 319 update_post_meta( $forum_id, '_bbp_visibility', 'hidden' ); 323 global $bbp, $wpdb; 324 $wpdb->update( $wpdb->posts, array( 'post_status' => 'hidden' ), array( 'ID' => $forum_id ) ); 325 wp_transition_post_status( $bbp->hidden_status_id, $current_visibility, get_post( $forum_id ) ); 320 326 } 321 327 … … 762 768 763 769 /** 770 * Returns a meta_query that either includes or excludes hidden forum IDs 771 * from a query. 772 * 773 * @uses is_super_admin() 774 * @uses bbp_is_user_home() 775 * @uses bbp_get_hidden_forum_ids() 776 * @uses bbp_get_private_forum_ids() 777 */ 778 function bbp_exclude_forum_ids( $query = array() ) { 779 780 // Show hidden topics for super admins 781 if ( is_super_admin() || bbp_is_user_home() ) 782 return $query; 783 784 // Setup arrays 785 $private = $hidden = array(); 786 787 // Private forums 788 if ( !current_user_can( 'read_private_forums' ) ) 789 $private = bbp_get_private_forum_ids(); 790 791 // Hidden forums 792 if ( !current_user_can( 'read_hidden_forums' ) ) 793 $hidden = bbp_get_hidden_forum_ids(); 794 795 // Merge private and hidden forums together 796 $forum_ids = array_merge( $private, $hidden ); 797 798 // Setup a meta_query to remove hidden forums 799 $value = implode( ',', $forum_ids ); 800 $compare = ( 1 < count( $forum_ids ) ) ? 'NOT IN' : '!='; 801 802 // Add meta_query to $replies_query 803 $meta_query['meta_query'] = array( array( 804 'key' => '_bbp_forum_id', 805 'value' => $value, 806 'compare' => $compare 807 ) ); 808 809 // Merge the queries together 810 if ( !empty( $meta_query ) ) 811 $query = array_merge( $query, $meta_query ); 812 813 return apply_filters( 'bbp_exclude_forum_ids', $query, $meta_query ); 814 } 815 816 /** 764 817 * Returns the forum's topic ids 765 818 * … … 857 910 */ 858 911 function bbp_forum_visibility_check() { 912 global $wp_query; 859 913 860 914 // Bail if not viewing a single item or if user has caps … … 863 917 864 918 // Check post type 865 switch ( get_post_type() ) {919 switch ( $wp_query->get( 'post_type' ) ) { 866 920 867 921 // Forum 868 922 case bbp_get_forum_post_type() : 869 $forum_id = bbp_get_forum_id( get_the_ID());923 $forum_id = bbp_get_forum_id( $wp_query->post->ID ); 870 924 break; 871 925 872 926 // Topic 873 927 case bbp_get_topic_post_type() : 874 $forum_id = bbp_get_topic_forum_id( get_the_ID());928 $forum_id = bbp_get_topic_forum_id( $wp_query->post->ID ); 875 929 break; 876 930 877 931 // Reply 878 932 case bbp_get_reply_post_type() : 879 $forum_id = bbp_get_reply_forum_id( get_the_ID());933 $forum_id = bbp_get_reply_forum_id( $wp_query->post->ID ); 880 934 break; 881 935 -
branches/plugin/bbp-includes/bbp-forum-template.php
r3066 r3085 58 58 global $bbp; 59 59 60 // Make sure we're back where we started 61 wp_reset_postdata(); 62 63 // Setup possible post__not_in array 64 $post_stati[] = 'publish'; 65 66 // Super admin get whitelisted post statuses 67 if ( is_super_admin() ) { 68 $post_stati = array( 'publish', 'private', 'hidden' ); 69 70 // Not a super admin, so check caps 71 } else { 72 73 // Check if user can read private forums 74 if ( current_user_can( 'read_private_forums' ) ) 75 $post_stati[] = 'private'; 76 77 // Check if user can read hidden forums 78 if ( current_user_can( 'read_hidden_forums' ) ) 79 $post_stati[] = 'hidden'; 80 } 81 82 // The default forum query for most circumstances 60 83 $default = array ( 61 84 'post_type' => bbp_get_forum_post_type(), 62 85 'post_parent' => bbp_get_forum_id(), 86 'post_status' => implode( ',', $post_stati ), 63 87 'posts_per_page' => get_option( '_bbp_forums_per_page', 15 ), 64 88 'orderby' => 'menu_order', … … 66 90 ); 67 91 92 // Parse the default against what is requested 68 93 $bbp_f = wp_parse_args( $args, $default ); 69 70 // Allow all forums to be queried if post_parent is set to -171 if ( -1 == $bbp_f['post_parent'] )72 unset( $bbp_f['post_parent'] );73 74 // Don't show private forums to normal users75 if ( empty( $bbp_f['meta_key'] ) && empty( $bbp_f['meta_value'] ) ) {76 77 // Include public and private forums only78 if ( current_user_can( 'read_private_forums' ) ) {79 $value = 'public, private';80 $compare = 'IN';81 82 // Include public forums only83 } else {84 $value = 'hidden';85 $compare = '!=';86 }87 88 // Meta query to determine visibility scope89 $bbp_f['meta_query'] = array( array(90 'key' => '_bbp_visibility',91 'value' => $value,92 'compare' => $compare93 ) );94 }95 94 96 95 // Filter the forums query to allow just-in-time modifications … … 161 160 */ 162 161 function bbp_get_forum_id( $forum_id = 0 ) { 163 global $bbp ;162 global $bbp, $wp_query; 164 163 165 164 // Easy empty checking … … 172 171 173 172 // Currently viewing a forum 174 elseif ( bbp_is_forum() && get_the_ID() )175 $bbp_forum_id = $bbp->current_forum_id = get_the_ID();173 elseif ( bbp_is_forum() && isset( $wp_query->post->ID ) ) 174 $bbp_forum_id = $bbp->current_forum_id = $wp_query->post->ID; 176 175 177 176 // Currently viewing a topic … … 520 519 */ 521 520 function bbp_forum_get_subforums( $args = '' ) { 521 522 // Use passed integer as post_parent 522 523 if ( is_numeric( $args ) ) 523 524 $args = array( 'post_parent' => $args ); 525 526 // Setup possible post__not_in array 527 $post_stati[] = 'publish'; 528 529 // Super admin get whitelisted post statuses 530 if ( is_super_admin() ) { 531 $post_stati = array( 'publish', 'private', 'hidden' ); 532 533 // Not a super admin, so check caps 534 } else { 535 536 // Check if user can read private forums 537 if ( current_user_can( 'read_private_forums' ) ) 538 $post_stati[] = 'private'; 539 540 // Check if user can read hidden forums 541 if ( current_user_can( 'read_hidden_forums' ) ) 542 $post_stati[] = 'hidden'; 543 } 524 544 525 545 $default = array( 526 546 'post_parent' => 0, 527 547 'post_type' => bbp_get_forum_post_type(), 548 'post_status' => implode( ',', $post_stati ), 528 549 'posts_per_page' => get_option( '_bbp_forums_per_page', 15 ), 529 550 'sort_column' => 'menu_order, post_title' … … 531 552 532 553 $r = wp_parse_args( $args, $default ); 533 534 554 $r['post_parent'] = bbp_get_forum_id( $r['post_parent'] ); 535 536 // Don't show hidden forums to normal users537 if ( !current_user_can( 'read_private_forums' ) && empty( $r['meta_query'] ) && empty( $r['meta_key'] ) && empty( $r['meta_value'] ) ) {538 $r['meta_query'] = array( array(539 'key' => '_bbp_visibility',540 'value' => 'public, private',541 'compare' => 'IN'542 ) );543 }544 555 545 556 // No forum passed … … 1238 1249 $forum_id = bbp_get_forum_id( $forum_id ); 1239 1250 1240 return apply_filters( 'bbp_get_forum_visibility', get_post_ meta( $forum_id, '_bbp_visibility', true), $forum_id );1251 return apply_filters( 'bbp_get_forum_visibility', get_post_status( $forum_id ), $forum_id ); 1241 1252 } 1242 1253 … … 1326 1337 1327 1338 // If post status is public, return true 1328 $retval = ( 'publi c' == $visibility );1339 $retval = ( 'publish' == $visibility ); 1329 1340 1330 1341 // Check ancestors and inherit their privacy setting for display -
branches/plugin/bbp-includes/bbp-general-template.php
r3068 r3085 46 46 */ 47 47 function bbp_is_forum( $post_id = 0 ) { 48 global $bbp ;48 global $bbp, $wp_query; 49 49 50 50 if ( empty( $post_id ) ) { … … 53 53 return true; 54 54 55 if ( ( $post_type = get_query_var( 'post_type' ) ) && ( bbp_get_forum_post_type() === $post_type) )55 if ( isset( $wp_query->query_vars['post_type'] ) && ( bbp_get_forum_post_type() === $wp_query->query_vars['post_type'] ) ) 56 56 return true; 57 57 … … 81 81 */ 82 82 function bbp_is_topic( $post_id = 0 ) { 83 global $bbp ;83 global $bbp, $wp_query; 84 84 85 85 // Return false if it's a edit topic page … … 92 92 return true; 93 93 94 if ( ( $post_type = get_query_var( 'post_type' ) ) && ( bbp_get_topic_post_type() === $post_type) )94 if ( isset( $wp_query->query_vars['post_type'] ) && ( bbp_get_topic_post_type() === $wp_query->query_vars['post_type'] ) ) 95 95 return true; 96 96 … … 166 166 */ 167 167 function bbp_is_reply( $post_id = 0 ) { 168 global $bbp ;168 global $bbp, $wp_query; 169 169 170 170 // Return false if it's a edit reply page … … 177 177 return true; 178 178 179 if ( ( $post_type = get_query_var( 'post_type' ) ) && ( bbp_get_reply_post_type() === $post_type) )179 if ( isset( $wp_query->query_vars['post_type'] ) && ( bbp_get_reply_post_type() === $wp_query->query_vars['post_type'] ) ) 180 180 return true; 181 181 … … 679 679 $r['selected'] = 0; 680 680 681 // Don't show private forums to normal users 682 if ( !current_user_can( 'read_private_forums' ) && empty( $r['meta_query'] ) && empty( $r['meta_key'] ) && empty( $r['meta_value'] ) && empty( $r['meta_compare'] ) ) { 683 $r['meta_query'] = array( 684 array( 685 'key' => '_bbp_visibility', 686 'value' => 'public', 687 'compare' => '=' 688 ) 689 ); 690 } 681 $r = bbp_exclude_forum_ids( $r ); 691 682 692 683 extract( $r ); -
branches/plugin/bbp-includes/bbp-reply-template.php
r3066 r3085 67 67 global $wp_rewrite, $bbp; 68 68 69 // Make sure we're back where we started 70 wp_reset_postdata(); 71 69 72 // Default status 70 73 $default_status = join( ',', array( 'publish', $bbp->closed_status_id ) ); … … 220 223 */ 221 224 function bbp_get_reply_id( $reply_id = 0 ) { 222 global $bbp ;225 global $bbp, $wp_query; 223 226 224 227 // Easy empty checking … … 227 230 228 231 // Currently viewing a reply 229 elseif ( ( bbp_is_reply() || bbp_is_reply_edit() ) && get_the_ID() )230 $bbp_reply_id = $bbp->current_reply_id = get_the_ID();232 elseif ( ( bbp_is_reply() || bbp_is_reply_edit() ) && isset( $wp_query->post->ID ) ) 233 $bbp_reply_id = $bbp->current_reply_id = $wp_query->post->ID; 231 234 232 235 // Currently inside a replies loop -
branches/plugin/bbp-includes/bbp-shortcodes.php
r3080 r3085 274 274 275 275 // Remove any topics from hidden forums 276 $topics_query = bbp_exclude_ hidden_forums( $topics_query );276 $topics_query = bbp_exclude_forum_ids( $topics_query ); 277 277 278 278 // Unset globals -
branches/plugin/bbp-includes/bbp-topic-template.php
r3066 r3085 66 66 global $wp_rewrite, $wp_query, $bbp, $wpdb; 67 67 68 // Make sure we're back where we started 69 wp_reset_postdata(); 70 68 71 // Are we in a forum and looking to do a forum only query? 69 72 $in_forum = (bool) ( bbp_is_forum() && !bbp_is_query_name( 'bbp_widget' ) ); 70 73 71 74 // What are the default allowed statuses (based on user caps) 72 if ( !empty( $_GET['view'] ) && ( true == $in_forum ) && ( 'all' == $_GET['view'] && current_user_can( 'edit_others_topics') ) )75 if ( current_user_can( 'moderate' ) && !bbp_is_query_name( 'bbp_widget' ) && ( !empty( $_GET['view'] ) && ( 'all' == $_GET['view'] ) ) ) 73 76 $default_status = join( ',', array( 'publish', $bbp->closed_status_id, $bbp->spam_status_id, 'trash' ) ); 74 77 else … … 321 324 */ 322 325 function bbp_get_topic_id( $topic_id = 0 ) { 323 global $bbp ;326 global $bbp, $wp_query; 324 327 325 328 // Easy empty checking … … 332 335 333 336 // Currently viewing a topic 334 elseif ( ( bbp_is_topic() || bbp_is_topic_edit() ) && get_the_ID() )335 $bbp_topic_id = $bbp->current_topic_id = get_the_ID();337 elseif ( ( bbp_is_topic() || bbp_is_topic_edit() ) && isset( $wp_query->post->ID ) ) 338 $bbp_topic_id = $bbp->current_topic_id = $wp_query->post->ID; 336 339 337 340 // Currently viewing a topic -
branches/plugin/bbp-includes/bbp-user-functions.php
r3015 r3085 173 173 // If user has favorites, load them 174 174 if ( $favorites = bbp_get_user_favorites_topic_ids( $user_id ) ) { 175 $query = bbp_has_topics( array( 'post__in' => $favorites ) ); 176 return apply_filters( 'bbp_get_user_favorites', $query, $user_id ); 175 176 // Possibly remove topics from hidden forums 177 $hidden_query = bbp_exclude_forum_ids(); 178 $favs_query = array( 'post__in' => $favorites ); 179 $topics_query = array_merge( $hidden_query, $favs_query ); 180 $topics_query = bbp_has_topics( $topics_query ); 181 182 return apply_filters( 'bbp_get_user_favorites', $topics_query, $user_id ); 177 183 } 178 184 … … 783 789 784 790 // Query defaults 785 $ topics_query = array(791 $default_query = array( 786 792 'post_author' => $user_id, 787 793 'show_stickies' => false, … … 789 795 ); 790 796 791 // Setup a meta_query to remove hidden forums 792 if ( $hidden = bbp_get_hidden_forum_ids() ) { 793 794 // Value and compare for meta_query 795 $value = implode( ',', bbp_get_hidden_forum_ids() ); 796 $compare = ( 1 < count( $hidden ) ) ? 'NOT IN' : '!='; 797 798 // Add meta_query to $replies_query 799 $topics_query['meta_query'] = array( array( 800 'key' => '_bbp_forum_id', 801 'value' => $value, 802 'compare' => $compare 803 ) ); 804 $topics_query['post_parent'] = 'any'; 805 } 806 797 // Assume user cannot read hidden forums 798 $topics_query = bbp_exclude_forum_ids( $default_query ); 799 800 // Get the topics 807 801 if ( $query = bbp_has_topics( $topics_query ) ) 808 802 return $query; -
branches/plugin/bbp-includes/bbp-widgets.php
r3044 r3085 303 303 304 304 $title = apply_filters( 'bbp_forum_widget_title', $instance['title'] ); 305 $parent_forum = !empty( $instance['parent_forum'] ) ? $instance['parent_forum'] : 0;306 307 $ default= array(305 $parent_forum = !empty( $instance['parent_forum'] ) ? $instance['parent_forum'] : '0'; 306 307 $forums_query = array( 308 308 'post_parent' => $parent_forum, 309 309 'posts_per_page' => get_option( '_bbp_forums_per_page', 15 ), … … 312 312 ); 313 313 314 // Don't show private forums to normal users315 if ( !current_user_can( 'read_private_forums' ) && empty( $default['meta_key'] ) && empty( $default['meta_value'] ) ) {316 $default['meta_key'] = '_bbp_visibility';317 $default['meta_value'] = 'public';318 }319 320 314 bbp_set_query_name( 'bbp_widget' ); 321 315 322 if ( bbp_has_forums( $ default) ) :316 if ( bbp_has_forums( $forums_query ) ) : 323 317 324 318 echo $before_widget; … … 455 449 // Query defaults 456 450 $topics_query = array( 451 'post_parent' => $parent_forum, 457 452 'post_author' => 0, 458 453 'posts_per_page' => $max_shown > $pop_check ? $max_shown : $pop_check, 454 'posts_per_page' => $max_shown, 459 455 'show_stickies' => false, 460 'posts_per_page' => $max_shown,461 456 'order' => 'DESC', 462 457 ); 463 458 464 // Setup a meta_query to remove hidden forums465 if ( ( empty( $parent_forum ) || ( 'any' == $parent_forum ) ) && ( $hidden = bbp_get_hidden_forum_ids() ) ) {466 467 // Value and compare for meta_query468 $value = implode( ',', $hidden );469 $compare = ( 1 < count( $hidden ) ) ? 'NOT IN' : '!=';470 471 // Add meta_query to $replies_query472 $topics_query['meta_query'] = array( array(473 'key' => '_bbp_forum_id',474 'value' => $value,475 'compare' => $compare476 ) );477 $topics_query['post_parent'] = 'any';478 }479 480 459 bbp_set_query_name( 'bbp_widget' ); 460 461 // Remove any topics from hidden forums 462 $topics_query = bbp_exclude_forum_ids( $topics_query ); 481 463 482 464 if ( $pop_check < $max_shown && bbp_has_topics( $topics_query ) ) : … … 655 637 ); 656 638 657 // Setup a meta_query to remove hidden forums658 if ( $hidden = bbp_get_hidden_forum_ids() ) {659 660 // Value and compare for meta_query661 $value = implode( ',', $hidden );662 $compare = ( 1 < count( $hidden ) ) ? 'NOT IN' : '!=';663 664 // Add meta_query to $replies_query665 $replies_query['meta_query'] = array( array(666 'key' => '_bbp_forum_id',667 'value' => $value,668 'compare' => $compare669 ) );670 }671 672 639 // Set the query name 673 640 bbp_set_query_name( 'bbp_widget' ); 641 642 // Exclude hidden forums 643 $replies_query = bbp_exclude_forum_ids( $replies_query ); 674 644 675 645 // Get replies and display them -
branches/plugin/bbp-themes/bbp-twentyten/bbpress/form-reply.php
r3061 r3085 7 7 * @subpackage Theme 8 8 */ 9 10 // Make sure we're back where we started 11 wp_reset_postdata(); 9 12 10 13 ?> -
branches/plugin/bbp-themes/bbp-twentyten/bbpress/form-topic.php
r3061 r3085 7 7 * @subpackage Theme 8 8 */ 9 10 // Make sure we're back where we started 11 wp_reset_postdata(); 9 12 10 13 ?>
Note: See TracChangeset
for help on using the changeset viewer.