Skip to:
Content

bbPress.org


Ignore:
Timestamp:
10/30/2011 03:39:45 AM (12 years ago)
Author:
johnjamesjacoby
Message:

Remove clever code from bbp-user-template.php. Introduce helper functions for accessing forum creation form. Pass user_nicename in profile URL functions. Fixes #1659 (plugin)

File:
1 edited

Legend:

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

    r3505 r3549  
    5757            $bbp_user_id = get_query_var( 'bbp_user_id' );
    5858
    59         return apply_filters( 'bbp_get_user_id', (int) $bbp_user_id );
     59        return (int) apply_filters( 'bbp_get_user_id', (int) $bbp_user_id, $displayed_user_fallback, $current_user_fallback );
    6060    }
    6161
     
    182182    function bbp_get_current_user_avatar( $size = 40 ) {
    183183
    184         if ( !$user = bbp_get_current_user_id() )
     184        $user = bbp_get_current_user_id();
     185        if ( empty( $user ) )
    185186            $user = bbp_get_current_anonymous_user_data( 'email' );
    186187
     
    213214     */
    214215    function bbp_get_user_profile_link( $user_id = 0 ) {
    215         if ( !$user_id = bbp_get_user_id( $user_id ) )
     216        $user_id = bbp_get_user_id( $user_id );
     217        if ( empty( $user_id ) )
    216218            return false;
    217219
     
    233235 */
    234236function bbp_user_profile_url( $user_id = 0, $user_nicename = '' ) {
    235     echo bbp_get_user_profile_url( $user_id );
     237    echo bbp_get_user_profile_url( $user_id, $user_nicename );
    236238}
    237239    /**
     
    331333 */
    332334function bbp_user_profile_edit_url( $user_id = 0, $user_nicename = '' ) {
    333     echo bbp_get_user_profile_edit_url( $user_id );
     335    echo bbp_get_user_profile_edit_url( $user_id, $user_nicename );
    334336}
    335337    /**
     
    352354        global $wp_rewrite, $bbp;
    353355
    354         if ( !$user_id = bbp_get_user_id( $user_id ) )
     356        $user_id = bbp_get_user_id( $user_id );
     357        if ( empty( $user_id ) )
    355358            return;
    356359
     
    408411            return;
    409412
    410         if ( $args && is_string( $args ) && false === strpos( $args, '=' ) )
     413        if ( $args && is_string( $args ) && ( false === strpos( $args, '=' ) ) )
    411414            $args = array( 'text' => $args );
    412415
     
    459462
    460463        // Get the author IP meta value
    461         if ( $author_ip = get_post_meta( $post_id, '_bbp_author_ip', true ) )
     464        $author_ip = get_post_meta( $post_id, '_bbp_author_ip', true );
     465        if ( !empty( $author_ip ) )
    462466            $author_ip = $before . $author_ip . $after;
    463467
     
    536540            return false;
    537541
    538         if ( !$user_id = bbp_get_user_id( $user_id, true, true ) )
     542        // Validate user and topic ID's
     543        $user_id  = bbp_get_user_id( $user_id, true, true );
     544        $topic_id = bbp_get_topic_id();
     545        if ( empty( $user_id ) || empty( $topic_id ) )
    539546            return false;
    540547
    541548        if ( !current_user_can( 'edit_user', (int) $user_id ) )
    542             return false;
    543 
    544         if ( !$topic_id = bbp_get_topic_id() )
    545549            return false;
    546550
     
    560564        }
    561565
    562         if ( $is_fav = bbp_is_user_favorite( $user_id, $topic_id ) ) {
     566        $is_fav = bbp_is_user_favorite( $user_id, $topic_id );
     567        if ( !empty( $is_fav ) ) {
    563568            $url  = esc_url( bbp_get_favorites_permalink( $user_id ) );
    564569            $rem  = preg_replace( '|%(.+)%|', "<a href='$url'>$1</a>", $rem );
     
    584589            $permalink = get_permalink();
    585590
    586         $url       = esc_url( wp_nonce_url( add_query_arg( $favs, $permalink ), 'toggle-favorite_' . $topic_id ) );
    587         $is_fav    = $is_fav ? 'is-favorite' : '';
    588         $html      = '<span id="favorite-toggle"><span id="favorite-' . $topic_id . '" class="' . $is_fav . '">' . $pre . '<a href="' . $url . '" class="dim:favorite-toggle:favorite-' . $topic_id . ':is-favorite">' . $mid . '</a>' . $post . '</span></span>';
     591        $url    = esc_url( wp_nonce_url( add_query_arg( $favs, $permalink ), 'toggle-favorite_' . $topic_id ) );
     592        $is_fav = $is_fav ? 'is-favorite' : '';
     593        $html   = '<span id="favorite-toggle"><span id="favorite-' . $topic_id . '" class="' . $is_fav . '">' . $pre . '<a href="' . $url . '" class="dim:favorite-toggle:favorite-' . $topic_id . ':is-favorite">' . $mid . '</a>' . $post . '</span></span>';
    589594
    590595        // Return the link
     
    671676        extract( $args );
    672677
    673         // Try to get a user_id
    674         if ( !$user_id = bbp_get_user_id( $user_id, true, true ) )
     678        // Validate user and topic ID's
     679        $user_id  = bbp_get_user_id( $user_id, true, true );
     680        $topic_id = bbp_get_topic_id( $topic_id );
     681        if ( empty( $user_id ) || empty( $topic_id ) )
    675682            return false;
    676683
     
    679686            return false;
    680687
    681         // No link if not viewing a topic
    682         if ( !$topic_id = bbp_get_topic_id( $topic_id ) )
    683             return false;
    684 
    685688        // Decine which link to show
    686         if ( $is_subscribed = bbp_is_user_subscribed( $user_id, $topic_id ) ) {
     689        $is_subscribed = bbp_is_user_subscribed( $user_id, $topic_id );
     690        if ( !empty( $is_subscribed ) ) {
    687691            $text = $unsubscribe;
    688692            $query_args  = array( 'action' => 'bbp_unsubscribe', 'topic_id' => $topic_id );
     
    11781182
    11791183    // Allow access to be filtered
    1180     return apply_filters( 'bbp_current_user_can_publish_topics', (bool) $retval );
     1184    return (bool) apply_filters( 'bbp_current_user_can_publish_forums', $retval );
     1185}
     1186
     1187/**
     1188 * Check if the current user can publish forums
     1189 *
     1190 * @since bbPress (r3549)
     1191 *
     1192 * @uses is_super_admin()
     1193 * @uses bbp_is_user_active()
     1194 * @uses current_user_can()
     1195 * @uses apply_filters()
     1196 *
     1197 * @return bool
     1198 */
     1199function bbp_current_user_can_publish_forums() {
     1200
     1201    // Users need to earn access
     1202    $retval = false;
     1203
     1204    // Always allow super admins
     1205    if ( is_super_admin() )
     1206        $retval = true;
     1207
     1208    // User is logged in
     1209    elseif ( bbp_is_user_active() && current_user_can( 'publish_forums' ) )
     1210        $retval = true;
     1211
     1212    // Allow access to be filtered
     1213    return (bool) apply_filters( 'bbp_current_user_can_publish_forums', $retval );
    11811214}
    11821215
     
    12131246
    12141247    // Allow access to be filtered
    1215     return apply_filters( 'bbp_current_user_can_publish_replies', (bool) $retval );
     1248    return (bool) apply_filters( 'bbp_current_user_can_publish_replies', $retval );
    12161249}
    12171250
     
    12671300
    12681301/**
     1302 * Performs a series of checks to ensure the current user can create forums.
     1303 *
     1304 * @since bbPress (r3549)
     1305 *
     1306 * @uses bbp_is_forum_edit()
     1307 * @uses current_user_can()
     1308 * @uses bbp_get_forum_id()
     1309 *
     1310 * @return bool
     1311 */
     1312function bbp_current_user_can_access_create_forum_form() {
     1313
     1314    // Always allow super admins
     1315    if ( is_super_admin() )
     1316        return true;
     1317
     1318    // Users need to earn access
     1319    $retval = false;
     1320
     1321    // Looking at a single forum & forum is open
     1322    if ( ( is_page() || is_single() ) && bbp_is_forum_open() )
     1323        $retval = bbp_current_user_can_publish_forums();
     1324
     1325    // User can edit this topic
     1326    elseif ( bbp_is_forum_edit() )
     1327        $retval = current_user_can( 'edit_forum', bbp_get_forum_id() );
     1328
     1329    // Allow access to be filtered
     1330    return (bool) apply_filters( 'bbp_current_user_can_access_create_forum_form', (bool) $retval );
     1331}
     1332
     1333/**
    12691334 * Performs a series of checks to ensure the current user can create topics.
    12701335 *
     
    12971362
    12981363    // Allow access to be filtered
    1299     return apply_filters( 'bbp_current_user_can_access_create_topic_form', (bool) $retval );
     1364    return (bool) apply_filters( 'bbp_current_user_can_access_create_topic_form', (bool) $retval );
    13001365}
    13011366
     
    13311396
    13321397    // Allow access to be filtered
    1333     return apply_filters( 'bbp_current_user_can_access_create_topic_form', (bool) $retval );
     1398    return (bool) apply_filters( 'bbp_current_user_can_access_create_reply_form', (bool) $retval );
    13341399}
    13351400
Note: See TracChangeset for help on using the changeset viewer.