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 working on a plugin which uses Wordpress Settings API. I notice that the functions do_settings_sections (and do_settings_fields) display the fields using TABLE. How do I change its formatting? (I want to use DIV instead of TABLE)

share|improve this question
    
the settings api displays the fields the way you define in your callback function for each field. –  Bainternet Nov 13 '11 at 16:39
    
My problem is not displaying the fields, but displaying the whole section. I want it to be in DIVs rather than it TABLE... –  amellie Nov 13 '11 at 17:06
    
Whats your code? –  Bainternet Nov 13 '11 at 17:24

1 Answer 1

up vote 2 down vote accepted

There are no hooks to modify the output of do_settings_sections().

Hence the only option you have is to write custom versions of the functions do_settings_sections() and do_settings_fields(). They are located in /wp-admin/includes/template.php, lines 1159-1174 and 1190-1207 (wordpress version 3.2.1), respectively (do not modify them there).

You could (not saying it is necessarily advisable, consider compatibility with future versions of wp) include something like this in your plugin:

function custom_do_settings_sections($page) {
    global $wp_settings_sections, $wp_settings_fields;

    if ( !isset($wp_settings_sections) || !isset($wp_settings_sections[$page]) )
        return;

    foreach( (array) $wp_settings_sections[$page] as $section ) {
        echo "<h3>{$section['title']}</h3>\n";
        call_user_func($section['callback'], $section);
        if ( !isset($wp_settings_fields) ||
             !isset($wp_settings_fields[$page]) ||
             !isset($wp_settings_fields[$page][$section['id']]) )
                continue;
        echo '<div class="settings-form-wrapper">';
        custom_do_settings_fields($page, $section['id']);
        echo '</div>';
    }
}

function custom_do_settings_fields($page, $section) {
    global $wp_settings_fields;

    if ( !isset($wp_settings_fields) ||
         !isset($wp_settings_fields[$page]) ||
         !isset($wp_settings_fields[$page][$section]) )
        return;

    foreach ( (array) $wp_settings_fields[$page][$section] as $field ) {
        echo '<div class="settings-form-row">';
        if ( !empty($field['args']['label_for']) )
            echo '<p><label for="' . $field['args']['label_for'] . '">' .
                $field['title'] . '</label><br />';
        else
            echo '<p>' . $field['title'] . '<br />';
        call_user_func($field['callback'], $field['args']);
        echo '</p></div>';
    }
}
share|improve this answer
    
Thanks! Greatly appreciated. –  amellie Nov 13 '11 at 21:07
1  
This question was made 2 years ago and until now there is no hooks for this. Thanks! –  PabloKarzin Jan 9 at 0:29

Your Answer

 
discard

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

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