do_settings_fields

Print out the settings fields for a particular settings section.

Description

do_settings_fields( (string) $page, (string) $section ); 

Part of the Settings API. Use this in a settings page to output a specific section. Should normally be called by do_settings_sections() rather than directly.

Parameters (2)

0. $page (string)
Slug title of the admin page who's settings fields you want to show.
1. $section (string)
Slug title of the settings section who's fields you want to show.

Usage

  1. if ( !function_exists( 'do_settings_fields' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/template.php'; 
  3.  
  4. // Slug title of the admin page who's settings fields you want to show. 
  5. $page = ''; 
  6.  
  7. // Slug title of the settings section who's fields you want to show. 
  8. $section = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = do_settings_fields($page, $section); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/template.php  
  1. function do_settings_fields($page, $section) { 
  2. global $wp_settings_fields; 
  3.  
  4. if ( ! isset( $wp_settings_fields[$page][$section] ) ) 
  5. return; 
  6.  
  7. foreach ( (array) $wp_settings_fields[$page][$section] as $field ) { 
  8. $class = ''; 
  9.  
  10. if ( ! empty( $field['args']['class'] ) ) { 
  11. $class = ' class="' . esc_attr( $field['args']['class'] ) . '"'; 
  12.  
  13. echo "<tr{$class}>"; 
  14.  
  15. if ( ! empty( $field['args']['label_for'] ) ) { 
  16. echo '<th scope="row"><label for="' . esc_attr( $field['args']['label_for'] ) . '">' . $field['title'] . '</label></th>'; 
  17. } else { 
  18. echo '<th scope="row">' . $field['title'] . '</th>'; 
  19.  
  20. echo '<td>'; 
  21. call_user_func($field['callback'], $field['args']); 
  22. echo '</td>'; 
  23. echo '</tr>';