Im creating Wordpress widget, where I have to add parts of code dynamically by JQUERY.ajax() a JQUERY.append() to the widget form. I need it, to be able to save it by function update(). I have PHP functions for each field of form, but in wp_widget I have to get the names and IDs by its function.
If I make function to get name outside the wp_widget child:
function gentitle($title,$num=''){
$widget=new WP_Widget();
return
sprintf('%1$s[%2$s]',
$widget->get_field_name($title),
$num
);
}
it returns errors and if I make the forms child classes of my widget, it fails too.
I need to be able to get the names into form functions and to be able to get them with AJAX and put it inside widget form...
In class it works, but I cant use it for the functions that generates the form (cos $v=new testwidget();$v->genname; returns error).
class awidget_test extends WP_Widget {
function awidget_test() {
$widget_ops=array('classname'=>'atestwidget','description'=>'Just testing something');
$control_ops=array('width'=>300,'height'=>350,'id_base'=>'atest-widget');
$this->WP_Widget('atestwidget-widget','Actually testing',$widget_ops,$control_ops);
}
function widget($args,$instance){
extract($args);
}
function update($new_instance,$instance) {
return $instance;
}
function gentitle($title,$num=''){
return
sprintf('%1$s[%2$s]',
$this->get_field_name($title),
$num
);
}
function form($instance) {
echo $this->gentitle('blabla');
}
}
Any ideas?