0

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)

3
  • the settings api displays the fields the way you define in your callback function for each field.
    – Bainternet
    Commented Nov 13, 2011 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
    Commented Nov 13, 2011 at 17:06
  • Whats your code?
    – Bainternet
    Commented Nov 13, 2011 at 17:24

1 Answer 1

7

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>';
    }
}
1
  • 2
    This question was made 2 years ago and until now there is no hooks for this. Thanks! Commented Jan 9, 2014 at 0:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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