Thord Daniel Hedengren - Smashing WordPress_ Beyond the Blog-Wiley (2014)

(avery) #1

194 PART III • Using Plugins with WordPress


// Initiate smashings_settingsdemo_init() in admin
add_action( 'admin_init', 'smashings_settingsdemo_init' );

// Runs at the start of the section
function smashing_settings_section_callback() {
echo '<p>This is the section intro.</p>';
}

// The input sample setting
function smashing_sample_input_callback() {
// Leaving PHP for a while ?>
<input type="text" name="smashing_sample_input" value="<?php echo
get_option( 'smashing_sample_input' ); ?>" />
<?php }
// Back to PHP

// Sanitize
function smashing_settingsdemo_validate($input) {

// Encode
$newinput = esc_attr($input);
return $newinput;

}

?>

There you have it — an extremely simple settings page that will save your data in the database,
as shown in Figure 7-5.

Figure 7-5: The simple settings page, with some text saved.
Free download pdf