Changeset 3430
- Timestamp:
- 08/20/2011 10:15:21 PM (15 years ago)
- Location:
- branches/plugin/bbp-includes
- Files:
-
- 2 edited
-
bbp-core-hooks.php (modified) (1 diff)
-
bbp-forum-functions.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/plugin/bbp-includes/bbp-core-hooks.php
r3427 r3430 124 124 add_action( 'pre_get_posts', 'bbp_pre_get_posts', 2 ); 125 125 add_action( 'pre_get_posts', 'bbp_pre_get_posts_exclude_forums', 4 ); 126 add_action( 'template_redirect', 'bbp_forum_visibility_check', -1 ); 126 127 // Restrict forum access 128 add_action( 'template_redirect', 'bbp_forum_enforce_hidden', -1 ); 129 add_action( 'template_redirect', 'bbp_forum_enforce_private', -1 ); 127 130 128 131 // Profile Edit -
branches/plugin/bbp-includes/bbp-forum-functions.php
r3349 r3430 945 945 946 946 /** 947 * Check if it's a hidden forum or a topic or reply of a hidden forum and if 948 * the user can't view it, then sets a 404 949 * 950 * @since bbPress (r2996) 951 * 952 * @uses current_user_can() To check if the current user can read private forums 953 * @uses is_singular() To check if it's a singular page 954 * @uses bbp_get_forum_post_type() To get the forum post type 955 * @uses bbp_get_topic_post_type() To get the topic post type 956 * @uses bbp_get_reply_post_type() TO get the reply post type 957 * @uses bbp_get_topic_forum_id() To get the topic forum id 958 * @uses bbp_get_reply_forum_id() To get the reply forum id 959 * @uses bbp_is_forum_hidden() To check if the forum is hidden or not 960 * @uses bbp_set_404() To set a 404 status 961 */ 962 function bbp_forum_enforce_hidden() { 963 964 // Bail if not viewing a single item or if user has caps 965 if ( !is_singular() || is_super_admin() || current_user_can( 'read_hidden_forums' ) ) 966 return; 967 968 global $wp_query; 969 970 // Define local variable 971 $forum_id = 0; 972 973 // Check post type 974 switch ( $wp_query->get( 'post_type' ) ) { 975 976 // Forum 977 case bbp_get_forum_post_type() : 978 $forum_id = bbp_get_forum_id( $wp_query->post->ID ); 979 break; 980 981 // Topic 982 case bbp_get_topic_post_type() : 983 $forum_id = bbp_get_topic_forum_id( $wp_query->post->ID ); 984 break; 985 986 // Reply 987 case bbp_get_reply_post_type() : 988 $forum_id = bbp_get_reply_forum_id( $wp_query->post->ID ); 989 break; 990 991 } 992 993 // If forum is explicitly hidden and user not capable, set 404 994 if ( !empty( $forum_id ) && bbp_is_forum_hidden( $forum_id ) && !current_user_can( 'read_hidden_forums' ) ) 995 bbp_set_404(); 996 } 997 998 /** 947 999 * Check if it's a private forum or a topic or reply of a private forum and if 948 1000 * the user can't view it, then sets a 404 … … 960 1012 * @uses bbp_set_404() To set a 404 status 961 1013 */ 962 function bbp_forum_visibility_check() { 1014 function bbp_forum_enforce_private() { 1015 1016 // Bail if not viewing a single item or if user has caps 1017 if ( !is_singular() || is_super_admin() || current_user_can( 'read_private_forums' ) ) 1018 return; 1019 963 1020 global $wp_query; 964 1021 965 // Bail if not viewing a single item or if user has caps 966 if ( !is_singular() || is_super_admin() || ( current_user_can( 'read_private_forums' ) && current_user_can( 'read_hidden_forums' ) ) ) 967 return; 968 1022 // Define local variable 1023 $forum_id = 0; 1024 969 1025 // Check post type 970 1026 switch ( $wp_query->get( 'post_type' ) ) { … … 988 1044 989 1045 // If forum is explicitly hidden and user not capable, set 404 990 if ( !empty( $forum_id ) && bbp_is_forum_ hidden( $forum_id ) && !current_user_can( 'read_hidden_forums' ) )1046 if ( !empty( $forum_id ) && bbp_is_forum_private( $forum_id ) && !current_user_can( 'read_hidden_forums' ) ) 991 1047 bbp_set_404(); 992 1048 }
Note: See TracChangeset
for help on using the changeset viewer.