Skip to:
Content

BuddyPress.org

Changeset 7171


Ignore:
Timestamp:
06/06/2013 11:13:00 PM (11 years ago)
Author:
boonebgorges
Message:

Use is_callable() to validate screen_function callbacks before hooking in bp-core-buddybar.php

We were previously using is_object() and other custom verification techniques
to hook screen functions in bp_core_new_nav_item() and elsewhere. These
techniques are limited in that they allow certain sorts of uncallable strings
to pass through. We also should not be reinventing the wheel.

Fixes #4794

Props r-a-y

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-buddybar.php

    r6762 r7171  
    8282            unset( $bp->canonical_stack['action'] );
    8383        } elseif ( ! bp_current_action() ) {
    84             $func = is_object( $screen_function[0] ) ? array( &$screen_function[0], $screen_function[1] ) : $screen_function;
    85             add_action( 'bp_screens', $func, 3 );
     84
     85            // Add our screen hook if screen function is callable
     86            if ( is_callable( $screen_function ) ) {
     87                add_action( 'bp_screens', $screen_function, 3 );
     88            }
    8689
    8790            if ( !empty( $default_subnav_slug ) ) {
     
    113116
    114117    if ( $function = $bp->bp_nav[$parent_slug]['screen_function'] ) {
    115         if ( is_object( $function[0] ) ) {
    116             remove_action( 'bp_screens', array( &$function[0], $function[1] ), 3 );
    117         } else {
     118        // Remove our screen hook if screen function is callable
     119        if ( is_callable( $function ) ) {
    118120            remove_action( 'bp_screens', $function, 3 );
    119121        }
     
    137139        if ( empty( $unfiltered_action ) ) {
    138140            if ( !bp_is_current_action( $subnav_slug ) ) {
    139                 if ( is_object( $screen_function[0] ) ) {
    140                     add_action( 'bp_screens', array( &$screen_function[0], $screen_function[1] ), 3 );
    141                 } else {
     141                if ( is_callable( $screen_function ) ) {
    142142                    add_action( 'bp_screens', $screen_function, 3 );
    143143                }
     
    279279        // Before hooking the screen function, check user access
    280280        if ( !empty( $user_has_access ) ) {
    281             if ( is_object( $screen_function[0] ) ) {
    282                 add_action( 'bp_screens', array( &$screen_function[0], $screen_function[1] ), 3 );
    283             } else {
     281            // Add our screen hook if screen function is callable
     282            if ( is_callable( $screen_function ) ) {
    284283                add_action( 'bp_screens', $screen_function, 3 );
    285284            }
     
    391390
    392391    if ( $function = $bp->bp_nav[$parent_id]['screen_function'] ) {
    393         if ( is_object( $function[0] ) ) {
    394             remove_action( 'bp_screens', array( &$function[0], $function[1] ), 3 );
    395         } else {
     392        // Remove our screen hook if screen function is callable
     393        if ( is_callable( $function ) ) {
    396394            remove_action( 'bp_screens', $function, 3 );
    397395        }
     
    413411    $screen_function = isset( $bp->bp_options_nav[$parent_id][$slug]['screen_function'] ) ? $bp->bp_options_nav[$parent_id][$slug]['screen_function'] : false;
    414412
    415     if ( !empty( $screen_function ) ) {
    416         if ( is_object( $screen_function[0] ) ) {
    417             remove_action( 'bp_screens', array( &$screen_function[0], $screen_function[1] ), 3 );
    418         } else {
     413    if ( ! empty( $screen_function ) ) {
     414        // Remove our screen hook if screen function is callable
     415        if ( is_callable( $screen_function ) ) {
    419416            remove_action( 'bp_screens', $screen_function, 3 );
    420417        }
Note: See TracChangeset for help on using the changeset viewer.