Plugin Settings Page Not Saving
-
I’m trying to create a small settings page on a plugin I’m working on. I’m running into a small error though. When I type anything into my two text boxes I get the following error “ERROR: options page not found.”.
What am I doing wrong?
<?php function test_admin_menu() { add_menu_page( __('Test Invoice', 'test'), __('Test', 'test'), 'manage_options', 'test', 'test_dashboard_html', 'dashicons-chart-line'); add_submenu_page('test', __('Invoices', 'test'), __('Invoices', 'test'), 'manage_options', 'test-invoices', 'test_invoices_html'); add_submenu_page('test', __('Clients', 'test'), __('Clients', 'test'), 'manage_options', 'test-clients', 'test_clients_html'); add_submenu_page('test', __('Options', 'test'), __('Options', 'test'), 'manage_options', 'test-options', 'test_options_html'); } add_action('admin_menu', 'test_admin_menu'); function test_settings_init() { register_setting('test', 'test_options'); add_settings_section('test-api-section', 'API Settings', 'test_api_section_callback', 'test'); add_settings_field('test-api-url-field', __('API URL', 'test'), 'test_api_url_field_callback', 'test', 'test-api-section'); add_settings_field('test-api-key-field', __('API Key', 'test'), 'test_api_key_field_callback', 'test', 'test-api-section'); register_setting('test-api-section', 'test-api-url-field'); register_setting('test-api-section', 'test-api-key-field'); } add_action('admin_init', 'test_settings_init'); function test_api_section_callback() { echo "Test Settings"; } function test_api_key_field_callback($args) { $api_key = esc_attr(get_option('test-api-key-field')); ?> <input type="text" value="<?php echo $api_key; ?>" id="test-api-key-field" name="test-api-key-field" /> <?php } function test_api_url_field_callback($args) { $api_url = esc_attr(get_option('test-api-url-field')); ?> <input type="text" value="<?php echo $api_url; ?>" id="test-api-url-field" name="test-api-url-field" /> <?php } function test_dashboard_html() { if(!current_user_can('manage_options')) return; ?> <div class="wrap"> <h1><?= esc_html(get_admin_page_title()); ?></h1> </div> <?php } function test_options_html() { if(!current_user_can('manage_options')) return; if(isset($_GET['settings-update'])) { add_settings_error('test_messages', 'test_message', __('Settings Saved', 'pnacakeapp'), 'updated'); } settings_errors('test_messages'); ?> <div class="wrap"> <h1><?= esc_html(get_admin_page_title()); ?></h1> <form id="" method="post" action="options.php"> <?php settings_fields('test_options'); do_settings_sections('test'); submit_button('Save Settings'); ?> </form> </div> <?php } function test_clients_html() { if(!current_user_can('manage_options')) return; ?> <div class="wrap"> <h1><?= esc_html(get_admin_page_title()); ?></h1> </div> <?php } function test_invoices_html() { if(!current_user_can('manage_options')) return; ?> <div class="wrap"> <h1><?= esc_html(get_admin_page_title()); ?></h1> </div> <?php }
- The topic ‘Plugin Settings Page Not Saving’ is closed to new replies.