Skip to:
Content

bbPress.org

Changeset 3127


Ignore:
Timestamp:
05/09/2011 08:36:05 AM (15 years ago)
Author:
johnjamesjacoby
Message:

Prevent "create topic" form from showing if current user cannot create topics or there are no public forums to create topics in. Fixes #1443.

Location:
branches/plugin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-includes/bbp-user-template.php

    r3126 r3127  
    10871087}
    10881088
     1089/** Forms *********************************************************************/
     1090
     1091/**
     1092 *
     1093 * @since bbPress (r3127)
     1094 *
     1095 * @uses bbp_get_forum_post_type()
     1096 * @uses bbp_exclude_forum_ids()
     1097 * @uses get_posts()
     1098 *
     1099 * @param type $args
     1100 * @return type
     1101 */
     1102function bbp_get_forums_for_current_user( $args = array() ) {
     1103
     1104    $defaults = array(
     1105        'post_type'   => bbp_get_forum_post_type(),
     1106        'child_of'    => '0',
     1107        'numberposts' => -1,
     1108        'post_status' => 'publish',
     1109    );
     1110    $r = wp_parse_args( $args, $defaults );
     1111
     1112    // Exclude forums the user cannot post to
     1113    $r = bbp_exclude_forum_ids( $r );
     1114
     1115    // Get the forums
     1116    if ( ! ( $posts = get_posts( $r ) ) )
     1117        $posts = false;
     1118
     1119    return apply_filters( 'bbp_get_forums_for_current_user', $posts );
     1120}
     1121
     1122/**
     1123 * Performs a series of checks to ensure the current user can create topics.
     1124 *
     1125 * @since bbPress (r3127)
     1126 *
     1127 * @uses bbp_get_forums_for_current_user()
     1128 * @uses bbp_is_topic_edit()
     1129 * @uses current_user_can()
     1130 * @uses bbp_get_topic_id()
     1131 * @uses bbp_allow_anonymous()
     1132 * @uses is_user_logged_in()
     1133 *
     1134 * @return bool
     1135 */
     1136function bbp_current_user_can_access_create_topic_form() {
     1137    if ( bbp_get_forums_for_current_user() && ( ( bbp_is_topic_edit() && current_user_can( 'edit_topic', bbp_get_topic_id() ) ) || current_user_can( 'publish_topics' ) || ( bbp_allow_anonymous() && !is_user_logged_in() ) ) )
     1138        return true;
     1139
     1140    return false;
     1141}
     1142
     1143/**
     1144 * Performs a series of checks to ensure the current user can create topics in
     1145 * this specific forum or scope.
     1146 *
     1147 * @since bbPress (r3127)
     1148 *
     1149 * @uses bbp_is_forum_category()
     1150 * @uses bbp_is_forum_closed()
     1151 * @uses current_user_can()
     1152 * @uses bbp_get_topic_forum_id()
     1153 * @uses bbp_is_topic_edit()
     1154 *
     1155 * @return bool
     1156 */
     1157function bbp_current_user_can_create_topic_in_forum() {
     1158    if ( ( !bbp_is_forum_category() && ( !bbp_is_forum_closed() || current_user_can( 'edit_forum', bbp_get_topic_forum_id() ) ) ) || bbp_is_topic_edit() )
     1159        return true;
     1160
     1161    return false;
     1162}
     1163
     1164
    10891165?>
  • branches/plugin/bbp-themes/bbp-twentyten/bbpress/form-topic.php

    r3105 r3127  
    1313?>
    1414
    15 <?php if ( ( bbp_is_topic_edit() && current_user_can( 'edit_topic', bbp_get_topic_id() ) ) || current_user_can( 'publish_topics' ) || ( bbp_allow_anonymous() && !is_user_logged_in() ) ) : ?>
     15<?php if ( bbp_current_user_can_access_create_topic_form() ) : ?>
    1616
    17     <?php if ( ( !bbp_is_forum_category() && ( !bbp_is_forum_closed() || current_user_can( 'edit_forum', bbp_get_topic_forum_id() ) ) ) || bbp_is_topic_edit() ) : ?>
     17    <?php if ( bbp_current_user_can_create_topic_in_forum() ) : ?>
    1818
    1919        <div id="new-topic-<?php bbp_topic_id(); ?>" class="bbp-topic-form">
Note: See TracChangeset for help on using the changeset viewer.