首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >wordpress小部件插件未处于活动状态

wordpress小部件插件未处于活动状态
EN

Stack Overflow用户
提问于 2013-10-25 18:40:01
回答 1查看 152关注 0票数 0

我是wordpress的新手。目前,我正在尝试创建一个插件,将显示标题,输入文本和小工具部分的文本区。为此,我编写了如下代码

代码语言:javascript
复制
<?php
/*
Plugin Name: WP Simple Plugin
Plugin URI: http://www.wordpress.org
Description: A Plugin to show simple text in widget
Version: 0.1
Author: 
*/

class WP_My_Plugin extends WP_Widget {
  function wp_my_plugin() {
    parent::WP_Widget( false, $name= 'Wp_My_Plugin' );
  }

   function form($instance) {
    if($instance) {
      $title = esc_attr($instance['title']);
      $text = esc_attr($instance['text']);
      $textarea = esc_attr($instance['textarea']);
    } else {
      $title = '';
      $text = '';
      $textarea = '';
    }
    ?>
    <p>
      <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Widget Title', 'wp_widget_plugin'); ?></label>
      <input class="widefat" type="text" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title');?>" value="<?php echo $title; ?>"/>
    </p>
    <p>
      <label for="<?php echo $this->get_field_id('text')?>"><?php _e('Text', 'wp_widget_plugin');?></label>
      <input type="text" class="widefat" name="<?php echo $this->get_field_name('text');?>" id="<?php echo get_field_id('text');?>" value="<?php echo $text; ?>" />
    </p>
    <p>
      <label for="<?php echo $this->get_field_id('textarea');?>"><?php _e('Textarea','wp_widget_plugin'); ?></label>
      <textarea name="<?php echo $this->get_field_name('textarea'); ?>" id="<?php echo $this->get_field_id('textarea'); ?>" class="widefat"  /><?php echo $textarea; ?></textarea>
    </p>

  <?php
  }

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

  function widget($args, $instance) {
    extract ($args);
    //The widget Options
    $title = apply_filters('widget_title' , $instance['title']);
    $text = $instance['text'];
    $textarea = $instance['textarea'];
    echo $before_widget;
    //Display Widget
    echo '<div class="widget-text wp_widget_plugin_box">';

    //Check If Title Is Set
    if($title) {
      echo $before_title.$title.$after_title;
    }

    //check if text is set
    if($text) {
      echo '<p class="wp_widget_plugin_text">'.$text.'</p>';
    }

    //check if texrarea is set
    if($textarea) {
      echo '<p class="wp_widget_plugin_textarea">'.$textarea.'</p>';
    }
    echo '</div>';
    echo $after_widget;
  }
}

  //Register Widget
  add_action( 'widgets_init', 'wp_my_plugin' );


?>

但当我尝试从仪表板激活插件时,它显示错误,如

代码语言:javascript
复制
Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'wp_my_plugin' not found or invalid function name in /wordpress/plugin.php on line 406

插件没有激活,所以有人能告诉我如何解决这个问题吗?任何帮助都将是非常有用的。谢谢

EN

回答 1

Stack Overflow用户

发布于 2013-10-25 19:00:58

会不会是你必须更改这行

代码语言:javascript
复制
parent::WP_Widget( false, $name= 'Wp_My_Plugin' );

代码语言:javascript
复制
parent::WP_Widget( false, $name= 'WP_My_Plugin' ); ?
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19587606

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档