wordpresssettings

Setting Api form "options page is not in the allowed options list."


https://www.youtube.com/watch?v=j9DY0avQagU. Please check this video, this form i developed by the setting api. This error is showing "options page is not in the allowed options list." when i was try to use this add_menu_page() this setting AI script working.But when i used this script in this Tabs. that is not working. How to fix this issues. Please can you tell me.

class GeneralTab {       
      public function __construct() {   
         add_action('admin_init', [$this, 'orange_general_settings']);
         $this->orang_general_settings_page();
      }
     
     public function orang_general_settings_page() {
        // You can put your HTML and settings fields here
        echo '<div class="wrap">';
        echo '<h2>General Settings</h2>';
        echo '<hr>';
        echo '<form method="post" action="options.php">';
        
        // Use the correct options group name here
        settings_fields('orange-general-setting-gp');
    
        // Add a settings section
        add_settings_section(
          'orang_general_custom',
          '', // section name blank
          '', 
          'orange_general_custom_page'
        );
    
        // Add a settings field
        add_settings_field(
          'orange_general_email_id', // ID
          'From email address',  // field label name
          [$this, 'orange_general_email'], // callback function
          'orange_general_custom_page', // setting page callback
          'orang_general_custom' // section page callback
        );
    
        add_settings_field(
          'organge_general_from_name_id', // ID
          'From Name',  // field name
          [$this, 'orange_general_name'], // callback function
          'orange_general_custom_page', // setting page callback
          'orang_general_custom' // section page callback
        );
    
        do_settings_sections('orange_general_custom_page');
        submit_button('Save Settings');
        echo '</form>';
        echo '</div>';
      }
    
      public function orange_general_email() {
        $value = get_option('orange_general_emailfield');
        echo '<input type="text" name="orange_general_emailfield" value="' . esc_attr($value) . '">';
      }
    
      public function orange_general_name() {
        $value = get_option('orange_general_namefield');
        echo '<input type="text" name="orange_general_namefield" value="' . esc_attr($value) . '">';
      }
    
      public function orange_general_settings() {
        // Use the correct options group name here
        register_setting('orange-general-setting-gp', 'orange_general_emailfield');
        register_setting('orange-general-setting-gp', 'orange_general_namefield');
      }
    }

Solution

  • try to call register_setting() on the rest_api_init action, in addition to the normal admin_init action.

    I mean to add the following line to the __construct method:

    add_action('rest_api_init', [$this, 'orange_general_settings']);