I am creating plugin on base of boiler plate structure and i am trying to create admin menu page, but i am getting an error.
Below is my code.

below code in class-plugin-name.php inside admin hook,

$this->loader->add_action( 'admin_menu', $plugin_admin, 'define_admin_page' );
$this->loader->add_action( 'admin_init', $plugin_admin, 'define_setting_fields' );

inside class-plugin-name-admin.php ,

public function define_admin_page(){

        add_menu_page(
          __('SEO Boost', 'seo-boost'), 
          __('SEO Boost', 'seo-boost'), 
          'manage_options', 
          'seo-boost', 
          array(&$this, 'seo_boost_page_callback')
        );        
    }

    public function seo_boost_page_callback(){
        include_once 'partials/plugin-name-admin-display.php';
    }

    public function define_setting_fields(){
        add_settings_section(
               $this->option_name.'_general-section',
               __( 'General', 'seo-boost' ), 
               array( $this, $this->option_name . '_general_line' ), 
               $this->plugin_name
               );

    add_settings_field(
           $this->option_name . '_text', 
           __("Text box label:", 'seo-boost'), 
           array( $this, $this->option_name . '_text_api_element' ),    
          $this->plugin_name, 
          $this->option_name.'general-section',
          array( 'label_for' => $this->option_name . '_text' )
          );

    register_setting($this->option_name.'general-section', $this->option_name . '_text');           

    }

    public function seo_boost_general_line(){
        echo '<p>' . __( 'Please change the settings accordingly.', 'outdated-notice' ) . '</p>';
    }

    public function seo_boost_text_api_element(){
        $text = get_option( $this->option_name . '_text' );
        echo '<input type="text" name="' . $this->option_name . '_text' . '" id="' . $this->option_name . '_text' . '" value="' . $text . '"> ' . __( 'text', 'seo-boost' );
    }

inside plugin-name-admin-display.php there is code for display admin page form fields,

<div class="wrap">
            <h1><?php _e('Seo Settings', 'seo-boost'); ?></h1>
             <form action="options.php" method="post">
        <?php       
        settings_fields($this->option_name.'_general-section');
        do_settings_sections($this->plugin_name);
        submit_button(); ?>             
            </form>
        </div>

But i am getting an error of Fatal error:

Call to undefined function settings_fields() in plugin-name-admin-display.php on line 20

Read more here: Call to undefined function settings_fields() in boiler plate plugin structure


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: