Adding Admin menus
-
Hi.
I have written a very simple plugin to add some menus to the ‘Reading’ admin page. They write the settings into the ‘Options’ table fine…. but when save button is pressed the page goes blank…. I have to manually navigate back to the admin section.There is obviously an error in my coding somewhere, but I cannot see it + I don’t have enough experience of using the Settings API to know what I’ve done wrong…… If I de-activate my plugin it all works as expected.
this is my code…. any help appreciated
<?php /* Plugin Name: Daves_Course_Report_Chooser Plugin URI: Description: This plugin allows you to switch on and off the course report flash file on the front page. Version: 1.0 Author: Dave Mills Author URI: License: A "Slug" license name e.g. GPL2 */ ?> <?php // ------------------------------------------------------------------ // Add all your sections, fields and settings during admin_init // ------------------------------------------------------------------ // function eg_settings_api_init() { // Add the section to reading settings so we can add our // fields to it add_settings_section('eg_setting_section', 'Course Status (Open / Closed)', 'eg_setting_section_callback_function', 'reading'); // Add the field with the names and function to use for our new // settings, put it in our new section //Course Status (Ticked = Open... Unticked = Closed add_settings_field('course_status', 'Course Status', 'eg_setting_callback_function', 'reading', 'eg_setting_section'); //A text box for the number of holes open add_settings_field('course_status_holes_open', 'Holes Open', 'holes_open_setting_callback_function', 'reading', 'eg_setting_section'); //A text box for the number of full greens in use. add_settings_field('course_status_full_green', 'Full Greens', 'full_greens_setting_callback_function', 'reading', 'eg_setting_section'); //A text box for the number of winter/temp greens in use add_settings_field('course_status_winter_greens', 'Winter Greens', 'winter_greens_setting_callback_function', 'reading', 'eg_setting_section'); //A text box for the full tees in use add_settings_field('course_status_full_tees', 'Full Tees', 'full_tees_setting_callback_function', 'reading', 'eg_setting_section'); //A text box for Yes/No as to whether buggies are allowed add_settings_field('course_status_buggies_allowed', 'Buggies', 'buggies_allowed_setting_callback_function', 'reading', 'eg_setting_section'); //A text box for Yes/No as to whether trolleys are allowed add_settings_field('course_status_trolleys_allowed', 'Trolleys', 'trolleys_allowed_setting_callback_function', 'reading', 'eg_setting_section'); //A text box for Yes/No as to whether placing on fairways is in operation add_settings_field('course_status_plaing_on_fairways', 'Placing', 'placing_setting_callback_function', 'reading', 'eg_setting_section'); // Register our setting so that $_POST handling is done for us and // our callback function just has to echo the <input> register_setting('reading','course_status'); register_setting('reading','course_status_holes_open'); register_setting('reading','course_status_full_green'); register_setting('reading','course_status_winter_greens'); register_setting('reading','course_status_full_tees'); register_setting('reading','course_status_buggies_allowed'); register_setting('reading','course_status_trolleys_allowed'); register_setting('reading','course_status_plaing_on_fairways'); } // eg_settings_api_init() add_action('admin_init', 'eg_settings_api_init'); // ------------------------------------------------------------------ // Settings section callback function // ------------------------------------------------------------------ // // This function is needed if we added a new section. This function // will be run at the start of our section // function eg_setting_section_callback_function() { echo '<p>This setting allows control of the flash file to display in the site heading... </br>Additionally the course report detail page can be edited from here...</p>'; } // ------------------------------------------------------------------ // Callback function for our example setting // ------------------------------------------------------------------ // // creates a checkbox true/false option. Other types are surely possible // function eg_setting_callback_function() { echo '<input name="course_status" id="gv_thumbnails_insert_into_excerpt" type="checkbox" value="1" class="code" ' . checked( 1, get_option('course_status'), false ) . ' /> Course Open?'; } function holes_open_setting_callback_function() { echo '<input name="course_status_holes_open" id="gv_thumbnails_insert_into_excerpt" type="input" class="code" value=' . ( get_option('course_status_holes_open') ) . ' /> Holes Open.'; } function full_greens_setting_callback_function() { echo '<input name="course_status_full_green" id="gv_thumbnails_insert_into_excerpt" type="input" class="code" value=' . ( get_option('course_status_full_green') ) . ' /> Full Greens.'; } function winter_greens_setting_callback_function() { echo '<input name="course_status_winter_greens" id="gv_thumbnails_insert_into_excerpt" type="input" class="code" value=' . ( get_option('course_status_winter_greens') ) . ' /> Winter Greens.'; } function full_tees_setting_callback_function() { echo '<input name="course_status_full_tees" id="gv_thumbnails_insert_into_excerpt" type="input" class="code" value=' . ( get_option('course_status_full_tees') ) . ' /> Full Tees.'; } function buggies_allowed_setting_callback_function() { echo '<input name="course_status_buggies_allowed" id="gv_thumbnails_insert_into_excerpt" type="input" class="code" value=' . ( get_option('course_status_buggies_allowed') ) . ' /> Buggies Allowed Yes/No.'; } function trolleys_allowed_setting_callback_function() { echo '<input name="course_status_trolleys_allowed" id="gv_thumbnails_insert_into_excerpt" type="input" class="code" value=' . ( get_option('course_status_trolleys_allowed') ) . ' /> Trolleys Allowed Yes/No.'; } function placing_setting_callback_function() { echo '<input name="course_status_plaing_on_fairways" id="gv_thumbnails_insert_into_excerpt" type="input" class="code" value=' . ( get_option('course_status_plaing_on_fairways') ) . ' /> Placing on Fairways Yes/No.'; } ?>
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Adding Admin menus’ is closed to new replies.