Shrink down register_settings on Settings API

Instead of having so many function calls, is there a way that I can have one function call and all the fields under one section and then just call one section on the form?

/**
* Register each section
*/
function register_insta_heading()
{
register_setting(‘instagram-settings’,’insta_heading’,”);
add_settings_section(”,”,”,’insta_heading_field’);
add_settings_field(”,’Heading’,’heading_display’, ‘insta_heading_field’,”);
}

function register_insta_username()
{
register_setting(‘instagram-settings’,’insta_username’);
add_settings_section(”,”,”,’insta_username_field’);
add_settings_field(”,’Username’,’username_display’,’insta_username_field’,”);
}

function register_insta_id()
{
register_setting(‘instagram-settings’,’insta_id’);
add_settings_section(”,”,”,’insta_id_field’);
add_settings_field(”,’Instagram ID’,’id_display’,’insta_id_field’,”);}

function register_insta_posts()
{
register_setting(‘instagram-settings’,’insta_posts’);
add_settings_section(”,”,”,’posts_number_field’);
add_settings_field(”,’# of Posts’,’posts_number_display’,’posts_number_field’,”);
}

function register_insta_accesstoken()
{
register_setting(‘instagram-settings’,’insta_accesstoken’);
add_settings_section(”,”,”,’access_token_field’);
add_settings_field(”,’Access Token’,’access_token_display’,’access_token_field’,”);
}

The form submit:

<?php
settings_fields( ‘instagram-settings’ );
do_settings_sections(“insta_heading_field”);
do_settings_sections(“insta_username_field”);
do_settings_sections(“insta_id_field”);
do_settings_sections(“posts_number_field”);
do_settings_sections(“access_token_field”);
submit_button();
?>

Read more here:: Shrink down register_settings on Settings API

Leave a Reply

Your email address will not be published. Required fields are marked *