To use setting option

function options_page_function_name(){

	 add_options_page( 'manu_title', 'menu name', 'manage_options', 'option-page', 'another_page_function_name', plugins_url( 'plugin_folder_name/images/icon.png' ),8 );


  // 4. Add setting option by used function. 
function register_settings_function_name() {
// Register settings and call sanitation functions
// 4. Add register setting. 
	register_setting( 'register_settings_name', 'demo_options_default', 'jeba_validate_options' );

add_action( 'admin_init', 'register_settings_function_name' );	

// 2. Add default value array. 
$demo_options_default = array(
	'jeba_use_demo' => 300,
	'jeba_control_radio_mode' => false,

  /*radio bottom option */
	    'label'=>'Active your single items'

	    'label'=>'Deactive your single items'

    if ( is_admin() ) : // 3. Load only if we are viewing an admin page	

 function another_page_function_name(){?>
 <?php // 5.1. Add settings API hook under form action.  ?>
<?php global $demo_options_default,$jeba_control_radio_mode ;

if ( ! isset( $_REQUEST['updated'] ) )
	$_REQUEST['updated'] = false; // This checks whether the form has just been submitted. 

   <div class="wrap">
	  <h2>scroll up setting</h2>
				  <?php if ( false !== $_REQUEST['updated'] ) : ?>
		<div class="updated fade"><p><strong><?php _e( 'Options saved' ); ?></strong></p></div>
		<?php endif; // 5.2. If the form has just been submitted, this shows the notification ?>	
	<form action="options.php" method="post">  
	<?php // 6.1 Add settings API hook under form action.  ?>
<?php $settings = get_option( 'demo_options_default', $demo_options_default ); ?>

<?php settings_fields( 'register_settings_name' );
/* 6.2  This function outputs some hidden fields required by the form,
including a nonce, a unique number used to ensure the form has been submitted from the admin page and not somewhere else, very important for security */ ?>

	<table class="form-table">
			<tr valign="top">
				<th scope="row"><label for="jeba_use_demo">scroll Distance</label></th>
						<input type="text" class="" value="<?php echo stripslashes($settings['jeba_use_demo']); ?>" id="jeba_use_demo" name="demo_options_default[jeba_use_demo]"/><p class="description">Distance from top/bottom before showing element (px)<br/>Best position is 200px to 300px</p>
			<tr valign="top">
				<th scope="row"><label for="jeba_control_radio_mode">single items mode</label></th>
					<?php foreach ( $jeba_control_radio_mode as $activate): ?>
					<input type="radio" id="<?php echo $activate['value']; ?>" name="demo_options_default[jeba_control_radio_mode]"  value="<?php esc_attr_e($activate['value']); ?>"<?php checked($settings['jeba_control_radio_mode'],$activate['value']); ?>  />
					<label for="<?php echo $activate['value']; ?>"><?php echo $activate ['label']; ?></label>
					<p class="description">You can add single items true or false</p><br/>
					<?php endforeach; ?>


<p class="submit">
<input type="submit" value="Save Changes" class="button button-primary" id="submit" name="submit">

  // 7. Add validate options. 
function jeba_validate_options( $input ) {
	global $demo_options_default,$jeba_control_radio_mode;

	$settings = get_option( 'demo_options_default', $demo_options_default );
	 // We strip all tags from the text field, to avoid vulnerablilties like XSS

 return $input;
	endif;  //3. EndIf is_admin()	
// danamic
function jeba_use_activator(){?>
<?php global $demo_options_default;

$bappiscroll_up_settings=get_option('demo_options_default','$demo_options_default'); ?>

	<!--use this where need dynamic data-->
	<?php echo $bappiscroll_up_settings['jeba_use_demo']; ?>
	<?php echo $bappiscroll_up_settings['jeba_control_radio_mode']; ?>



Note: Here show two option for jeba_use_demo and jeba_control_radio_mode . Can use more option.

Leave a Reply