Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

When I move a Wordpress custom option menu to the top level it stop saving input settings? -


this code adds menu in settings section of wordpress' administrator

right add_options_page declared, custom menu appears inside settings

i changed add_options_page add_menu_page in order bring menu top-level, stopped working (when click custom menu opens, can't save settings anymore).

what's remaining code have change in order make work?

thanks in advance!

<?php  add_action('admin_menu', 'create_theme_options_page'); add_action('admin_init', 'register_and_build_fields');  function create_theme_options_page() {    add_options_page('theme options', 'theme options', 'administrator', __file__, 'options_page_fn'); }  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('color_scheme', 'color scheme:', 'color_scheme_setting', __file__, 'main_section');    add_settings_field('logo', 'logo:', 'logo_setting', __file__, 'main_section'); // logo    add_settings_field('banner_heading', 'banner heading:', 'banner_heading_setting', __file__, 'main_section');    add_settings_field('adverting_information', 'advertising info:', 'advertising_information_setting', __file__, 'main_section');     add_settings_field('ad_one', 'ad:', 'ad_setting_one', __file__, 'main_section'); // ad1    add_settings_field('ad_two', 'second ad:', 'ad_setting_two', __file__, 'main_section'); // ad2 }  function options_page_fn() { ?> <div id="theme-options-wrap" class="widefat"> <div class="icon32" id="icon-tools"></div>  <h2>my theme options</h2> <p>take control of theme, overriding default settings 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'); ?>" /> </p> </form> </div> <?php }  // banner heading function banner_heading_setting() {    $options = get_option('plugin_options');    echo "<input name='plugin_options[banner_heading]' type='text' value='{$options['banner_heading']}' />"; }  // color scheme function color_scheme_setting() {    $options = get_option('plugin_options');    $items = array("white", "black", "#dddddd", "#444444");     echo "<select name='plugin_options[color_scheme]'>";    foreach ($items $item) {       $selected = ( $options['color_scheme'] === $item ) ? 'selected = "selected"' : '';       echo "<option value='$item' $selected>$item</option>";    }    echo "</select>"; }  // advertising info function advertising_information_setting() {    $options = get_option('plugin_options');    echo "<textarea name='plugin_options[advertising_information]' rows='10' cols='60' type='textarea'>{$options['advertising_information']}</textarea>"; }  // ad 1 function ad_setting_one() {    echo '<input type="file" name="ad_one" />'; }  // ad 2 function ad_setting_two() {    echo '<input type="file" name="ad_two" />'; }  // logo function logo_setting() {    echo '<input type="file" name="logo" />'; }  function validate_setting($plugin_options) {    $keys = array_keys($_files);    $i = 0;     foreach ($_files $image) {       // if files upload       if ($image['size']) {          // if image          if (preg_match('/(jpg|jpeg|png|gif)$/', $image['type'])) {             $override = array('test_form' => false);             $file = wp_handle_upload($image, $override);              $plugin_options[$keys[$i]] = $file['url'];          } else {             $options = get_option('plugin_options');             $plugin_options[$keys[$i]] = $options[$logo];             wp_die('no image uploaded.');          }       }        // else, retain image that's on file.       else {          $options = get_option('plugin_options');          $plugin_options[$keys[$i]] = $options[$keys[$i]];       }       $i++;    }     return $plugin_options; }  function section_cb() {}  // add stylesheet add_action('admin_head', 'admin_register_head');  function admin_register_head() {    $url = get_bloginfo('template_directory') . '/functions/options_page.css';    echo "<link rel='stylesheet' href='$url' />\n"; } 

supply proper handle when registering menu page(fourth parameter).

add menu example

add top level menu page

add_menu_page( 'theme options', 'theme options', 'manage_options', 'my-theme-options', 'options_page_fn' ); 

add submenu example

add submenu page new top level page

add_submenu_page( 'my-theme-options', 'theme sub1', 'theme sub1', 'manage_options', 'my-theme-options-subpage1', 'my_callback_function' ); 

hope helps..

and please consider posting future wordpress questions on wordpress stack exchange.

regarding main problem though, try updating do_settings_section call to..

<?php do_settings_sections( 'main_section' ); ?> 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -