0

I'm using the Settings API to provide my admin-user with some options for a plugin I'm writing. I have about 30 text fields to output on the plugin options page so I have created a very general callback:

public function my_fields_callback( $args ) {

    $name = esc_attr( $args['name'] );
    $value = esc_attr( $args['value'] );
    echo "<input type='text' name='$name' value='$value' />";

}

The part I'm having problems with is the $args parameter in add_settings_field(). Specifically, I'm getting the following PHP debug notice:

Notice: Undefined index: height

Notice: Undefined index: weight

Here is how I'm adding my settings field(s):

add_settings_field( 'field-1', 'Field One', array( $this, 'my_fields_callback' ), 'slug', 'section', array( 'name' => 'settings[weight]', 'value' => $settings['weight'] ) );

add_settings_field( 'field-2', 'Field Two', array( $this, 'my_fields_callback' ), 'slug', 'section', array( 'name' => 'settings[height]', 'value' => $settings['height'] ) );

Why am I getting the 'undefined index' notice and how can I avoid this? I'm trying to pinpoint what I am doing wrong.

  • The array $settings has no width and height keys (indexes), which is why you're getting these errors. Where are you defining $settings? – engelen Jun 13 '14 at 14:17
  • Ah, that might be the problem. I haven't defined $settings. Where and how should I define it? – henrywright Jun 13 '14 at 14:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.