• I am working on learning how to build an admin area for my theme. I don’t understand how and why to use the following functions. I have read through the codex on these functions but still do not understand. Can you put it simply?

    register_setting
    add_settings_field()
    add_settings_section()
    settings_fields()

    I have been googling the crap out of the wordpress admin area and have found 5 different ways to do this. This is the latest method. I do have a form set up and I am testing. This is what I have now

    add_action('admin_menu', 'omr_create_menu');
    
    function omr_create_menu() {
    
    	//create new top-level menu
    	add_menu_page('Paradiso Options', 'Paradiso options', 'administrator', __FILE__, 'paradiso_settings_page', 'favicon.ico');
    
    	//call register settings function
    	add_action( 'admin_init', 'register_mysettings' );
    }
    
    function register_mySettings(){
    	register_setting('paradiso_group','paradiso_introText');
    }
    
    function paradiso_settings_page(){
    	?><div class="wrap">
    		<h2>Paradiso Options Page</h2>
    
    		<form method="post" action="options.php">
    			<?php settings_fields('paradiso_group'); ?>
    			<table class="form-table">
    			<tr valign="top">
    				<th scope="row">Intro Text</th>
    					<td><input type="text" name="paradiso_introText" value="<?php echo get_option('paradiso_introText');?>" /></td>
    			</tr>
    			</table>
    			<p class="submit"><input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>"  /></p>
    		</form>
    	</div><!--END wrap-->
    	<?php
    }
    ?>
    <?php

    I don’t understand why in the form I need this line
    <?php settings_fields('paradiso_group'); ?>

    For this one setting, is the code complete? am I missing anything? Is there a better way?

    Thank you for taking the time to answer this post. Your time is appreciated

  • The topic ‘please explain this code if you can’ is closed to new replies.