HPTOnline Posted November 24, 2013 Share Posted November 24, 2013 I am in the process of converting a widget plugin where the user inputs the settings via the widget page to where the user inputs the settings via an admin page. Everything is working fine, apart from the dropdown option. This is the settings field callback with the dropdown: <?php public function socialiconsselect_callback() { printf( '<select id="socialiconsselect" name="social_contact_display_options[socialiconsselect]" />', $options = array('Light', 'Dark', 'Modern Flat', 'Cute', 'Shaded', 'Simple Flat', 'Circle', 'Vintage', 'Retro', 'Retro 2', 'Wooden', 'CSS and HTML5 set 1', 'CSS and HTML5 set 2') foreach ($options as $option) { '<option value="' . $option . '" id="' . $option . '"', $socialiconsselect == $option ? ' selected="socialiconsselect"' : '', '>', $option, '</option>', } '</select>', isset( $this->options['socialiconsselect'] ) ? esc_attr( $this->options['socialiconsselect']) : '' ); } Can anyone see what I have done wrong? Put this through PHPStorm and corrected the syntax errors it stated, which gave me this: public function socialiconsselect_callback() { printf( '<select id="socialiconsselect" name="social_contact_display_options[socialiconsselect]" />', ($options = array('Light', 'Dark', 'Modern Flat', 'Cute', 'Shaded', 'Simple Flat', 'Circle', 'Vintage', 'Retro', 'Retro 2', 'Wooden', 'CSS and HTML5 set 1', 'CSS and HTML5 set 2'))); foreach ($options as $option) { '<option value="' . $option . '" id="' . $option . '"'; $socialiconsselect == $option ? ' selected="socialiconsselect"' : ''; '>'; $option; '</option>'; } '</select>'; isset( $this->options['socialiconsselect'] ) ? esc_attr( $this->options['socialiconsselect']) : '' ; } The page now loads, but still does not show any options in the dropdown.. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted November 24, 2013 Share Posted November 24, 2013 (edited) You are using printf incorrectly Change the function to public function socialiconsselect_callback() { $menu = '<select id="socialiconsselect" name="social_contact_display_options[socialiconsselect]" />'; $options = array('Light', 'Dark', 'Modern Flat', 'Cute', 'Shaded', 'Simple Flat', 'Circle', 'Vintage', 'Retro', 'Retro 2', 'Wooden', 'CSS and HTML5 set 1', 'CSS and HTML5 set 2'); $socialiconsselect = isset( $this->options['socialiconsselect'] ) ? esc_attr( $this->options['socialiconsselect']) : ''); foreach ($options as $option) { $menu .= '<option value="' . $option . '" id="' . $option . '"' . ($socialiconsselect == $option ? ' selected="socialiconsselect"' : '') . '>' .$option .'</option>'; } $menu .= '</select>'; return $menu; // return the html for the menu } You can then echo the method echo $obj->socialiconsselect_callback(); to display the menu Edited November 24, 2013 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
HPTOnline Posted November 24, 2013 Author Share Posted November 24, 2013 Thanks for the reply. Sorry, I should of also pointed out I am currently using the following code to display the form: public function create_admin_page() { // Set class property $this->options = get_option( 'social_contact_display_options' ); ?> <div class="wrap"> <?php screen_icon(); ?> <h2>Social Contact Display Settings</h2> <div id="scd-header"></div> <form method="post" action="options.php"> <?php // This prints out all hidden setting fields settings_fields( 'social_contact_display_options_group' ); do_settings_sections( 'social-contact-display-admin' ); submit_button(); ?> </form> </div> <?php } Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted November 24, 2013 Share Posted November 24, 2013 So what is calling the socialiconsselect_callback() method? Quote Link to comment Share on other sites More sharing options...
HPTOnline Posted November 24, 2013 Author Share Posted November 24, 2013 It is being called within "social_contact_display_options" as part of "social_contact_display_options_group". Quote Link to comment Share on other sites More sharing options...
HPTOnline Posted November 24, 2013 Author Share Posted November 24, 2013 I am starting to think it might just be easier to create the form directly within "public function create_admin_page()" instead of using callbacks.. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted November 24, 2013 Share Posted November 24, 2013 It is being called within "social_contact_display_options" as part of "social_contact_display_options_group". I wouldn't of known that.You just posted a few lines of code with no explanation of what does what. I am starting to think it might just be easier to create the form directly within "public function create_admin_page()" instead of using callbacks.. No Idea. Quote Link to comment Share on other sites More sharing options...
HPTOnline Posted November 24, 2013 Author Share Posted November 24, 2013 Sorry for being so vague, I will post more of the code in future... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.