我有一个非常简单的wordpress小部件,它有3个输入字段。每当我提交数据时,它不会保存到数据库中。我已经添加和删除了插件,停用和重新激活了多次,但没有运气。下面是我的代码:-
class price_package extends WP_Widget {
function __construct() {
parent::__construct(
\'price_package\',
\'Price Package\',
array(
\'classname\' => \'price-package\',
\'description\' => \'Wordpress Package Page Creator\'
)
);
add_action(\'admin_print_styles\', array($this, \'register_admin_styles\'));
add_action(\'wp_enqueue_scripts\', array($this, \'register_widget_styles\'));
add_shortcode(\'package\', function($atts, $content = null) {
$atts = shortcode_atts(
array(
\'name\' => \'Super Platinum\',
\'content\' => \'No description available.\'
), $atts
);
extract($atts);
include(plugin_dir_path(__FILE__).\'/views/package.php\');
});
}
function form ($instance) {
$instance = wp_parse_args(
(array)$instance,
array (
\'name\' => \'\',
\'divclass\' => \'\',
\'paypal\' => \'\',
)
);
include(plugin_dir_path(__FILE__).\'/views/admin.php\');
}
function update($new_instance, $old_instance) {
$old_instance[\'name\'] = htmlentities($new_instance[\'name\']);
$old_instance[\'divclass\'] = htmlentities($new_instance[\'divclass\']);
$old_instance[\'paypal\'] = htmlentities($new_instance[\'paypal\']);
return $old_instance;
}
function widget($args, $instance) {
extract($args, EXTR_SKIP);
echo $before_widget;
include(plugin_dir_path(__FILE__).\'/views/widget.php\');
echo $after_widget;
}
function register_admin_styles() {
wp_enqueue_style(\'price-package\', plugins_url(\'price-package/css/admin.css\'));
}
function register_widget_styles() {
wp_enqueue_style(\'price-package\', plugins_url(\'price-package/css/widget.css\'));
}
}
add_action(\'widgets_init\', create_function(\'\', \'register_widget("price_package");\'));
如果我犯了什么错误,请告诉我。