Reputation: 65
I learned how to create a plugin on WordPress a while ago. However, WordPress changed everything around and I'm trying to create the same plugin using the new WordPress format. I've read several things, but tried to jump right in by modifying the WordPress Text Field plugin (one of my goals with redoing the plugin was to make it usable multiple times). I realize the code is really rough, but I'm stuck. I've tried to add two new fields just to see how things go and while they appear when I go to edit the widget once you click save on the Title and first textarea data gets saved, the other two fields dissapear.
I have a feeling I'm missing something obvious, but I just can't seem to figure it out. Here's the code:
'widget_text', 'description' => __('Text or HTML')); $control_ops = array('width' => 400, 'height' => 350); $this->WP_Widget('text', __('Multi Excerpt'), $widget_ops, $control_ops); } function widget( $args, $instance ) { extract($args); $title = apply_filters( 'widget_title', empty($instance['title']) ? '' : $instance['title'], $instance ); $text = apply_filters( 'widget_text', $instance['text'], $instance ); $texta = apply_filters( 'widget_text', $instance['texta'], $instance ); $posts = $instance['posts']; echo $before_widget; if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } ?> '', 'text' => '', 'posts' => '', 'texta' => '' ) ); $title = strip_tags($instance['title']); $text = format_to_edit($instance['text']); $texta = format_to_edit($instance['texta']); $posts = $instance['posts']; ?>get_field_id('title'); ?>"> get_field_id('title'); ?>" name="get_field_name('title'); ?>" type="text" value="" />
get_field_id('text'); ?>" name="get_field_name('text'); ?>"> get_field_id('texta'); ?>" name="get_field_name('texta'); ?>">get_field_id('posts'); ?>">Posts: get_field_id('posts'); ?>" name="get_field_name('posts'); ?>" type="text" value="" />
Thanks in advance.
Upvotes: 0
Views: 489
Reputation: 1066
Edited: I found my original answer was somewhat correct. Below are the details needs to fix your problem.
Change your WP_Widget_Excerpt
function to:
function WP_Widget_Excerpt() {
$widget_ops = array('classname' => 'WP_Widget_Excerpt', 'description' => __('Text or HTML'));
$control_ops = array('width' => 400, 'height' => 350);
$this->WP_Widget('WP_Widget_Excerpt', __('Multi Excerpt'), $widget_ops, $control_ops);
}
Upvotes: 0
Reputation: 120
If your Widget is doing something simple you can use Widgetifyr.com to create your widget for you. I creates the old style widget as well as the new 2.8+ class based widget. This way your widget will run on more versions of Wordpress.
Upvotes: 0