I have a theme that I’m developing from an HTML template I have. I’m also designing an options page along with a plethora of plugins built-into the theme itself. I’ve chosen a tabbed interface and I’m trying to learn how to use WordPress’ Settings API.

I’m using a class structure for the theme’s functions. The following is the declaration of registering settings and whatnot.

public function __admin_init()
{
    register_setting( 'cncfps_twitter', 'cncfps_twitter_options', array( &$this, 'wp_cncfps_twitter' ) );
    add_settings_section( 'cncfps_twitter', 'Twitter', array( &$this, 'wp_cncfps_twitter' ), 'cncfps' );
    add_settings_field( 'cncfps_twitter_consumer_key', 'Consumer Key', array( &$this, 'twitter_consumer_key' ), 'cncfps', 'cncfps_twitter' );
    add_settings_field( 'cncfps_twitter_consumer_secret', 'Consumer Secret', array( &$this, 'twitter_consumer_secret' ), 'cncfps', 'cncfps_twitter' );
    add_settings_field( 'cncfps_twitter_apikey', 'API Key', array( &$this, 'twitter_apikey' ), 'cncfps', 'cncfps_twitter' );
}

public function wp_cncfps_twitter()
{
    // TODO: wut. ?!?!
    echo "what is this?";
}

public function twitter_consumer_key()
{
    echo "Hello";
}

public function twitter_consumer_secret()
{
    echo "World";
}

When I want to display the fields as shown here, I don’t see a thing. The following is how I attempt to display them. I did follow a few tutorials but it’s just not clicking in my brain for some reason.

settings_fields('cncfps_twitter');
do_settings_sections('cncfps_twitter');

enter image description here

2 Answers
2

The do_settings_section() function call needs to correspond to the $optiongroup argument you pass to register_setting(). To see how all of the myriad functions fit together, see page 10 of my tutorial.

It does get fairly confusing trying to follow how the various functions string together.

EDIT:

You do appear to be using the option group properly. Can you clarify what is/is not “clicking” for you? You mention in the title that you want to use a tabbed interface, but the question text itself doesn’t really indicate where exactly you’re running into difficulty.

Leave a Reply

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