I am creating wordpress theme on a single options page. I have customized the default do_settings_fields and do_settings_sections functions. my fields are displaying fine but when i am trying to save it, It won't save.
function amna_theme_options_page () {
wp_enqueue_style( 'theme-options-css', get_template_directory_uri() . '/inc/admin/assets/css/theme-options-css.css' );
settings_errors();
?>
<div class="wrap flex-tab">
<form action='' method='post' class="amna-fields">
<?php
amna_do_settings_fields('amna-fields-group', 'theme_amna');
amna_do_settings_sections('theme_amna');
submit_button();
?>
</form>
</div>
<?php }
And these are the functions i have override to display fields
function amna_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">';
amna_do_settings_fields($page, $section['id']);
echo '</div>';
}
}
function amna_do_settings_fields($page, $section) {
global $wp_settings_fields;
if ( ! isset( $wp_settings_fields[ $page ][ $section ] ) ) {
return;
}
foreach ( (array) $wp_settings_fields[$page][$section] as $field ) { ?>
<div class="settings-form-row flex-tab">
<?php if ( !empty($field['args']['label_for']) )
echo '<p><label for="' . $field['args']['label_for'] . '">' .
$field['title'] . '</label><br />';
else
call_user_func($field['callback'], $field['args']);
echo '</p>';
echo '</div>';
}
}
options.php
and there should be a call toregister_setting()
in your code.