Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am trying to add_settings_section() by supplying a callback with parameter as follows:

class warpress_progression_plugin {
  function warpress_progression_plugin() {
    $this->__construct();
  }
  function __construct() {
    add_action('admin_init', array(&$this, 'plugin_admin_init'));
  }
  function plugin_admin_init() {
    $rows = $this->get_options_structure();
    for ($i = 0; $i < count($rows); $i++) {
      add_settings_section('expansion_'.$row->expansion_id,'',call_user_func(array(&$this, 'display_expansion'), $row->expansion),'warpress_progression'); // PROBLEM SEEMS TO BE HERE
    }
  }
  function display_expansion($expansion_name) {
    echo "<h3>" . $expansion_name . "</h3>";
  }
}

However, I'm getting the following error:

Warning: call_user_func() [function.call-user-func]: First argument is expected to be a valid callback

However, the echo of

"<h3>" . $expansion_name . "</h3>"

is occurring as I would have expected. What am I doing wrong here?

share|improve this question
add comment

1 Answer

Hi @Loni Huff:

Your Code, Reformatted:

It appear you are trying to call your callback with call_user_func() instead of just passing it. Reformatting your code, this is what you have:

add_settings_section(
  'expansion_' . $row->expansion_id, 
  '', 
  call_user_func(array(&$this, 'display_expansion'), $row->expansion),
  'warpress_progression'
); // PROBLEM SEEMS TO BE HERE

Equivalent to Your Code:

Which is basically the same thing as this:

add_settings_section(
  'expansion_' . $row->expansion_id, 
  '', 
  $this->display_expansion($row->expansion),
  'warpress_progression'
); 

Clearly not what add_settings_section() is expecting.

What I think you Want:

What I think you want (without having tested it) is simply this (and I edited the first parameter to use a coding style I prefer):

add_settings_section(
  "expansion_{$row->expansion_id}", 
  '', 
  array(&$this, 'display_expansion'),
  'warpress_progression'
); 

Let me know if that works for you.

share|improve this answer
    
Thank you for your response, Mike. That code doesn't throw any errors, but it also doesn't pass the value of $row->expansion to the display_expansion method. Perhaps that is simply not possible? Should I instead try to "push" that data outside of the plugin_admin_init function so that it's available to be used by the display_expansion function? –  user4446 Apr 5 '11 at 13:14
    
I believe I misunderstood how admin_init works and am restructuring my plugin so that this is no longer necessary. Thanks again for the response! –  user4464 Apr 5 '11 at 18:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.