Php 自定义小部件在Wordpress中被禁用/变灰

Php 自定义小部件在Wordpress中被禁用/变灰,php,wordpress,widget,Php,Wordpress,Widget,我按照本教程创建了自己的小部件: 一切都很好,但是。。。我的小部件没有出现在网页中,并且在管理面板中变灰 有什么想法吗 编辑 Test.php(插件/测试) widget.php <?php class test_widget extends WP_Widget { // constructor function test_widget() { $widget_ops = array(

我按照本教程创建了自己的小部件:

一切都很好,但是。。。我的小部件没有出现在网页中,并且在管理面板中变灰

有什么想法吗

编辑

Test.php(插件/测试)


widget.php

<?php 
    class test_widget extends WP_Widget {

        // constructor
        function test_widget() {
            $widget_ops = array( 
                'class_name' => 'test_widget',
                'description' => 'MyWidget',
            );
            parent::__construct( 'test_widget', 'MyWidget', $widget_ops );
        }

        // widget form creation
        function form($instance) {  
            $title = ! empty( $instance['title'] ) ? $instance['title'] : __( 'New title', 'text_domain' );
            ?>
            <p>
            <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> 
            <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
            </p>
            <?php 
        }

        // widget update
        function update($new_instance, $old_instance) {
              $instance = $old_instance;
              // Fields
              $instance['title'] = strip_tags($new_instance['title']);
             return $instance;
        }

        // widget display
        function widget($args, $instance) {
            echo "Is there anybody out there?";
        }
    }
?>



欢迎来到StackOverflow!你能提供你的代码吗?@James:谢谢,我已经添加了代码:)代码
?>@James:是的,这只是为了我的测试,最后它将被放在一个单独的文件中。它只是在主题的定制页面中显示一个名为“title”的字段及其标签,在这里并不重要。我在页面上或wordpress日志文件中没有任何错误?我说的是PHP错误日志(如果您在Linux上使用Apache,通常在/var/log/apache2/error.log中)。我要它是因为我没有发现你的代码中有任何错误,所以我无法帮助你:-(欢迎来到StackOverflow!你能提供你的代码吗?@James:谢谢,我已经添加了代码:)代码
?>@James:是的,它只是为了我的测试,最后它将被放在一个单独的文件中。它只是在主题的定制页面中显示一个名为“title”的字段及其标签,在这里并不重要。我在页面上或wordpress日志文件中没有任何错误?我说的是PHP错误日志(如果您在Linux上使用Apache,通常在/var/log/apache2/error.log中)。我之所以要它,是因为我没有发现您的代码中有任何错误,因此我无法帮助您:-(
<?php 
    class test_widget extends WP_Widget {

        // constructor
        function test_widget() {
            $widget_ops = array( 
                'class_name' => 'test_widget',
                'description' => 'MyWidget',
            );
            parent::__construct( 'test_widget', 'MyWidget', $widget_ops );
        }

        // widget form creation
        function form($instance) {  
            $title = ! empty( $instance['title'] ) ? $instance['title'] : __( 'New title', 'text_domain' );
            ?>
            <p>
            <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> 
            <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
            </p>
            <?php 
        }

        // widget update
        function update($new_instance, $old_instance) {
              $instance = $old_instance;
              // Fields
              $instance['title'] = strip_tags($new_instance['title']);
             return $instance;
        }

        // widget display
        function widget($args, $instance) {
            echo "Is there anybody out there?";
        }
    }
?>
<?php 
    class TestSettings
    {
        /**
         * Holds the values to be used in the fields callbacks
         */
        private $options;

        /**
         * Start up
         */
        public function __construct()
        {
            add_action( 'admin_menu', array( $this, 'add_plugin_page' ) );
            add_action( 'admin_init', array( $this, 'page_init' ) );
            add_action( 'widgets_init', array( $this, 'register_widget' ) );
        }


        public function register_widget() {
            register_widget( 'test_widget' );
        }

        /**
         * Add options page
         */
        public function add_plugin_page()
        {
            // This page will be under "Settings"
            add_options_page(
                'Settings Admin', 
                'Test', 
                'manage_options', 
                'test', 
                array( $this, 'create_admin_page' )
            );
        }

        /**
         * Options page callback
         */
        public function create_admin_page()
        {
            // Set class property
            $this->options = get_option( 'my_option_name' );
            ?>
            <div class="wrap">
                <form method="post" action="options.php">
                    <?php settings_fields( 'test-settings-group' ); ?>
                    <?php do_settings_sections( 'test-settings-group' ); ?>
                    <table class="form-table">
                        <tr valign="top">
                        <th scope="row">Fournisseur</th>
                            <td><input type="text" name="provider" value="<?php echo esc_attr( get_option('provider') ); ?>" /></td>
                        </tr>

                        <tr valign="top">
                        <th scope="row">Script</th>
                            <td><textarea name="script" rows="10" style="width:100%;"><?php echo esc_attr( get_option('script') ); ?></textarea></td>
                        </tr>
                    </table>
                    <?php submit_button(); ?>
                </form>
            </div>
            <?php
        }

        /**
         * Register and add settings
         */
        public function page_init()
        {        
            register_setting( 'test-settings-group', 'provider' );     
            register_setting( 'test-settings-group', 'script' );     
        }
    }
?>