WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

structure admin panel

I achieved this structure in wordpress admin panel. I am using wordpress option api to save and retrieve data from option.php .

All I want to do is on every click of add more image button one more browse image should appear so that I can upload as many images as I wanted and then all these images path should be stored in array in option.php after clicking save changes.

(banner heading is working properly I am able to upload 1 image and retrieve it but I want to do it for multiple images).

Any suggestions to make this work

here is my code


 function register_menu()
     add_options_page('slider setting', 'slider settings', 'manage_options', __FILE__, 'build_options_page');

 function build_options_page() 
     <div id="theme-options-wrap">    
         <div class="icon32" id="icon-tools"> <br /> </div>
             <h2>My Theme Options</h2>    
             <p>Take control of your theme, by overriding the default settings with your own specific preferences.</p>    
             <form method="post" action="options.php" enctype="multipart/form-data">  
                 <?php settings_fields('plugin_options'); ?>  
                 <?php do_settings_sections(__FILE__); ?>  <p class="submit">  
               <input name="Submit" type="submit" class="button-primary" value="<?php esc_attr_e('Save Changes'); ?>" /> 
 add_action('admin_init', 'register_and_build_fields');
 function register_and_build_fields() 
        register_setting('plugin_options', 'plugin_options', 'validate_setting');
        add_settings_section('main_section', 'Main Settings', 'section_cb', __FILE__);
        add_settings_field('banner_heading', 'Banner Heading:', 'banner_heading_setting', __FILE__, 'main_section');
        add_settings_field('logo[]', 'Logo:', 'logo_setting', __FILE__, 'main_section'); // LOGO
        add_settings_field('add_image', 'add image :', 'add_images', __FILE__, 'main_section'); // LOGO
 function validate_setting($plugin_options) 
      $keys = array_keys($_FILES);
       $i = 0; 
       foreach ( $_FILES as $image ) 
       {   // if a files was upload   
       if ($image['size']) 
       {     // if it is an image    
        if ( preg_match('/(jpg|jpeg|png|gif)$/', $image['type']) ) 
                $override = array('test_form' => false);      
 // save the file, and store an array, containing its location in $file       
 $file = wp_handle_upload( $image, $override );
       $plugin_options[$keys[$i]] = $file['url']; 
           } else {       // Not an image.      
             $options = get_option('plugin_options');  
                 $plugin_options[$keys[$i]] = $options[$logo];       // Die and let the user know that they made a mistake. 
                        wp_die('No image was uploaded.');     } 
             }   // Else, the user didn't upload a file.   // Retain the image that's already on file.  
              else {     $options = get_option('plugin_options');   
                $plugin_options[$keys[$i]] = $options[$keys[$i]];  
       return $plugin_options;
 function section_cb() 


 // Banner Heading
 function banner_heading_setting() 
       $options = get_option('plugin_options');
       echo "<input name='plugin_options[banner_heading]' type='text' value='{$options['banner_heading']}' />";
 global $multi_file_upload;
 function add_images()
     $add_more="<a name='add_images' href='#' class='button-primary' onclick='" .logo_setting() . "'>add more images</a>";
     echo $add_more;
 function logo_setting()
     $multi_file_upload.= '<input type="file" name="logo" />';
     echo "$multi_file_upload";
share|improve this question
Post your code please. – s_ha_dum May 22 '14 at 13:48
posted my code pls resolve my prob ty – user3378022 May 22 '14 at 13:56
This seems like a generic HTML/JavaScript issue - check out "jQuery add file input". – TheDeadMedic May 22 '14 at 14:23
logo_setting() is a PHP function, how is it going to insert new input field in the browser? you need to bind it to a javascript function, which would insert the appropriate input field in the dom. – MortalViews May 22 '14 at 14:29
@MortalViews i agree with you lets say i use jquery function to add another field then how you will register this field inside add_settings_field(); function and add input data to array ?? – user3378022 May 23 '14 at 8:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.