| | 1605 | |
| | 1606 | function add_settings_section($id, $title, $callback, $page) { |
| | 1607 | global $wp_settings_sections; |
| | 1608 | |
| | 1609 | if ( !isset($wp_settings_sections) ) |
| | 1610 | $wp_settings_sections = array(); |
| | 1611 | if ( !isset($wp_settings_sections[$page]) ) |
| | 1612 | $wp_settings_sections[$page] = array(); |
| | 1613 | if ( !isset($wp_settings_sections[$page][$id]) ) |
| | 1614 | $wp_settings_sections[$page][$id] = array(); |
| | 1615 | |
| | 1616 | $wp_settings_sections[$page][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback); |
| | 1617 | } |
| | 1618 | |
| | 1619 | function add_settings_field($id, $title, $callback, $page, $section = 'default', $args = array()) { |
| | 1620 | global $wp_settings_fields; |
| | 1621 | |
| | 1622 | if ( !isset($wp_settings_fields) ) |
| | 1623 | $wp_settings_fields = array(); |
| | 1624 | if ( !isset($wp_settings_fields[$page]) ) |
| | 1625 | $wp_settings_fields[$page] = array(); |
| | 1626 | if ( !isset($wp_settings_fields[$page][$section]) ) |
| | 1627 | $wp_settings_fields[$page][$section] = array(); |
| | 1628 | |
| | 1629 | $wp_settings_fields[$page][$section][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $args); |
| | 1630 | } |
| | 1631 | |
| | 1632 | function do_settings_sections($page) { |
| | 1633 | global $wp_settings_sections, $wp_settings_fields; |
| | 1634 | |
| | 1635 | if ( !isset($wp_settings_sections) || !isset($wp_settings_sections[$page]) ) |
| | 1636 | return; |
| | 1637 | |
| | 1638 | foreach ( (array) $wp_settings_sections[$page] as $section ) { |
| | 1639 | echo "<h3>{$section['title']}</h3>\n"; |
| | 1640 | call_user_func($section['callback'], $section); |
| | 1641 | if ( !isset($wp_settings_fields) || !isset($wp_settings_fields[$page]) || !isset($wp_settings_fields[$page][$section['id']]) ) |
| | 1642 | continue; |
| | 1643 | echo '<table class="form-table">'; |
| | 1644 | do_settings_fields($page, $section['id']); |
| | 1645 | echo '</table>'; |
| | 1646 | } |
| | 1647 | } |
| | 1648 | |
| | 1649 | function do_settings_fields($page, $section) { |
| | 1650 | global $wp_settings_fields; |
| | 1651 | |
| | 1652 | if ( !isset($wp_settings_fields) || !isset($wp_settings_fields[$page]) || !isset($wp_settings_fields[$page][$section]) ) |
| | 1653 | return; |
| | 1654 | |
| | 1655 | foreach ( (array) $wp_settings_fields[$page][$section] as $field ) { |
| | 1656 | echo '<tr valign="top">'; |
| | 1657 | if ( !empty($field['args']['label_for']) ) |
| | 1658 | echo '<th scope="row"><label for="' . $field['args']['label_for'] . '">' . $field['title'] . '</label></th>'; |
| | 1659 | else |
| | 1660 | echo '<th scope="row">' . $field['title'] . '</th>'; |
| | 1661 | echo '<td>'; |
| | 1662 | call_user_func($field['callback']); |
| | 1663 | echo '</td>'; |
| | 1664 | echo '</tr>'; |
| | 1665 | } |
| | 1666 | } |
| | 1667 | |