添加foreach功能

I am trying to edit a wordpress php file with the following function :

add_action('userpro_after_profile_head','userpro_sc_bar', 99);
    function userpro_sc_bar( $args ) {
        global $userpro, $userpro_social;
        extract($args);

        ( display content buttons here )
}

I am trying to add a button to this function from a different plugin and I need to add the following global rules :

foreach ( $sellers['users'] as $seller ) {
                    $store_info = get_store_info( $seller->ID );
                    $store_url  = get_store_url( $seller->ID );
}

When I add the two lines $store_info and $store_url to the global rules, it works, but I'm not getting the $seller ID that is defined with the foreach argument

When I add the whole thing into the global rules like this :

add_action('userpro_after_profile_head','userpro_sc_bar', 99);
    function userpro_sc_bar( $args ) {
        global $userpro, $userpro_social;
        extract($args);
           foreach ( $sellers['users'] as $seller ) {
                    $store_info = get_store_info( $seller->ID );
                    $store_url  = get_store_url( $seller->ID );
           }
                   ( display content buttons here )
    }

It is no longer working.

It there a proper to combine these 2 together ??

I am not too familiar with wordpress... but could this be an issue with the $sellers variable?

I think the $sellers variable is not accessible from within your function.

Assuming $sellers is a global variable you could try:

add_action('userpro_after_profile_head','userpro_sc_bar', 99);
    function userpro_sc_bar( $args ) {
        global $userpro, $userpro_social, $sellers; // <-- Added $sellers
        extract($args);
           foreach ( $sellers['users'] as $seller ) {
                    $store_info = get_store_info( $seller->ID );
                    $store_url  = get_store_url( $seller->ID );
           }
                   ( display content buttons here )
    }

Ok, got is ,this works for me :

add_action('userpro_after_profile_head','userpro_sc_bar', 99);
    function userpro_sc_bar( $args ) {
        global $userpro, $userpro_social, $sellers; // <-- Added $sellers
        extract($args);
        $sellers = get_sellers(); // <-- Get $sellers
           foreach ( $sellers['users'] as $seller ) {
                    $store_info = get_store_info( $seller->ID );
                    $store_url  = get_store_url( $seller->ID );
           }
                   ( display content buttons here )
    }