激活插件不显示后端形式


Activated plugin not showing in backend form

我是一个wordpress新手,我做了一个简单的小部件插件,显示标题和文本。一切似乎都很好,插件被激活,但小部件只是没有显示在后端小部件列表中。我做错了什么?

我已经搜索了,检查了又检查了,但似乎无法确定是哪里出了问题。

下面是我的代码文件:

显然也

<?php
    function ms_init_widgets($id){
       register_sidebar(array(
            'name' => 'Showcase',
            'id' => 'showcase',
            'before_widget'  => '',
            'after_widget' => '',
            'before_title' => '',
            'after_title' => ''
        ));
    }
add_action('widgets_init', 'ms_init_widgets');

new-showcase-widget.php

<?php
    /*
    *Plugin name:   New Showcase Widget
    *Description: A new showcase widget that displays a title and text
    *Author: Shefalizzle
    *version: 1.0
    *
    */
    include('class.new-showcase-widget.php');
    function register_new_showcase_widget(){
        register_widget('New_Showcase_Widget');
    }
    add_action('widgets-init', 'register_new_showcase_widget');

class.new-showcase-widget.php

<?php
class New_Showcase_Widget extends WP_Widget {
    // constructor
    public function __construct() {
        $widget_ops = array( 
            'classname' => 'new_showcase_widget',
            'description' => __('A new widget I created that is actually working', 'text_domain'),
        );
        parent::__construct( 'new_showcase_widget', 'New_Showcase_Widget', $widget_ops );
    }
    // widget form creation
    function form($instance) {  
    /* ... */
    if( $instance) {
     $title = esc_attr($instance['title']);
     $heading = esc_attr($instance['heading']);
     $text = esc_attr($instance['text']);
    } else {
        $title = '';
        $heading = '';
        $text = '';
    }
    ?>
    <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 $title; ?>" />
    </p>
    <p>
    <label for="<?php echo $this->get_field_id('heading'); ?>"><?php _e('Heading:'); ?></label>
    <input class="widefat" id="<?php echo $this->get_field_id('heading'); ?>" name="<?php echo $this->get_field_name('heading'); ?>" type="text" value="<?php echo $heading; ?>" />
    </p>
    <p>
    <label for="<?php echo $this->get_field_id('text'); ?>"><?php _e('Text:'); ?></label>
    <input class="widefat" id="<?php echo $this->get_field_id('text'); ?>" name="<?php echo $this->get_field_name('text'); ?>"><?php echo $text; ?></input>
    </p>
    <?php
    }
    // widget update
    function update($new_instance, $old_instance) {
        /* ... */
        $instance = $old_instance;
        $instance['title'] = strip_tags($new_instance['title']);
        $instance['text'] = strip_tags($new_instance['text']);
        $instance['textarea'] = strip_tags($new_instance['textarea']);
        return $instance;
    }
    // widget display
    function widget($args, $instance) {
        /* ... */
        extract($args);
        $title = apply_filters('widget_title', $instance['title']);
        $heading = $instance['heading'];
        $text = $instance['text'];
        echo $before_widget;
         // Check if title is set
        if ( $title ) {
          echo $before_title . $title . $after_title;
        }
        if($heading) {
            echo '<h1>'.$heading.'</h1>';
        }
        // Check if text is set
        if( $text ) {
            echo '<p>'.$text.'</p>';
        }
        echo $after_widget;     
    }   
}

我认为表单函数有问题,但我似乎找不出来

您是否尝试在您的index.php页面或您需要的页面中显示小部件?

<?php if(is_active_sidebar('showcase')) : ?>
     <?php dynamic_sidebar('showcase'); ?>
<?php endif; ?>