Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've been trying to follow this tutorial but instead of just spawning code into the functions.php file, I'm trying to build a personal framework, so I can use this in other projects.

Anyway, I wasn't able to date to make the settings fields appear in the Theme settings page. What am I doing wrong?



    class tee_configs{

        private static $ins = null;

        public static function instance()
            // create a new object if it doesn't exist.
            is_null(self::$ins) && self::$ins = new self;
            return self::$ins;

        public function init(){

            add_action( 'admin_init', array(self::instance(), ' init_settings_api_fields'));


        function sandbox_theme_display() {
            <!-- Create a header in the default WordPress 'wrap' container -->
            <div class="wrap">

                <div id="icon-themes" class="icon32"></div>
                <h2>Sandbox Theme Options</h2>
                <?php settings_errors(); ?>

                <form method="post" action="options.php">
                    <?php settings_fields( 'sandbox_theme_display_options' ); ?>
                    <?php do_settings_sections( 'sandbox_theme_display_options' ); ?>
                    <?php submit_button(); ?>

            </div><!-- /.wrap -->
        } // end sandbox_theme_display

        function sandbox_initialize_theme_options() {

            // If the theme options don't exist, create them.
            if( false == get_option( 'sandbox_theme_display_options' ) ) {
                add_option( 'sandbox_theme_display_options' );
            } // end if

            // First, we register a section. This is necessary since all future options must belong to a
                'general_settings_section',         // ID used to identify this section and with which to register options
                'Display Options',                  // Title to be displayed on the administration page
                'sandbox_general_options_callback', // Callback used to render the description of the section
                'sandbox_theme_display_options'     // Page on which to add this section of options

            // Next, we'll introduce the fields for toggling the visibility of content elements.
                'show_header',                      // ID used to identify the field throughout the theme
                'Header',                           // The label to the left of the option interface element
                'sandbox_toggle_header_callback',   // The name of the function responsible for rendering the option interface
                'sandbox_theme_display_options',    // The page on which this option will be displayed
                'general_settings_section',         // The name of the section to which this field belongs
                array(                              // The array of arguments to pass to the callback. In this case, just a description.
                    'Activate this setting to display the header.'

                    'Activate this setting to display the content.'

                    'Activate this setting to display the footer.'

            // Finally, we register the fields with WordPress

        } // end sandbox_initialize_theme_options

        function sandbox_general_options_callback() {
            echo '<p>Select which areas of content you wish to display.</p>';
        } // end sandbox_general_options_callback

        function sandbox_toggle_header_callback($args) {

            // First, we read the options collection
            $options = get_option('sandbox_theme_display_options');

            // Next, we update the name attribute to access this element's ID in the context of the display options array
            // We also access the show_header element of the options collection in the call to the checked() helper function
            $html = '<input type="checkbox" id="show_header" name="sandbox_theme_display_options[show_header]" value="1" ' . checked(1, $options['show_header'], false) . '/>';

            // Here, we'll take the first argument of the array and add it to a label next to the checkbox
            $html .= '<label for="show_header"> '  . $args[0] . '</label>';

            echo $html;

        } // end sandbox_toggle_header_callback

        function sandbox_toggle_content_callback($args) {

            $options = get_option('sandbox_theme_display_options');

            $html = '<input type="checkbox" id="show_content" name="sandbox_theme_display_options[show_content]" value="1" ' . checked(1, $options['show_content'], false) . '/>';
            $html .= '<label for="show_content"> '  . $args[0] . '</label>';

            echo $html;

        } // end sandbox_toggle_content_callback

        function sandbox_toggle_footer_callback($args) {

            $options = get_option('sandbox_theme_display_options');

            $html = '<input type="checkbox" id="show_footer" name="sandbox_theme_display_options[show_footer]" value="1" ' . checked(1, $options['show_footer'], false) . '/>';
            $html .= '<label for="show_footer"> '  . $args[0] . '</label>';

            echo $html;


share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.