Skip to:
Content

BuddyPress.org

Changeset 12281


Ignore:
Timestamp:
11/07/2018 04:09:00 PM (6 years ago)
Author:
boonebgorges
Message:

Avoid passing non-variables to empty() throughout codebase.

This ensures full compatibility with versions of PHP earlier than 5.5.

In some cases, we avoid the use of empty() by moving to its equivalent,
! isset( $foo ) || ! $foo. In some cases, we convert the tested value
to a variable before passing to empty().

See #7998.

Location:
trunk/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/bp-activity-filters.php

    r12112 r12281  
    323323    }
    324324
     325    $bp = buddypress();
     326
    325327    // If our temporary variable doesn't exist, stop now.
    326     if ( empty( buddypress()->activity->mentioned_users ) )
     328    if ( empty( $bp->activity->mentioned_users ) )
    327329        return;
    328330
    329331    // Grab our temporary variable from bp_activity_at_name_filter_updates().
    330     $usernames = buddypress()->activity->mentioned_users;
     332    $usernames = $bp->activity->mentioned_users;
    331333
    332334    // Get rid of temporary variable.
    333     unset( buddypress()->activity->mentioned_users );
     335    unset( $bp->activity->mentioned_users );
    334336
    335337    // Send @mentions and setup BP notifications.
  • trunk/src/bp-activity/bp-activity-functions.php

    r12154 r12281  
    2121 */
    2222function bp_activity_has_directory() {
    23     return (bool) !empty( buddypress()->pages->activity->id );
     23    return isset( buddypress()->pages->activity->id ) && buddypress()->pages->activity->id;
    2424}
    2525
  • trunk/src/bp-blogs/bp-blogs-activity.php

    r12169 r12281  
    11591159    // Initialize a local object so we won't have to query this again in the
    11601160    // comment loop.
    1161     if ( empty( buddypress()->blogs->allow_comments ) ) {
     1161    if ( ! isset( buddypress()->blogs->allow_comments ) ) {
    11621162        buddypress()->blogs->allow_comments = array();
    11631163    }
    1164     if ( empty( buddypress()->blogs->thread_depth ) ) {
     1164    if ( ! isset( buddypress()->blogs->thread_depth ) ) {
    11651165        buddypress()->blogs->thread_depth   = array();
    11661166    }
    1167     if ( empty( buddypress()->blogs->comment_moderation ) ) {
     1167    if ( ! isset( buddypress()->blogs->comment_moderation ) ) {
    11681168        buddypress()->blogs->comment_moderation = array();
    11691169    }
     
    12431243            // If comments are closed for the WP blog post, we should disable
    12441244            // activity comments for this activity entry.
    1245             if ( empty( buddypress()->blogs->allow_comments[ bp_get_activity_id() ] ) ) {
     1245            if ( ! isset( buddypress()->blogs->allow_comments[ bp_get_activity_id() ] ) || ! buddypress()->blogs->allow_comments[ bp_get_activity_id() ] ) {
    12461246                $retval = false;
    12471247            }
    12481248
    12491249            // If comments need moderation, disable activity commenting.
    1250             if ( ! empty( buddypress()->blogs->comment_moderation[ bp_get_activity_id() ] ) ) {
     1250            if ( isset( buddypress()->blogs->comment_moderation[ bp_get_activity_id() ] ) && buddypress()->blogs->comment_moderation[ bp_get_activity_id() ] ) {
    12511251                $retval = false;
    12521252            }
     
    13291329        // The blog post has closed off commenting, so we should disable all activity
    13301330        // comments under the parent 'new_blog_post' activity entry.
    1331         if ( empty( buddypress()->blogs->allow_comments[$comment->item_id] ) ) {
     1331        if ( ! buddypress()->blogs->allow_comments[ $comment->item_id ] ) {
    13321332            $retval = false;
    13331333        }
     
    13351335
    13361336    // If comments need moderation, disable activity commenting.
    1337     if ( ! empty( buddypress()->blogs->comment_moderation[$comment->item_id] ) ) {
     1337    if ( isset( buddypress()->blogs->comment_moderation[ $comment->item_id ] ) && buddypress()->blogs->comment_moderation[ $comment->item_id ] ) {
    13381338        $retval = false;
    13391339    }
  • trunk/src/bp-core/bp-core-functions.php

    r12259 r12281  
    25492549 */
    25502550function bp_nav_menu_get_loggedin_pages() {
     2551    $bp = buddypress();
    25512552
    25522553    // Try to catch the cached version first.
    2553     if ( ! empty( buddypress()->wp_nav_menu_items->loggedin ) ) {
    2554         return buddypress()->wp_nav_menu_items->loggedin;
     2554    if ( ! empty( $bp->wp_nav_menu_items->loggedin ) ) {
     2555        return $bp->wp_nav_menu_items->loggedin;
    25552556    }
    25562557
    25572558    // Pull up a list of items registered in BP's primary nav for the member.
    2558     $bp_menu_items = buddypress()->members->nav->get_primary();
     2559    $bp_menu_items = $bp->members->nav->get_primary();
    25592560
    25602561    // Some BP nav menu items will not be represented in bp_nav, because
     
    25912592    }
    25922593
    2593     if ( empty( buddypress()->wp_nav_menu_items ) ) {
     2594    if ( empty( $bp->wp_nav_menu_items ) ) {
    25942595        buddypress()->wp_nav_menu_items = new stdClass;
    25952596    }
    25962597
    2597     buddypress()->wp_nav_menu_items->loggedin = $page_args;
     2598    $bp->wp_nav_menu_items->loggedin = $page_args;
    25982599
    25992600    return $page_args;
     
    26152616 */
    26162617function bp_nav_menu_get_loggedout_pages() {
     2618    $bp = buddypress();
    26172619
    26182620    // Try to catch the cached version first.
    2619     if ( ! empty( buddypress()->wp_nav_menu_items->loggedout ) ) {
    2620         return buddypress()->wp_nav_menu_items->loggedout;
     2621    if ( ! empty( $bp->wp_nav_menu_items->loggedout ) ) {
     2622        return $bp->wp_nav_menu_items->loggedout;
    26212623    }
    26222624
     
    26652667    }
    26662668
    2667     if ( empty( buddypress()->wp_nav_menu_items ) ) {
    2668         buddypress()->wp_nav_menu_items = new stdClass;
    2669     }
    2670 
    2671     buddypress()->wp_nav_menu_items->loggedout = $page_args;
     2669    if ( empty( $bp->wp_nav_menu_items ) ) {
     2670        $bp->wp_nav_menu_items = new stdClass;
     2671    }
     2672
     2673    $bp->wp_nav_menu_items->loggedout = $page_args;
    26722674
    26732675    return $page_args;
  • trunk/src/bp-core/bp-core-template-loader.php

    r11447 r12281  
    563563 */
    564564function bp_is_template_included() {
    565     return ! empty( buddypress()->theme_compat->found_template );
     565    return isset( buddypress()->theme_compat->found_template ) && buddypress()->theme_compat->found_template;
    566566}
    567567
  • trunk/src/bp-core/bp-core-template.php

    r12224 r12281  
    139139
    140140    // Use the string provided by the component.
    141     if ( ! empty( buddypress()->{$component}->directory_title ) ) {
     141    if ( isset( buddypress()->{$component}->directory_title ) && buddypress()->{$component}->directory_title ) {
    142142        $title = buddypress()->{$component}->directory_title;
    143143
     
    11501150 */
    11511151function bp_account_was_activated() {
    1152     $activation_complete = ! empty( buddypress()->activation_complete ) || ( bp_is_current_component( 'activate' ) && ! empty( $_GET['activated'] ) );
     1152    $bp = buddypress();
     1153
     1154    $activation_complete = ! empty( $bp->activation_complete ) || ( bp_is_current_component( 'activate' ) && ! empty( $_GET['activated'] ) );
    11531155
    11541156    return $activation_complete;
     
    20822084            }
    20832085
    2084             if ( empty( buddypress()->$component->features ) || false === in_array( $feature, buddypress()->$component->features, true ) ) {
     2086            $component_features = isset( buddypress()->{$component}->features ) ? buddypress()->{$component}->features : array();
     2087
     2088            if ( empty( $component_features ) || false === in_array( $feature, $component_features, true ) ) {
    20852089                $retval = false;
    20862090            }
  • trunk/src/bp-core/bp-core-theme-compatibility.php

    r11987 r12281  
    687687
    688688    // Bail if the template already matches a BuddyPress template.
    689     if ( ! empty( buddypress()->theme_compat->found_template ) ) {
     689    if ( isset( buddypress()->theme_compat->found_template ) && buddypress()->theme_compat->found_template ) {
    690690        return $template;
    691691    }
  • trunk/src/bp-core/classes/class-bp-core-oembed-extension.php

    r11447 r12281  
    425425            // Add markers to tell that we're embedding a single activity.
    426426            // This is needed for various oEmbed response data filtering.
    427             if ( empty( buddypress()->{$this->slug_endpoint} ) ) {
     427            if ( ! isset( buddypress()->{$this->slug_endpoint} ) || ! buddypress()->{$this->slug_endpoint} ) {
    428428                buddypress()->{$this->slug_endpoint} = new stdClass;
    429429            }
     
    534534
    535535            // Add custom route args to iframe.
    536             if ( ! empty( buddypress()->{$this->slug_endpoint}->embedargs_in_progress ) ) {
     536            if ( isset( buddypress()->{$this->slug_endpoint}->embedargs_in_progress ) && buddypress()->{$this->slug_endpoint}->embedargs_in_progress ) {
    537537                foreach( buddypress()->{$this->slug_endpoint}->embedargs_in_progress as $key => $value ) {
    538538                    $url = add_query_arg( $key, $value, $url );
  • trunk/src/bp-groups/bp-groups-template.php

    r11938 r12281  
    56155615        if ( groups_get_current_group() ) {
    56165616            $r['group_id'] = bp_get_current_group_id();
    5617         } elseif ( ! empty( buddypress()->groups->new_group_id ) ) {
     5617        } elseif ( isset( buddypress()->groups->new_group_id ) && buddypress()->groups->new_group_id ) {
    56185618            $r['group_id'] = buddypress()->groups->new_group_id;
    56195619        }
Note: See TracChangeset for help on using the changeset viewer.