Theme Options Settings

I have problem with my theme options settings saving.

My settings is to saving to permanently , its just only save when you stay on the theme options page after saving the settings. But when I go to any other page or reload the current page the settings disappeared.

function theme_options_do_page() {
        global  $theme_options, $icons_options, $new_values, $shortname, $values_array;

        if( !isset( $_REQUEST['submit'] ) ) {
            $_REQUEST['submit'] = false;
        }
    $values_array = array(
     array( 
               "name" => "Footer copyright text:",
               "desc" => "Enter text in the footer.",
               "id" => "footer_text",
               "type" => "text",
               "std" => array ('footer_text'=>$_POST['footer_text'],)
             ),
     array( 
               "name" => "Facebook URL :",
               "desc" => "Enter your Facebook URL here.",
               "id" => 'facebook',
               "type" => "text",
               "std" => array ('facebook'=>$_POST['facebook'],)
             ),
     array( 
               "name" => "Twitter URL :",
               "desc" => "Enter your Twitter URL here.",
               "id" => 'twitter',
               "type" => "text",
               "std" => array ('twitter'=>$_POST['twitter'],)
             ),
     array( 
               "name" => "Google+ URL :",
               "desc" => "Enter your Google+ URL here.",
               "id" => 'google',
               "type" => "text",
               "std" => array ('google'=>$_POST['google'],)
             ),
     array( 
               "name" => "Instagram URL :",
               "desc" => "Enter your Instagram URL here.",
               "id" => 'instagram',
               "type" => "text",
               "std" => array ('instagram'=>$_POST['instagram'],)
             ),
     array( 
               "name" => "Linkedin URL :",
               "desc" => "Enter your Linkedin URL here.",
               "id" => 'linkedin',
               "type" => "text",
               "std" => array ('linkedin'=>$_POST['linkedin'],)
             ),
     array( 
               "name" => "Pinterest URL :",
               "desc" => "Enter your Pinterest URL here.",
               "id" => 'pinterest',
               "type" => "text",
               "std" => array ('pinterest'=>$_POST['pinterest'],)
             ),
     array( 
               "name" => "Rss URL :",
               "desc" => "Enter your Rss URL here.",
               "id" => 'rss',
               "type" => "text",
               "std" => array ('rss'=>$_POST['rss'],)
             ),
     array( 
               "name" => "Stumbleupon URL :",
               "desc" => "Enter your Stumbleupon URL here.",
               "id" => 'stumbleupon',
               "type" => "text",
               "std" => array ('stumbleupon'=>$_POST['stumbleupon'],)
             ),
     array( 
               "name" => "Vimeo URL :",
               "desc" => "Enter your Vimeo URL here.",
               "id" => 'vimeo',
               "type" => "text",
               "std" => array ('vimeo'=>$_POST['vimeo'],)
             ),
     array( 
               "name" => "YouTube URL :",
               "desc" => "Enter your YouTube URL here.",
               "id" => 'youtube',
               "type" => "text",
               "std" => array ('youtube'=>$_POST['youtube'],)
             ),
        );
if ( $_GET['page'] == basename(__FILE__) ) {



        if (isset ( $_POST[ 'submit' ] ) ) {
            update_option( 'new_theme_options', serialize( $values_array )); 
        } 
    $theme_options = get_option('new_theme_options',false);
    $theme_values = unserialize($theme_options);

}

    if (isset ($_POST['submit'])) {
            $icons_size = array (
                'width'=>$_POST['width'],
                'height'=>$_POST['height'],
            );
            update_option('social_settings_responsivetheme_options', serialize($icons_size));
    };
    $icons_options = get_option('social_settings_responsivetheme_options');
    $icons_values = unserialize($icons_options);

    ?>
    <?php if( false !== $_REQUEST['submit'] ) : ?>
        <div class="updated fade"><p><strong><?php _e( 'Options Saved', 'responsivetheme' ); ?></strong></p></div>
    <?php endif; ?>
        <div class="wrap">
        <?php $theme_name = wp_get_theme() ?>
        <?php screen_icon(); echo "<h2>" . $theme_name . __( ' Options', 'responsivetheme' ) . "</h2>"; ?>




<form method="post" action="themes.php?page=theme-options.php">
<?php foreach ($values_array as  $value) {

?>
<table width="100%" border="0" style=" padding:10px;">
<?php 

?>

<?php 
?>
<tr>
<td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
<td width="80%"><input style="width:400px;" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" value="<?php foreach ($value['std'] as $key){echo $key;}?>" /></td>
</tr>
<tr>
<td><small><?php echo $value['desc']; ?></small></td>
</tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;">&nbsp;</td></tr><tr><td colspan="2">&nbsp;</td></tr>


<?php

}//end foreach
?>
</table>
    <p class="submit">
             <input type="submit" name="submit" class="button-primary"  id="submit" value="<?php _e( 'Save Options', 'responsivetheme' ); ?>" />
        </p>
    </form>
</div>

I hope I will get my problems solution.

Many thanks in advance.

I found my solution , But I have another problem, how to retrive from each option 'std' value?

like "std" => array ('footer_text'=>$_POST['footer_text'],)

how can I echo this value in the footer and each of that all social values too?

Please help me.

My old problem solution was
I changed from

foreach ($values_array as $value) to foreach ($theme_values as $value)

and now its working.

Hi,

I suggest you to install this plugin to your wordpress. It will resolve all your theme issues.

http://wordpress.org/plugins/option-tree/

You can setup and retrive all possible theme options like:
Background
Category Checkbox
Category Select
Checkbox
Color Picker
CSS
Custom Post Type Checkbox
Custom Post Type Select
Date Picker
Date Time Picker
Gallery and many more..

Please check and let me know.
Thanks,
Ajay

I already tried it.
this is not what I want.

I am developing my own theme and I want to add my own theme options as possible as more.
Thanks

It seems your output return as array i.e.

like "std" => array ('footer_text'=>$_POST['footer_text'],)

Try to fetch values as array.

Any example?
I dont know how to do it.

Hi,

Please echo the output like print_r($std) etc. and let me know. I think we need to make a function to get values from array etc.

Thanks,
Ajay

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.