Skip to:
Content

bbPress.org


Ignore:
Timestamp:
01/30/2012 07:23:19 AM (14 years ago)
Author:
johnjamesjacoby
Message:

Add error handling to bbp_new_forum_handler() if forum parent is completely missing from POST request.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-includes/bbp-forum-functions.php

    r3716 r3727  
    171171    /** Forum Parent **********************************************************/
    172172
    173     // Cast Forum parent id to int
    174     $forum_parent_id = (int) $_POST['bbp_forum_parent_id'];
     173    // Forum parent was passed (the norm)
     174    if ( !empty( $_POST['bbp_forum_parent_id'] ) ) {
     175        $forum_parent_id = (int) $_POST['bbp_forum_parent_id'];
     176
     177    // No forum parent was passed (should never happen)
     178    } elseif ( !isset( $_POST['bbp_forum_parent_id'] ) ) {
     179        bbp_add_error( 'bbp_new_forum_missing_parent', __( '<strong>ERROR</strong>: Your forum must have a parent.', 'bbpress' ) );
     180    }
     181
     182    // Filter and sanitize
     183    $forum_parent_id = apply_filters( 'bbp_new_forum_pre_parent_id', $forum_parent_id );
    175184
    176185    // Forum exists
     
    178187
    179188        // Forum is a category
    180         if ( bbp_is_forum_category( $forum_parent_id ) )
    181             bbp_add_error( 'bbp_edit_forum_forum_category', __( '<strong>ERROR</strong>: This forum is a category. No forums can be created in this forum.', 'bbpress' ) );
     189        if ( bbp_is_forum_category( $forum_parent_id ) ) {
     190            bbp_add_error( 'bbp_new_forum_forum_category', __( '<strong>ERROR</strong>: This forum is a category. No forums can be created in this forum.', 'bbpress' ) );
     191        }
    182192
    183193        // Forum is closed and user cannot access
    184         if ( bbp_is_forum_closed( $forum_parent_id ) && !current_user_can( 'edit_forum', $forum_parent_id ) )
    185             bbp_add_error( 'bbp_edit_forum_forum_closed', __( '<strong>ERROR</strong>: This forum has been closed to new forums.', 'bbpress' ) );
     194        if ( bbp_is_forum_closed( $forum_parent_id ) && !current_user_can( 'edit_forum', $forum_parent_id ) ) {
     195            bbp_add_error( 'bbp_new_forum_forum_closed', __( '<strong>ERROR</strong>: This forum has been closed to new forums.', 'bbpress' ) );
     196        }
    186197
    187198        // Forum is private and user cannot access
    188         if ( bbp_is_forum_private( $forum_parent_id ) && !current_user_can( 'read_private_forums' ) )
    189             bbp_add_error( 'bbp_edit_forum_forum_private', __( '<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new forums in it.', 'bbpress' ) );
     199        if ( bbp_is_forum_private( $forum_parent_id ) && !current_user_can( 'read_private_forums' ) ) {
     200            bbp_add_error( 'bbp_new_forum_forum_private', __( '<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new forums in it.', 'bbpress' ) );
     201        }
    190202
    191203        // Forum is hidden and user cannot access
    192         if ( bbp_is_forum_hidden( $forum_parent_id ) && !current_user_can( 'read_hidden_forums' ) )
    193             bbp_add_error( 'bbp_edit_forum_forum_hidden', __( '<strong>ERROR</strong>: This forum is hidden and you do not have the capability to read or create new forums in it.', 'bbpress' ) );
     204        if ( bbp_is_forum_hidden( $forum_parent_id ) && !current_user_can( 'read_hidden_forums' ) ) {
     205            bbp_add_error( 'bbp_new_forum_forum_hidden', __( '<strong>ERROR</strong>: This forum is hidden and you do not have the capability to read or create new forums in it.', 'bbpress' ) );
     206        }       
    194207    }
    195208
Note: See TracChangeset for help on using the changeset viewer.