• I am trying to build a plugin option page and i already managed to build one. But the problem is the way the input fields are displayed. For example if there are 2 check boxes and 2 dropdown boxes its all appearing in a separate line. I am looking for a way so i can display 1 check box and dropdown box in one line and then in a new line another set of check box and drop down box will be showed. Is there any way to do that? or i have go with writing html manually.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Could be done with CSS if you haven’t tried that already. Do you have some sample code you could show here?

    Thread Starter Rashed Latif

    (@rashedlatif)

    This is a sample code but very similar to my code.

    class JW_Options{
        public $options;
    
        public function __construct(){
            //delete_option('jw_plugin_options');
            $this->options = get_option('jw_plugin_options');
            $this->register_setting_and_fields();  
    
        }
    
        public static function add_menu_page(){
            add_options_page('Theme Options', 'Theme Options', 'administrator', __FILE__, array('JW_Options', 'display_options_page'));
        }
    
        public static function display_options_page(){
            ?>
            <div class="wrap">
                <?php screen_icon(); ?>
                <h2>My Theme Options</h2>
                <?php print_r(get_option('jw_plugin_options'));?>
                <form method="post" action="options.php" enctype="multipart/form-data">
                    <?php settings_fields('jw_plugin_options'); ?>
                    <?php do_settings_sections(__FILE__); ?>
    
                    <P class="submit">
                        <input name="submit" type="submit" class="button-primary" value="Save Changes" />
    
                    </P>
                </form>
    
            </div>
    
            <?php
        }
    
        public function register_setting_and_fields(){
            register_setting('jw_plugin_options', 'jw_plugin_options', array($this, 'jw_validate_settings'));// 3rd param = optional call back function
            //register_setting('jw_plugin_options', 'jw_plugin_options');
            add_settings_section('jw_main_section', 'Main Settings', array($this, 'jw_main_section_cb'), __FILE__); // id,title of section, cb, which page?
            add_settings_field('jw_banner_heading', 'Banner Heading', array($this, 'jw_banner_heading_setting'), __FILE__, 'jw_main_section');
            add_settings_field('jw_logo', 'Your Logo', array($this, 'jw_logo_setting'), __FILE__, 'jw_main_section');
            add_settings_field('jw_color_scheme', 'Your Desired Color Scheme', array($this, 'jw_color_scheme_setting'), __FILE__, 'jw_main_section');
        }
    
        public function jw_main_section_cb(){
            //optional
        }
    
        public function jw_validate_settings($plugin_options){
            print_r($plugin_options);
        }
    
        /*
         *
         *Inputs
         *
         */
    
        // Banner Heading
        public function jw_banner_heading_setting(){
    
            echo "<input name='jw_plugin_options[jw_banner_heading]' type='text' value='{$this->options['jw_banner_heading']}' />";
            //echo "<input name='jw_plugin_options[jw_banner_heading]' type='text' value='' />";
        }
    
        public function jw_logo_setting(){
    
            echo '<input type= "file" />';
        }
    
        public function jw_color_scheme_setting(){
            $items = array('Red', 'Green', 'Blue', 'Yellow', 'Black', 'White');
            echo "<select name='jw_plugin_options[jw_color_scheme]'>";
            foreach ($items as $item){
                $selected = ($this->options['jw_color_scheme']== $item) ? 'selected="selected"' : '';
                echo "<option value='$item' $selected>$item</option>";
            }
            echo "</select>";
    
        }
    
    }
    
    add_action('admin_menu', function(){
        JW_Options::add_menu_page();
    });
    
    add_action('admin_init', function(){
        new JW_Options();
    });

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Help regarding add_settings_field’ is closed to new replies.