Hopefully, this is an easy question - I'm just a bit confused.
I've got a custom widget with the usual structure:
class My_Widget extends WP_Widget {
function My_Widget() {
// widget actual processes
}
function form($instance) {
// outputs the options form on admin
}
function update($new_instance, $old_instance) {
// processes widget options to be saved
}
function widget($args, $instance) {
// outputs the content of the widget
}
}
register_widget('My_Widget');
I's like to add my own custom function to it, so I can reuse it. Something like:
function item_width_cols_to_class( $cols_num = null ) {
if( $cols_num ){
switch ( $cols_num ){
case '2':
return "col140";
break;
case '3':
return "col220";
break;
case '4':
return "col300";
break;
case '5':
return "col380";
break;
case '6':
return "col480";
break;
case '7':
return "col540";
break;
default:
return "";
break;
}
}
}
However, when I add that code to My_Widget class I got an error saying: "Fatal error: Call to undefined function 'item_width_cols_to_class()'"
. I'd think it's possible to add custom functions to a widget as it extends the WP_widget class.
Am I doing something wrong? :S
Thanks for help, Dasha