Skip to:
Content
Pages
Categories
Search
Top
Bottom

[bp_core.php] 2 bugs in bp_core_new_subnav_item and bp_core_remove_subnav_item

  • Avatar of calvin_42
    calvin_42
    Participant

    @calvin_42

    Hi there.

    I think I have discovered 2 bugs in bp_core.php and since I couldn’t log to TRAC, I post here.

    Version : all / trunk

    See http://trac.buddypress.org/browser/trunk/bp-core.php


    Function bp_core_new_subnav_item – Line 740


    Bug : $screen_function is not saved in the tab bp_options_nav.

    Patch : see below

    function bp_core_new_subnav_item( $args = '' ) {
    global $bp;

    $defaults = array(
    'name' => false, // Display name for the nav item
    'slug' => false, // URL slug for the nav item
    'parent_slug' => false, // URL slug of the parent nav item
    'parent_url' => false, // URL of the parent item
    'item_css_id' => false, // The CSS ID to apply to the HTML of the nav item
    'user_has_access' => true, // Can the logged in user see this nav item?
    'site_admin_only' => false, // Can only site admins see this nav item?
    'position' => 90, // Index of where this nav item should be positioned
    'screen_function' => false // The name of the function to run when clicked
    );

    $r = wp_parse_args( $args, $defaults );
    extract( $r, EXTR_SKIP );

    /* If we don't have the required info we need, don't create this subnav item */
    if ( empty($name) || empty($slug) || empty($parent_slug) || empty($parent_url) || empty($screen_function) )
    return false;

    /* If this is for site admins only and the user is not one, don't create the subnav item */
    if ( $site_admin_only && !is_site_admin() )
    return false;

    if ( empty( $item_css_id ) )
    $item_css_id = $slug;

    $bp->bp_options_nav[$parent_slug][$slug] = array(
    'name' => $name,
    'link' => $parent_url . $slug . '/',
    'slug' => $slug,
    'css_id' => $item_css_id,
    'position' => $position,
    'user_has_access' => $user_has_access,
    'screen_function' => $screen_function
    );

    if ( ( $bp->current_action == $slug && $bp->current_component == $parent_slug ) && $user_has_access ) {
    if ( !is_object( $screen_function[0] ) )
    add_action( 'wp', $screen_function, 3 );
    else
    add_action( 'wp', array( &$screen_function[0], $screen_function[1] ), 3 );
    }
    }


    Function bp_core_remove_subnav_item – Line 847


    Bug : $function variable has to be replaced by $screen_function variable instead

    Patch : see below

    function bp_core_remove_subnav_item( $parent_id, $slug ) {
    global $bp;

    $screen_function = $bp->bp_options_nav[$parent_id][$slug]['screen_function'];

    if ( $screen_function ) {
    if ( !is_object( $screen_function[0] ) )
    remove_action( 'wp', $screen_function, 3 );
    else
    remove_action( 'wp', array( &$screen_function[0], $screen_function[1] ), 3 );
    }

    unset( $bp->bp_options_nav[$parent_id][$slug] );

    if ( !count( $bp->bp_options_nav[$parent_id] ) )
    unset($bp->bp_options_nav[$parent_id]);
    }

    Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.