Skip to content

Instantly share code, notes, and snippets.

@roine
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roine/3cf9dc253d21cbbe8797 to your computer and use it in GitHub Desktop.
Save roine/3cf9dc253d21cbbe8797 to your computer and use it in GitHub Desktop.
wp have a checkbox in option page to be user specific saved
add_action( 'admin_init', 'register_modal_email_settings' );
function register_modal_email_settings()
{
if( !get_option( $user->user_nicename . '_plugin_options' ) ){
register_setting( 'section_email_modal', $user->user_nicename . '_plugin_options', '0' );
}
add_settings_section( 'section_foo', 'Foo settings', 'foo_desc', 'foo' );
add_settings_field( 'bar', 'Bar field', 'bar_option', 'foo', 'section_foo' );
}
function foo_desc()
{
return 'Description';
}
function bar_option()
{
$user = wp_get_current_user();
$checked = $this->email_modal_settings[$user->user_nicename.'_plugin_options'] ? 'checked' : '';
$name = $this->plugin_slug."[".$user->user_nicename."_plugin_options ]";
?>
<input type="checkbox" <?php echo $checked ?> name="<?php echo $name ?>" />
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment