Skip to:
Content

bbPress.org

Changeset 3605


Ignore:
Timestamp:
11/14/2011 03:33:48 AM (13 years ago)
Author:
johnjamesjacoby
Message:

Introduce bbp_template_redirect() and use for checking various edit screens:

  • Introduce bbp_check_topic_edit() to check for topic edit
  • Introduce bbp_check_reply_edit() to check for reply edit
  • Introduce bbp_check_topic_tag_edit() to check for topic tag edit
  • Introduce bbp_check_user_edit() to check for user edit
  • Remove these checks from bbp_pre_get_posts() and only use it to setup query vars
  • See #1684
  • For 2.0 branch
Location:
branches/2.0/bbp-includes
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/2.0/bbp-includes/bbp-common-template.php

    r3541 r3605  
    434434function bbp_is_user_home() {
    435435    global $bbp;
     436
     437    if ( !is_user_logged_in() )
     438        return false;
    436439
    437440    if ( empty( $bbp->displayed_user ) )
  • branches/2.0/bbp-includes/bbp-core-compatibility.php

    r3602 r3605  
    15711571        if ( !empty( $is_edit ) ) {
    15721572
    1573             // Only allow super admins on multisite to edit every user.
    1574             if ( !is_user_logged_in() || ( is_multisite() && !current_user_can( 'manage_network_users' ) && ( $user->ID != bbp_get_current_user_id() ) && !apply_filters( 'enable_edit_any_user_configuration', true ) ) || !current_user_can( 'edit_user', $user->ID ) ) {
    1575                 wp_die( __( 'You do not have the permission to edit this user.', 'bbpress' ) );
    1576             }
    1577 
    15781573            // We are editing a profile
    15791574            $posts_query->bbp_is_single_user_edit = true;
     
    16311626    // Topic/Reply Edit Page
    16321627    } elseif ( !empty( $is_edit ) ) {
    1633 
    1634         // Bail from edit if user is not logged in
    1635         if ( !is_user_logged_in() ) {
    1636             return;
    1637         }
    16381628
    16391629        // We are editing a topic
  • branches/2.0/bbp-includes/bbp-core-hooks.php

    r3515 r3605  
    3737add_action( 'generate_rewrite_rules', 'bbp_generate_rewrite_rules', 10 );
    3838add_action( 'wp_enqueue_scripts',     'bbp_enqueue_scripts',        10 );
     39add_action( 'template_redirect',      'bbp_template_redirect',      10 );
    3940add_filter( 'template_include',       'bbp_template_include',       10 );
    4041
     
    228229add_action( 'bbp_activation',   'flush_rewrite_rules' );
    229230add_action( 'bbp_deactivation', 'flush_rewrite_rules' );
     231
     232// Redirect user if needed
     233add_action( 'bbp_template_redirect', 'bbp_check_user_edit',      10 );
     234add_action( 'bbp_template_redirect', 'bbp_check_topic_edit',     10 );
     235add_action( 'bbp_template_redirect', 'bbp_check_reply_edit',     10 );
     236add_action( 'bbp_template_redirect', 'bbp_check_topic_tag_edit', 10 );
    230237
    231238/**
     
    710717}
    711718
     719/** Theme Permissions *********************************************************/
     720
     721/**
     722 * The main action used for redirecting bbPress theme actions that are not
     723 * permitted by the current_user
     724 *
     725 * @since bbPress (r3605)
     726 *
     727 * @uses do_action()
     728 */
     729function bbp_template_redirect() {
     730    do_action( 'bbp_template_redirect' );
     731}
     732
    712733?>
  • branches/2.0/bbp-includes/bbp-reply-functions.php

    r3544 r3605  
    14441444}
    14451445
     1446/** Permissions ***************************************************************/
     1447
     1448/**
     1449 * Redirect if unathorized user is attempting to edit a reply
     1450 *
     1451 * @since bbPress (r3605)
     1452 *
     1453 * @uses bbp_is_reply_edit()
     1454 * @uses current_user_can()
     1455 * @uses bbp_get_topic_id()
     1456 * @uses wp_safe_redirect()
     1457 * @uses bbp_get_topic_permalink()
     1458 */
     1459function bbp_check_reply_edit() {
     1460
     1461    // Bail if not editing a topic
     1462    if ( !bbp_is_reply_edit() )
     1463        return;
     1464
     1465    // User cannot edit topic, so redirect back to reply
     1466    if ( !current_user_can( 'edit_reply', bbp_get_reply_id() ) ) {
     1467        wp_safe_redirect( bbp_get_reply_url() );
     1468        exit();
     1469    }
     1470}
     1471
    14461472?>
  • branches/2.0/bbp-includes/bbp-topic-functions.php

    r3545 r3605  
    30423042}
    30433043
     3044/** Permissions ***************************************************************/
     3045
     3046/**
     3047 * Redirect if unathorized user is attempting to edit a topic
     3048 *
     3049 * @since bbPress (r3605)
     3050 *
     3051 * @uses bbp_is_topic_edit()
     3052 * @uses current_user_can()
     3053 * @uses bbp_get_topic_id()
     3054 * @uses wp_safe_redirect()
     3055 * @uses bbp_get_topic_permalink()
     3056 */
     3057function bbp_check_topic_edit() {
     3058
     3059    // Bail if not editing a topic
     3060    if ( !bbp_is_topic_edit() )
     3061        return;
     3062
     3063    // User cannot edit topic, so redirect back to topic
     3064    if ( !current_user_can( 'edit_topic', bbp_get_topic_id() ) ) {
     3065        wp_safe_redirect( bbp_get_topic_permalink() );
     3066        exit();
     3067    }
     3068}
     3069
     3070/**
     3071 * Redirect if unathorized user is attempting to edit a topic tag
     3072 *
     3073 * @since bbPress (r3605)
     3074 *
     3075 * @uses bbp_is_topic_tag_edit()
     3076 * @uses current_user_can()
     3077 * @uses bbp_get_topic_tag_id()
     3078 * @uses wp_safe_redirect()
     3079 * @uses bbp_get_topic_tag_link()
     3080 */
     3081function bbp_check_topic_tag_edit() {
     3082
     3083    // Bail if not editing a topic tag
     3084    if ( !bbp_is_topic_tag_edit() )
     3085        return;
     3086
     3087    // Bail if current user cannot edit topic tags
     3088    if ( !current_user_can( 'edit_topic_tags', bbp_get_topic_tag_id() ) ) {
     3089        wp_safe_redirect( bbp_get_topic_tag_link() );
     3090        exit();
     3091    }
     3092}
     3093
    30443094?>
  • branches/2.0/bbp-includes/bbp-user-functions.php

    r3505 r3605  
    12491249}
    12501250
     1251/** Premissions ***************************************************************/
     1252
     1253/**
     1254 * Redirect if unathorized user is attempting to edit a topic
     1255 *
     1256 * @since bbPress (r3605)
     1257 *
     1258 * @uses bbp_is_topic_edit()
     1259 * @uses current_user_can()
     1260 * @uses bbp_get_topic_id()
     1261 * @uses wp_safe_redirect()
     1262 * @uses bbp_get_topic_permalink()
     1263 */
     1264function bbp_check_user_edit() {
     1265
     1266    // Bail if not editing a topic
     1267    if ( !bbp_is_single_user_edit() )
     1268        return;
     1269
     1270    // Only allow super admins on multisite to edit every user.
     1271    if ( !is_user_logged_in() || ( is_multisite() && !current_user_can( 'manage_network_users' ) && bbp_is_user_home() && !apply_filters( 'enable_edit_any_user_configuration', true ) ) || !current_user_can( 'edit_user', bbp_get_displayed_user_id() ) ) {
     1272        wp_safe_redirect( bbp_get_user_profile_url( bbp_get_displayed_user_id() ) );
     1273        exit();
     1274    }
     1275}
     1276
    12511277?>
Note: See TracChangeset for help on using the changeset viewer.