Use wordpress widget option (instance) outside the class
-
I’m trying to use an instance or option from the widget backend settings outside the class but can’t seem to get it to work.
I’ve omitted some of the code to simplify what I mean:
<?php ##trying to use variable here! echo $instance['variableiwant']; class my_class extends WP_Widget { ## get variable from the backend form settings of widget function form($instance) { $title = ! empty( $instance['variableiwant'] ) ? $instance['title'] : __( 'variableiwant' ); } ##update save of widget function update($new_instance, $old_instance) { $instance = $old_instance; $instance['variableiwant'] = strip_tags($new_instance[ 'variableiwant']); return $instance; } function widget($args, $instance) { }I can use the variable perfectly fine inside the class and its functions but is there special API I need to use to pull the variable outside the class as the code:
echo $instance['variableiwant'];Just returns 0 or zero
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
The topic ‘Use wordpress widget option (instance) outside the class’ is closed to new replies.