Skip to:
Content

bbPress.org

Changeset 3504


Ignore:
Timestamp:
09/10/2011 07:30:45 PM (10 years ago)
Author:
johnjamesjacoby
Message:

Introduce bbp_is_user_active() and bbp_is_user_inactive() to help with spammed and deleted user checks. See #1630 and r3503.

Location:
branches/plugin/bbp-includes
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-includes/bbp-core-caps.php

    r3423 r3504  
    181181
    182182            // Add do_not_allow cap if user is spam or deleted
    183             if ( bbp_is_user_spammer( $user_id ) || bbp_is_user_deleted( $user_id ) )
     183            if ( bbp_is_user_inactive( $user_id ) )
    184184                $caps = array( 'do_not_allow' );
    185185
     
    195195
    196196                // Add 'do_not_allow' cap if user is spam or deleted
    197                 if ( bbp_is_user_spammer( $user_id ) || bbp_is_user_deleted( $user_id ) )
     197                if ( bbp_is_user_inactive( $user_id ) )
    198198                    $caps[] = 'do_not_allow';
    199199
     
    217217
    218218                // Add 'do_not_allow' cap if user is spam or deleted
    219                 if ( bbp_is_user_spammer( $user_id ) || bbp_is_user_deleted( $user_id ) )
     219                if ( bbp_is_user_inactive( $user_id ) )
    220220                    $caps[] = 'do_not_allow';
    221221
     
    239239
    240240                // Add 'do_not_allow' cap if user is spam or deleted
    241                 if ( bbp_is_user_spammer( $user_id ) || bbp_is_user_deleted( $user_id ) )
     241                if ( bbp_is_user_inactive( $user_id ) )
    242242                    $caps[] = 'do_not_allow';
    243243
     
    479479 * @uses is_multisite()
    480480 * @uses bbp_allow_global_access()
    481  * @uses bbp_is_user_deleted()
    482  * @uses bbp_is_user_spammer()
     481 * @uses bbp_is_user_inactive()
    483482 * @uses is_user_logged_in()
    484483 * @uses current_user_can()
     
    493492        return;
    494493
    495     // Bail if user is marked as spam or is deleted
    496     if ( bbp_is_user_deleted() || bbp_is_user_spammer() )
     494    // Bail if user is not active
     495    if ( bbp_is_user_inactive() )
    497496        return;
    498497
     
    562561 * @uses is_multisite()
    563562 * @uses bbp_allow_global_access()
    564  * @uses bbp_is_user_deleted()
    565  * @uses bbp_is_user_spammer()
     563 * @uses bbp_is_user_inactive()
    566564 * @uses is_user_logged_in()
    567565 * @uses current_user_can()
     
    579577
    580578    // Bail if user is marked as spam or is deleted
    581     if ( bbp_is_user_deleted() || bbp_is_user_spammer() )
     579    if ( bbp_is_user_inactive() )
    582580        return;
    583581
  • branches/plugin/bbp-includes/bbp-user-functions.php

    r3453 r3504  
    11861186}
    11871187
     1188/**
     1189 * Checks if user is active
     1190 *
     1191 * @since bbPress (r3502)
     1192 *
     1193 * @uses is_user_logged_in() To check if user is logged in
     1194 * @uses bbp_get_displayed_user_id() To get current user ID
     1195 * @uses bbp_is_user_spammer() To check if user is spammer
     1196 * @uses bbp_is_user_deleted() To check if user is deleted
     1197 *
     1198 * @param int $user_id The user ID to check
     1199 * @return bool True if public, false if not
     1200 */
     1201function bbp_is_user_active( $user_id = 0 ) {
     1202
     1203    // Default to current user
     1204    if ( empty( $user_id ) && is_user_logged_in() )
     1205        $user_id = bbp_get_current_user_id();
     1206
     1207    // No user to check
     1208    if ( empty( $user_id ) )
     1209        return false;
     1210
     1211    // Check spam
     1212    if ( bbp_is_user_spammer( $user_id ) )
     1213        return false;
     1214
     1215    // Check deleted
     1216    if ( bbp_is_user_deleted( $user_id ) )
     1217        return false;
     1218
     1219    // Assume true if not spam or deleted
     1220    return true;
     1221}
     1222
     1223/**
     1224 * Checks if user is not active.
     1225 *
     1226 * @since bbPress (r3502)
     1227 *
     1228 * @uses is_user_logged_in() To check if user is logged in
     1229 * @uses bbp_get_displayed_user_id() To get current user ID
     1230 * @uses bbp_is_user_active() To check if user is active
     1231 *
     1232 * @param int $user_id The user ID to check
     1233 * @return bool True if inactive, false if active
     1234 */
     1235function bbp_is_user_inactive( $user_id = 0 ) {
     1236
     1237    // Default to current user
     1238    if ( empty( $user_id ) && is_user_logged_in() )
     1239        $user_id = bbp_get_current_user_id();
     1240
     1241    // No user to check
     1242    if ( empty( $user_id ) )
     1243        return false;
     1244
     1245    // Return the inverse of active
     1246    return !bbp_is_user_active( $user_id );
     1247}
     1248
    11881249?>
  • branches/plugin/bbp-includes/bbp-user-template.php

    r3485 r3504  
    11551155 * @uses is_user_logged_in()
    11561156 * @uses bbp_allow_anonymous()
     1157 * @uses bbp_is_user_active()
    11571158 * @uses current_user_can()
    11581159 * @uses apply_filters()
     
    11741175
    11751176    // User is logged in
    1176     elseif ( !bbp_is_user_spammer() && !bbp_is_user_deleted() && current_user_can( 'publish_topics' ) )
     1177    elseif ( bbp_is_user_active() && current_user_can( 'publish_topics' ) )
    11771178        $retval = true;
    11781179
     
    11891190 * @uses is_user_logged_in()
    11901191 * @uses bbp_allow_anonymous()
     1192 * @uses bbp_is_user_active()
    11911193 * @uses current_user_can()
    11921194 * @uses apply_filters()
     
    12081210
    12091211    // User is logged in
    1210     elseif ( !bbp_is_user_spammer() && !bbp_is_user_deleted() && current_user_can( 'publish_replies' ) )
     1212    elseif ( bbp_is_user_active() && current_user_can( 'publish_replies' ) )
    12111213        $retval = true;
    12121214
     
    12881290
    12891291    // Looking at a single forum & forum is open
    1290     if ( ( bbp_is_single_forum() || is_page() || is_single() ) && bbp_is_forum_open() ) {
     1292    if ( ( bbp_is_single_forum() || is_page() || is_single() ) && bbp_is_forum_open() )
    12911293        $retval = bbp_current_user_can_publish_topics();
    12921294
    12931295    // User can edit this topic
    1294     } elseif ( bbp_is_topic_edit() ) {
     1296    elseif ( bbp_is_topic_edit() )
    12951297        $retval = current_user_can( 'edit_topic', bbp_get_topic_id() );
    1296     }
    12971298
    12981299    // Allow access to be filtered
     
    13231324
    13241325    // Looking at a single topic, topic is open, and forum is open
    1325     if ( ( bbp_is_single_topic() || is_page() || is_single() ) && bbp_is_topic_open() && bbp_is_forum_open() ) {
     1326    if ( ( bbp_is_single_topic() || is_page() || is_single() ) && bbp_is_topic_open() && bbp_is_forum_open() )
    13261327        $retval = bbp_current_user_can_publish_replies();
    13271328
    13281329    // User can edit this topic
    1329     } elseif ( bbp_is_reply_edit() ) {
     1330    elseif ( bbp_is_reply_edit() )
    13301331        $retval = current_user_can( 'edit_reply', bbp_get_reply_id() );
    1331     }
    13321332
    13331333    // Allow access to be filtered
Note: See TracChangeset for help on using the changeset viewer.