Skip to content

Instantly share code, notes, and snippets.

@ChrisFlannagan
Last active May 31, 2016 16:24
Show Gist options
  • Save ChrisFlannagan/26264438230bad687680c8cf61a8f5fa to your computer and use it in GitHub Desktop.
Save ChrisFlannagan/26264438230bad687680c8cf61a8f5fa to your computer and use it in GitHub Desktop.
<?php
if( ! current_user_can( 'manage_options' ) ) {
exit();
}
$settings_color = "#fff";
if( isset( $_POST['settings_color'] ) && wp_verify_nonce( $_POST['_wpnonce'] ) ) {
update_option( "myplugin_settings_color", $_POST['settings_color'] );
if( isset( $_POST['feature_on'] ) ) {
update_option( "my_plugin_featureon", true );
} else {
update_option( "my_plugin_featureon", false );
}
echo "<p><strong>Settings Saved!</strong></p>";
}
if( get_option( "myplugin_settings_color" ) !== false ) {
$settings_color = get_option( "myplugin_settings_color" );
}
?>
<div class="wrap">
<h2>Plugin Settings</h2>
<form action="" method="post">
<?php wp_nonce_field(); ?>
<p><input name="feature_on" type="checkbox" <?php
if ( get_option( "myplugin_feature_on" ) !== false && get_option( "myplugin_feature_on" ) ) {
echo 'checked="checked" ';
}
?> /> Turn Feature On</p>
<p>Color: <input type="text" name="settings_color" value="<?php echo $settings_color; ?>" /></p>
<p><button type="submit">Save Settings</button></p>
</form>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment