Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Plugin Options not saving

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #37023
    Brightonmike
    Member

    For some reason, I cannot get my settings field to save with my plugin for WordPress. The parent settings save into the database, I can find “coffee_options” in my database. But not “coffee_Colour_string”. Any ideas where I’m going wrong? I followed a few different guides on the new settings API, never done this before.

    // add the admin options page
    add_action('admin_menu', 'coffee_admin_add_page');
    function coffee_admin_add_page() {
    add_options_page('Coffee Admin Theme Page', 'Coffee Admin Theme Menu', 'manage_options', 'coffee-admin-theme', 'coffee_options_page');
    }
    function coffee_options_page() {
    ?>

    Coffee Theme Settings


    Change the appearance of your theme.








    add_action('admin_init', 'coffee_admin_init');
    function coffee_admin_init(){
    register_setting('coffee_options', 'coffee_options', 'coffee_options_validate' );
    add_settings_section('coffee_main', 'Main Settings', 'coffee_section_text', 'coffee-admin-theme');
    add_settings_field('coffee_colour_string', 'Colour Scheme', 'coffee_setting_string', 'coffee-admin-theme', 'coffee_main');
    }
    function coffee_section_text() {
    echo '

    You options.

    ';
    }



    function coffee_setting_string() {
    $options = get_option('coffee_options');
    echo "";}

    // validate our options
    function coffee_options_validate($input) {
    $newinput = trim($input);
    if(!preg_match('/^[a-z0-9]{12}$/i', $newinput)) {
    $newinput = '';
    }
    return $newinput;
    }

    Nevermind, got it working!

Viewing 1 post (of 1 total)
  • The forum ‘Back End’ is closed to new topics and replies.