Skip to:
Content

bbPress.org

Changeset 5657


Ignore:
Timestamp:
03/24/2015 12:47:54 PM (7 years ago)
Author:
johnjamesjacoby
Message:

Users: Update bbp_check_user_edit():

  • Update @uses in docblock
  • Add filters to allow overriding result & redirect_to URL
  • Bail instead of indent
  • Move bbp_get_displayed_user_id() into reusable variable

Fixes #2777.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/users/functions.php

    r5625 r5657  
    16961696 * This is hooked to 'bbp_template_redirect' and controls the conditions under
    16971697 * which a user can edit another user (or themselves.) If these conditions are
    1698  * met. We assume a user cannot perform this task, and look for ways they can
     1698 * met, we assume a user cannot perform this task, and look for ways they can
    16991699 * earn the ability to access this template.
    17001700 *
    17011701 * @since bbPress (r3605)
    17021702 *
    1703  * @uses bbp_is_topic_edit()
     1703 * @uses bbp_is_single_user_edit()
    17041704 * @uses current_user_can()
    1705  * @uses bbp_get_topic_id()
     1705 * @uses bbp_get_displayed_user_id()
    17061706 * @uses wp_safe_redirect()
    1707  * @uses bbp_get_topic_permalink()
     1707 * @uses bbp_get_user_profile_url()
    17081708 */
    17091709function bbp_check_user_edit() {
    17101710
    1711     // Bail if not editing a topic
     1711    // Bail if not editing a user
    17121712    if ( ! bbp_is_single_user_edit() ) {
    17131713        return;
     
    17161716    // Default to false
    17171717    $redirect = true;
     1718    $user_id  = bbp_get_displayed_user_id();
    17181719
    17191720    // Allow user to edit their own profile
     
    17221723
    17231724    // Allow if current user can edit the displayed user
    1724     } elseif ( current_user_can( 'edit_user', bbp_get_displayed_user_id() ) ) {
     1725    } elseif ( current_user_can( 'edit_user', $user_id ) ) {
    17251726        $redirect = false;
    17261727
     
    17301731    }
    17311732
    1732     // Maybe redirect back to profile page
    1733     if ( true === $redirect ) {
    1734         wp_safe_redirect( bbp_get_user_profile_url( bbp_get_displayed_user_id() ) );
    1735         exit();
    1736     }
     1733    // Allow conclusion to be overridden
     1734    $redirect = (bool) apply_filters( 'bbp_check_user_edit', $redirect, $user_id );
     1735
     1736    // Bail if not redirecting
     1737    if ( false === $redirect ) {
     1738        return;
     1739    }
     1740
     1741    // Filter redirect URL
     1742    $profile_url = bbp_get_user_profile_url( $user_id );
     1743    $redirect_to = apply_filters( 'bbp_check_user_edit_redirect_to', $profile_url, $user_id );
     1744
     1745    // Redirect
     1746    wp_safe_redirect( $redirect_to );
     1747    exit();
    17371748}
    17381749
Note: See TracChangeset for help on using the changeset viewer.