0

I have a plugin page with several settings. Four of this settings, all in the same section, need to be displayed inline rather than one above the other. However to ensure the settings are whitelisted, I must use the add_settings_field() function.

I can achieve most of my goal by passing a blank label and a callback to a function that outputs nothing for 3 of the options, and then add all four settings to the callback for the other. However doing so still adds a table row and thus leaves unnecessary white space for 3 of the options.

I've looked at the source of the add_settings_field() function, and all that does is add the setting to the $wp_settings_fields global. These settings are then output by the do_settings_fields() function, which has no obvious way of not outputting a table row.

Does anybody know of a way in which I can achieve all of my goal?

Here is how I am registering the settings -

/**
 * Register the settings that can be saved by this plugin
 */
public function register_plugin_settings(){

    add_settings_section(
        'aab_header_logo_section',                                      // ID
        __('What logo do you want to use?', 'djg-admin-area-branding'), // Title
        false,                                                          // Callback
        'djg_admin_area_branding_header'                                // Page
    );

    add_settings_field('header_logo_margin_top',//ID
        __('Header logo margin (px)', 'djg-admin-area-branding'), // Title
        array($this, '_option_header_logo_margin'),               // Callback
        'djg_admin_area_branding_header',                         // Page
        'aab_header_logo_section',                                // Section
        array(                                                    // Args
            'label_for' => 'header_logo_margin_top'
        ) 
    );

    add_settings_field(
        'header_logo_margin_right',
        false,
        array($this, '_null'),
        'djg_admin_area_branding_header',
        'aab_header_logo_section' 
    );

    add_settings_field(
        'header_logo_margin_bottom',
        false,
        array($this, '_null'),
        'djg_admin_area_branding_header',
        'aab_header_logo_section'
    );

    add_settings_field(
        'header_logo_margin_left',
        false,
        array($this, '_null'),
        'djg_admin_area_branding_header',
        'aab_header_logo_section'
    );

}
1

You should use register_setting() to whitelist an option. It won't affect the UI at all.

register_setting( 'my_option_group', 'my_option', 'optional_sanitize_callback' ); 
  • Ah, I get it now. I Did use register setting for each setting (should have added to question), and then I was also outputting each setting using add_settings_field(). So I'll just register one setting (header_logo_margin), make one call to add_settings_field(), and in the callback for that add four inputs with names like header_logo_margin[top]. Job done, thanks for the kick that made me think straight! – David Gard Apr 25 '14 at 11:01

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.