找不到Wordpress错误选项页面

时间:2017-06-12 09:44:04

标签: wordpress options

我知道有相同错误的帖子很多,但所有发布的解决方案都不适用于我的情况...

我认为option_pageoption_group没问题。所以我不知道问题是什么......也许是我插件的结构。

我的主要课程JMVWManage

 <?php

 class JMVWManage
 {
     public function __construct(){
         register_activation_hook(__FILE__, array('JMVWManage', 'install'));
         register_uninstall_hook(__FILE__, array('JMVWManage', 'uninstall'));
         add_action('admin_menu', array($this, 'add_admin_menu'), 20);

         include_once plugin_dir_path( __FILE__ ).'/admin/jmvwform.php';

         // Tracks new sections for whitelist_custom_options_page()
         $this->page_sections = array();
         // Must run after wp's `option_update_filter()`, so priority > 10
         add_action( 'whitelist_options', array( $this, 'whitelist_custom_options_page' ),11 );

        }

     // White-lists options on custom pages.
     // Workaround for second issue: 
     public function whitelist_custom_options_page( $whitelist_options ){
     // Custom options are mapped by section id; Re-map by page slug.
        foreach($this->page_sections as $page => $sections ){
            $whitelist_options[$page] = array();
            foreach( $sections as $section )
                if( !empty( $whitelist_options[$section] ) )
                    foreach( $whitelist_options[$section] as $option )
                        $whitelist_options[$page][] = $option;
        }
        return $whitelist_options;
    }

    // Wrapper for wp's `add_settings_section()` that tracks custom sections
    private function add_settings_section( $id, $title, $cb, $page ){
        add_settings_section( $id, $title, $cb, $page );
        if( $id != $page ){
            if( !isset($this->page_sections[$page]))
                $this->page_sections[$page] = array();
                $this->page_sections[$page][$id] = $id;
          }
    }




    public static function install(){

       global $wpdb;
       $wpdb->query("CREATE TABLE IF NOT EXISTS {$wpdb->prefix}jmvw_cat_user (id INT AUTO_INCREMENT PRIMARY KEY, cat VARCHAR(255) NOT NULL);");

    }

    public static function uninstall(){

       global $wpdb;
       $wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}jmvw_cat_user;");
    }



    public function add_admin_menu(){
        add_users_page('Manage Users Categories', 'Manage Categories', 'manage_options', 'plugin-settings', array($this, 'plugin_settings'));
    }


    public function plugin_settings(){
        echo '<h1>'.get_admin_page_title().'</h1>';
        echo '<p>Bienvenue sur la page d\'accueil du plugin</p>';

        $form = new JMVWForm();

        echo $form->jmvw_form();

   }
}

new JMVWManage();
?>

我的第二个班级JMVWform

 <?php 

 class JMVWForm
 {


    private $categorie;

    public function __construct(){
       add_action('admin_init', array($this, 'jmvw_register_settings'));

       // Tracks new sections for whitelist_custom_options_page()
       $this->page_sections = array();
       // Must run after wp's `option_update_filter()`, so priority > 10
       add_action( 'whitelist_options', array( $this, 'whitelist_custom_options_page' ),11 );


   }


   // White-lists options on custom pages.
   // Workaround for second issue: 
   public function whitelist_custom_options_page( $whitelist_options ){
       // Custom options are mapped by section id; Re-map by page slug.
       foreach($this->page_sections as $page => $sections ){
           $whitelist_options[$page] = array();
           foreach( $sections as $section )
               if( !empty( $whitelist_options[$section] ) )
                   foreach( $whitelist_options[$section] as $option )
                       $whitelist_options[$page][] = $option;
       }
     return $whitelist_options;
   }

   // Wrapper for wp's `add_settings_section()` that tracks custom sections
   private function add_settings_section( $id, $title, $cb, $page ){
       add_settings_section( $id, $title, $cb, $page );
       if( $id != $page ){
           if( !isset($this->page_sections[$page]))
               $this->page_sections[$page] = array();
               $this->page_sections[$page][$id] = $id;
       }
   }


   public function jmvw_form(){

       global $wpdb;
       $row = $wpdb->get_var("SELECT * FROM $wpdb->cat");
       if(is_null($row)){
               ?>
                   <form method="post" action="options.php">
                           <?php settings_fields('jmvw_settings');?>
                           <label>Ajout de categories</label>
                           <input type="text" name="jmvw_options_sender" value="<?php echo get_option('jmvw_options_sender')?>"/>
                           <?php submit_button(); ?>
                   </form>

           <?php

       }
       else{

           foreach($categorie as $cat){

               ?>
                   <div class="jmvw-div-cat">
                           <h3><?php echo $cat ?></h3>

                           <div class="jmvw-cat-rights">
                               <?php echo "Dans lidee ici il y aura les droit des categorie" ?>
                           </div>

                   </div>

           <?php
           }

       }

   }



   public function jmvw_register_settings(){

       register_setting('jmvw_settings', 'jmvw_options_sender');

   }

}



?>

因此,当我提交表单时,wordpress说,找不到选项页面,不知道为什么。 我想我的所有参数都是正确的。

提前致谢 约旦

0 个答案:

没有答案