Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I created a custom Flickr Widget for Wordpress and successfully set up an options form for users to enter their Flickr information, but I cannot get the checkbox in the form to save whether or not it is checked. Any help would be greatly appreciated! Here are my widget(), form(), and update() functions:

function widget($args, $instance) {
extract($args);

$title = apply_filters('widget_title', $instance['title']);
$displaynum = $instance['displaynum'];
$flickrid = $instance['flickrname'];
$num = 6;
$feed = new SimplePie($instance['feed']);
$feed->handle_content_type(); 
$photostream = $instance['show_photostream'];


function update($new_instance, $old_instance) {
$instance = $old_instance;

$instance['title'] = strip_tags($new_instance['title'] );
$instance['displaynum'] = strip_tags($new_instance['displaynum'] );
$instance['feed'] = $new_instance['feed'];
$instance['flickrname'] = $new_instance['flickrname'];
$instance['show_photostream'] = (bool) $new_instance['show_photostream'];

return $instance;
}

function form($instance) {
$defaults = array (
    'title' => 'My Recent Flickr Uploads',
    'displaynum' => 6,
    'feed' => 'http://api.flickr.com/services/feeds/photos_public.gne?id=33927859@N06&lang=en-us&format=rss_200',
    'flickrname' => 'rastajellyfish',
    'show_photostream' => isset( $instance['show_photostream'] ) ? (bool) $instance['show_photostream'] : false
);
$instance = wp_parse_args( (array) $instance, $defaults); ?>

Any help would be greatly appreciated!!!

share|improve this question
add comment

1 Answer

I would do:

function update($new_instance, $old_instance) {
    ...

    $instance['show_photostream'] = $new_instance['show_photostream'];

    return $instance;
}

function form($instance) {
    $defaults = array (
        ...
        'show_photostream' => !empty( $instance['show_photostream'] ) ? $instance['show_photostream'] : false
    );
    $instance = wp_parse_args( (array) $instance, $defaults);
share|improve this answer
    
hmmm...there seems to still be a problem. I'll still check the checkbox in the widgets page, the save process works fine, but the value of the checkbox is not retained and always reverts to being unchecked. –  Christian Benincasa Sep 3 '10 at 14:53
1  
can you post all the widget code? especially all the form function –  sorich87 Sep 3 '10 at 16:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.