Wordpress - How to pass variable to add_settings_section() callback?

if you look at the do_settings_sections function more specifically the line 1164 where the callback function is being executed :

call_user_func($section['callback'], $section);

you can see that the $section array is being passed to the callback function, so you can identify the callback by the $section['id']

hope this make since.

Update

here is an example, if your add_settings_section callback for all sections was named oenology_hooks_section_callback then you can identify it like this:

function oenology_hooks_section_callback($section_passed){
    if ($section_passed['id'] == 'whatever_section_id'){
        //do stuff
    }
    if ($section_passed['id'] == 'whatever_section_id_number2'){
        //do other stuff
    }
 }

and by do stuff i mean do whatever you want to do with that section callback.


I know this is an old question but I'll throw my two cents in, just in case someone else comes along; a simpler way to do so would be do write you own modification of the add_settings_section() function, which would only add a callback args parameter at the end of it.

This would look like this ( or something like it )

function my_add_settings_section($id, $title, $callback, $page, $callbackargs) {

global $wp_settings_sections;

if ( !isset($wp_settings_sections) ) 
{
    $wp_settings_sections = array();
}

if ( !isset($wp_settings_sections[$page]) )
{
    $wp_settings_sections[$page] = array();
}

if ( !isset($wp_settings_sections[$page][$id]) )
{
    $wp_settings_sections[$page][$id] = array();
}

$wp_settings_sections[$page][$id] = array( 'id' => $id, 'title' => $title, 'callback' => $callback, 'callbackargs' => $callbackargs, 'page' => 'page' );
}

Now you would simply use this instead of the native wordpress function and access your callback args through the 'callbackargs' array key in a usual fashion, like this

function oenology_hooks_sections_callback( $section_passed ) {
   // Our callback arguments  
   $section_passed['callbackargs']
}

Which we could use to pass to some other function :

 function oenology_hooks_sections_callback( $section_passed ) {
   // Our callback arguments  
   $args = $section_passed['callbackargs'];
   some_other_function( $args );
}

Or the callback args could be an array themselves which we use :

function oenology_hooks_sections_callback( $section_passed ) {
   // Our callback arguments  
   if ( $section_passed['callbackargs']['stuff'] !== 'things' ) 
   {
       echo 'stuff is not things!";
   }
}

This is all possible because all add_settings_section() does is add a new array member to the $wp_settings_sections global variable, that new array member could be an array itself containing any number of keys with different names, which could be used, by any function that knew they were there. When do_settings_sections calls the call_user_func_array it passes a $sections paramater as Bainternet noted, this means that the entire array we added to $wp_settings_sections in my_add_settings_section() is passed into our callback, meaning we have access to every new array member we add to it such as the callbackargs allowing our function to have a full fledged callback.

Even though im sure that this might be obvious i thought that I'd just explain it in case someone who gets confused looks in.