I am trying to pass some widget options to an external script using wp_localize_script. I know how to pass the variables and how to use them within the script, but how do I extract the widget options to pass them as an array to the script? Here is what I have currently:
class WidgetName extends WP_Widget {
public function __construct() {
// load plugin text domain
add_action( 'init', array( $this, 'widget_textdomain' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'register_widget_scripts' ) );
}
// This is what i'm having a problem with
public function register_widget_scripts() {
$options = get_option('widget-name');
wp_localize_script('handle', 'obj-name', $options);
}
// The rest of the widget code goes here
}