I'm trying to learn how to make custom dashboard pages and settings in WordPress. The tutorial I followed was pretty clear...but there's one very small thing that doesn't make sense to me.
There is a line of code near the bottom of my funcions.php in the demo_footer_message_display()
function that says option['message']
. I don’t understand where ‘message’ is ever defined. If it said option[‘footer_message’] that would make plenty of sense because ‘footer_message’ is the id of the field I’m dealing with.
The code works fine but I just don’t understand why? Where is ‘message’ ever defined as an index of the options array. Can anyone explain this to me?
PS. in case it's not obvious my settings page just has an input where you can enter some text in the footer of the theme.
functions.php
<?php /* --------------------------------------------* * Menus /*---------------------------------------------*/ // Adds the 'DEMO THEME OPTIONS' to the 'Settings' menu in WordPress function demo_add_options_page(){ add_options_page( 'Lindsay Demo Theme Options', //browser title 'Lindsay Demo Theme Options', // menu text 'manage_options', // required capability of users to access this menu 'lindsay-demo-theme-options', // slug 'demo_theme_option_display' // name of function used to display content ); } add_action('admin_menu', 'demo_add_options_page'); /* --------------------------------------------* * Sections, Settings, and Fields /*---------------------------------------------*/ // Registers a new settings field on the 'Demo Theme Options' page function demo_initialize_theme_options(){ //section to be rendered on the new options page add_settings_section( 'footer_section', //id 'Footer Options', //title on screen 'demo_footer_options_display', //callback 'lindsay-demo-theme-options'//ID of page ); //define the settings field add_settings_field( 'footer_message', //ID of field 'Theme Footer Message', //label 'demo_footer_message_display', //callback 'lindsay-demo-theme-options', // page 'footer_section' // the section to add to ); //Register the 'footer_message' setting with the 'General' section register_setting( 'footer_section', //name of the group of settings 'footer_options' //name of option ); } //end demo_initialize_theme_options add_action('admin_init', 'demo_initialize_theme_options'); /* --------------------------------------------* * Callbacks /*---------------------------------------------*/ function demo_theme_option_display(){ ?> <div class="wrap"> <h2 >Demo Theme Options</h2> <form method="post" action="options.php"> <?php // render the settings for the settings section identified as 'Footer section' settings_fields('footer_section'); //render all of the settings for 'demo-theme-options' sections do_settings_sections('lindsay-demo-theme-options'); // add the submit button to serialize options submit_button(); ?> </form> </div> <?php } function demo_footer_message_display(){ $options = (array)get_option('footer_options'); $message = $options['message']; echo '<input type="text" name="footer_options[message]" id="footer_options_message" value="'.$message.'"/>'; } function demo_footer_options_display(){ echo 'These options are designed to help you control whats dislayed in your footer'; }
footer.php
<div id="footer" class="col-md-12">
<?php wp_footer() ?>
<div class="site-info">
<a href="http://wordpress.org/" title="A Semantic Personal Publishing Platform" rel="generator">Proudly Powered by WordPress</a>
<span class="sep"> | </span>
<?php $options = (array) get_option('footer_options');?>
<?php $message = $options['message'];?>
<span id="footer-message"><?php echo $message; ?></span>
</div>
</div>