*/ // add menu item function create_boilerplate_admin_page() { add_options_page('Boilerplate Admin', 'Boilerplate Admin', 'administrator', 'boilerplate-admin', 'build_boilerplate_admin_page'); } add_action('admin_menu', 'create_boilerplate_admin_page'); // menu item click callback function build_boilerplate_admin_page() { ?>

Boilerplate Admin

The choice is yours, you want it or not?

'.PHP_EOL; } add_action('admin_head', 'admin_register_head'); // add fields to admin form function register_and_build_fields() { register_setting('plugin_options', 'plugin_options', 'validate_setting'); add_settings_section('main_section', '', 'section_cb', 'boilerplate-admin'); add_settings_field('handheld_css', 'Handheld CSS?:', 'handheld_css_setting', 'boilerplate-admin', 'main_section'); add_settings_field('print_css', 'Print CSS?:', 'print_css_setting', 'boilerplate-admin', 'main_section'); add_settings_field('modernizr_js', 'Modernizr JS?:', 'modernizr_js_setting', 'boilerplate-admin', 'main_section'); add_settings_field('jquery_js', 'jQuery JS?:', 'jquery_js_setting', 'boilerplate-admin', 'main_section'); add_settings_field('plugins_js', 'jQuery Plug-ins JS?:', 'plugins_js_setting', 'boilerplate-admin', 'main_section'); add_settings_field('site_js', 'Site-specific JS?:', 'site_js_setting', 'boilerplate-admin', 'main_section'); add_settings_field('belated_png_js', 'Belated PNG JS?:', 'belated_png_js_setting', 'boilerplate-admin', 'main_section'); add_settings_field('yahoo_profiling_js', 'Yahoo! Profiling JS?:', 'yahoo_profiling_js_setting', 'boilerplate-admin', 'main_section'); } add_action('admin_init', 'register_and_build_fields'); // process form submission 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 { // else, the user didn't upload a file, retain the image that's already on file. $options = get_option('plugin_options'); $plugin_options[$keys[$i]] = $options[$keys[$i]]; } $i++; } return $plugin_options; } // in case you need it... function section_cb() {} // callback fn for handheld CSS function handheld_css_setting() { $options = get_option('plugin_options'); $checked = ($options['handheld_css']) ? 'checked="checked" ' : ''; echo ' (File location: '.get_bloginfo('template_directory') . '/css/handheld.css)'; } // callback fn for print CSS function print_css_setting() { $options = get_option('plugin_options'); $checked = ($options['print_css']) ? 'checked="checked" ' : ''; echo ' (File location: '.get_bloginfo('template_directory') . '/css/print.css)'; } // callback fn for Modernizr JS function modernizr_js_setting() { $options = get_option('plugin_options'); $checked = ($options['modernizr_js']) ? 'checked="checked" ' : ''; echo ' (File location: '.get_bloginfo('template_directory') . '/js/handheld.js)'; } // callback fn for jQuery JS function jquery_js_setting() { $options = get_option('plugin_options'); $checked = ($options['jquery_js']) ? 'checked="checked" ' : ''; echo ' (File location: '.get_bloginfo('template_directory') . '/js/jquery-1.4.2.min.js)'; } // callback fn for Plug-ins JS function plugins_js_setting() { $options = get_option('plugin_options'); $checked = ($options['plugins_js']) ? 'checked="checked" ' : ''; echo ' (File location: '.get_bloginfo('template_directory') . '/js/plug-in.js)'; } // callback fn for Site-specific JS function site_js_setting() { $options = get_option('plugin_options'); $checked = ($options['site_js']) ? 'checked="checked" ' : ''; echo ' (File location: '.get_bloginfo('template_directory') . '/js/script.js)'; } // callback fn for Belated PNG JS function belated_png_js_setting() { $options = get_option('plugin_options'); $checked = ($options['belated_png_js']) ? 'checked="checked" ' : ''; echo ' (File location: '.get_bloginfo('template_directory') . '/js/dd_belatedpng.js)'; } // callback fn for Yahoo! Profiling JS function yahoo_profiling_js_setting() { $options = get_option('plugin_options'); $checked = ($options['yahoo_profiling_js']) ? 'checked="checked" ' : ''; echo ' (File location: '.get_bloginfo('template_directory') . '/js/profiling/config.js)'; } // $options['handheld_css'] function add_handheld_stylesheet() { wp_register_style( 'handheld', get_bloginfo('template_directory') . '/css/handheld.css', array(), '1.0', 'handheld' ); wp_enqueue_style( 'handheld'); } // $options['print_css']; implement as: http://www.alistapart.com/articles/return-of-the-mobile-stylesheet ? function add_print_stylesheet() { wp_register_style( 'print', get_bloginfo('template_directory') . '/css/print.css', array(), '1.0', 'print' ); wp_enqueue_style( 'print'); } // $options['modernizr_js'] function add_modernizr_script() { wp_deregister_script( 'modernizr' ); // get rid of any native Modernizr wp_register_script( 'modernizr', get_bloginfo('template_directory') . '/js/modernizr-1.5.min.js', array(), '1.0' ); wp_enqueue_script( 'modernizr' ); } // $options['jquery_js'] function add_jquery_script() { wp_deregister_script( 'jquery' ); // get rid of WP's jQuery wp_register_script( 'jquery', get_bloginfo('template_directory') . '/js/jquery-1.4.2.min.js', array(), '1.0', true ); wp_enqueue_script( 'jquery' ); } // $options['plugins_js'] function add_plugin_script() { wp_register_script( 'plug_ins', get_bloginfo('template_directory') . '/js/plugins.js', array('jquery'), '1.0', true ); wp_enqueue_script( 'plug_ins' ); } // $options['site_js'] function add_site_script() { wp_register_script( 'site_script', get_bloginfo('template_directory') . '/js/script.js', array(), '1.0', true ); wp_enqueue_script( 'site_script' ); } // $options['belated_png_js'] function add_belated_png_script() { echo ''.PHP_EOL; } // $options['yahoo_profiling_js'] function add_yahoo_profiling_script() { wp_register_script( 'yahoo_profiling', get_bloginfo('template_directory') . '/js/profiling/yahoo-profiling.min.js', array(), '1.0', true ); wp_enqueue_script( 'yahoo_profiling' ); wp_register_script( 'yahoo_profiling_config', get_bloginfo('template_directory') . '/js/profiling/config.js', array(), '1.0', true ); wp_enqueue_script( 'yahoo_profiling_config' ); } // add Boilerplate files to page, as requested if (!is_admin() ) { $options = get_option('plugin_options'); if ($options['handheld_css']) {add_action('wp_print_styles', 'add_handheld_stylesheet');} if ($options['print_css']) {add_action('wp_print_styles', 'add_print_stylesheet');} if ($options['modernizr_js']) {add_action('wp_loaded', 'add_modernizr_script');} if ($options['jquery_js']) {add_action('wp_loaded', 'add_jquery_script');} if ($options['plugins_js']) {add_action('wp_loaded', 'add_plugin_script');} if ($options['site_js']) {add_action('wp_loaded', 'add_site_script');} if ($options['belated_png_js']) {add_action('wp_footer', 'add_belated_png_script');} if ($options['yahoo_profiling_js']) {add_action('wp_loaded', 'add_yahoo_profiling_script');} } /* End customization for Boilerplate */ ?>