Finally I finished to write my widget, and now want to call it using function inside themes php files. My widget looks like this:
function reg_custom_widget() { register_widget('wp_custom_widget'); } class wp_custom_widget extends WP_Widget { function wp_custom_widget() { /* constructor */ } function widget($args, $instance) { /* here is the code, that uses 'core' functions to build the result and display it */ } function shortcode_handler($atts) { /* the same code as in widget() with a couple of features */ } /* here are basic functions, strongly related. they perform main widget functionality */ function core_func_one($input) { } function core_func_two($input) { } function core_func_three($input) { } function core_func_four($input) { } function core_func_five($input) { } function update($new_instance, $old_instance) { /* updating settings */ } function form($instance) { /* building widget setup-form */ } }
I already know about following methods, that call widget, and can be placed in themes files:
1. calling via shortcode with do_shortcode()
wp function;
2. calling widget with the_widget()
wp function;
Both this methods work great, but my designer rejects them.
He want to hard code calling of widget in this way: if(function_exists('custom_widget')) { custom_widget(); }
How can I realize this option? Maybe is reasonable to make another one function in the widget class, make it global or something, it will run the widget from inside of it? Sounds like delirium, but I don't really understand now how to resolve this problem.