2017-05-12 52 views
0

我正在锅炉板结构的基础上创建插件,我想创建管理菜单页,但我得到一个错误。 以下是我的代码。调用未定义的函数settings_fields()在锅炉板插件结构

下面管理员钩内部类插件-name.php代码,

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

类插件名称管理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 register_setting(){ 
     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'); 
    } 

插件名称管理管理 - 内部有Display.php的是用于显示管理页面的表单字段代码,

<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> 

但我正在逐渐致命错误的错误:

调用未定义功能settings_fields()的插件名管理员,对Display.php的线20

我使用REF从这个链接创建插件。 REf. plugin

+0

您注册的函数名称是define_setting_fields,但您正在写set_fields并调用它。那么脚本将如何获得该功能? – Exprator

+0

看看这个 - https://codex.wordpress.org/Function_Reference/do_settings_fields在这个页面的底部,你会有类似的功能来处理。 –

+0

do_settings_sections($ this-> plugin_name,$ this-> option_name .'_ general-section'); 试试这个@AshPatel – Exprator

回答

0

这条线:

settings_fields($this->option_name.'_general-section'); 

是指必须不存在的功能......你的意思是使用define_settings_fields(..)add_settings_field(...)在这里呢?

+0

不是工作王寿 –