0

I'm working on flickr Wp-widget. Here is code to fetch flickr pics.

class imperia_flickr extends WP_Widget {

    function imperia_flickr() {
        $widget_ops = array('description' => 'This Flickr widget populates photos from a Flickr ID.' );

        parent::WP_Widget(false, __('imperia - Flickr', 'imperiathemes'),$widget_ops);      
    }

    function widget($args, $instance) {  
        extract( $args );
        $id = $instance['id'];
        $number = $instance['number'];

        echo $before_widget;
        echo $before_title; ?>
        <div class="flickr-icon"></div>
        <?php _e('Photostream'); ?>
            <?php echo $after_title; ?>
            <script type="text/javascript">
            $(document).ready(function() {
            $('#flickr').jflickrfeed({
            limit: <?php echo $number; ?>,
            qstrings: {
            id: '<?php echo $id; ?>'
          },
            itemTemplate: '<li><a href="{{image_b}}" rel="prettyPhoto[pp_gal]"><img class="flickr" src="{{image_s}}" alt="{{title}}" width="45" height="45"></a></li>'
          }, function(data) {
          $('#flickr a').prettyPhoto();
          });   
            }); 
            </script>        
            <ul id="flickr"></ul>
            <div class="clear"></div>
       <?php            
       echo $after_widget;
   }

   function update($new_instance, $old_instance) {                
       return $new_instance;
   }

   function form($instance) {        
    ******  $id = esc_attr($instance['id']);
    ******  $number = esc_attr($instance['number']);
        ?>
        <p>
            <label for="<?php echo $this->get_field_id('id'); ?>"><?php _e('Flickr ID (<a href="http://www.idgettr.com">idGettr</a>):','imperiathemes'); ?></label>
            <input type="text" name="<?php echo $this->get_field_name('id'); ?>" value="<?php echo $id; ?>" class="widefat" id="<?php echo $this->get_field_id('id'); ?>" />
        </p>
        <p>
            <label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number:','imperiathemes'); ?></label>
            <select name="<?php echo $this->get_field_name('number'); ?>" class="widefat" id="<?php echo $this->get_field_id('number'); ?>">
                <?php for ( $i = 1; $i <= 12; $i += 1) { ?>
                <option value="<?php echo $i; ?>" <?php if($number == $i){ echo "selected='selected'";} ?>><?php echo $i; ?></option>
                <?php } ?>
            </select>
        </p>
        <?php
    }
} 

register_widget('imperia_flickr');

This widget works fine but gives following error

-- Debug: Undefined index: id on line 54 of /wp-content/themes/imperia/includes/widgets/widget-imperia-flickr.php
-- Debug: Undefined index: number on line 55 of /wp-content/themes/imperia/includes/widgets/widget-imperia-flickr.php

I have marked these lines with ** above.

Where I'm going wrong ? What needs to be fixed ?

Thanks

1 Answer 1

4

You should use isset

$id = isset( $instance['id'] ) ? esc_attr( $instance['id'] ) : '';
$number = isset( $instance['number'] ) ? esc_attr( $instance['number'] ) : '';
3
  • after using isset my page is completely broken & I get error : Parse error: syntax error, unexpected ':' in /Volumes/STUDIO/Workspace/WP - WS/gamma/wp-content/themes/imperia/includes/widgets/widget-imperia-flickr.php on line 55
    – MANnDAaR
    Commented Aug 9, 2011 at 11:56
  • I fixed the code.
    – t31os
    Commented Aug 9, 2011 at 12:01
  • Thanks t31os, missed that while editing. @MANnDAaR now code will work properly
    – Mamaduka
    Commented Aug 9, 2011 at 12:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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