Changeset 20071
- Timestamp:
- 03/02/2012 01:58:58 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/default-widgets.php
r20047 r20071 103 103 $show_images = isset($instance['images']) ? $instance['images'] : true; 104 104 $category = isset($instance['category']) ? $instance['category'] : false; 105 $orderby = isset( $instance['orderby'] ) ? $instance['orderby'] : 'name'; 106 $order = $orderby == 'rating' ? 'DESC' : 'ASC'; 107 $limit = isset( $instance['limit'] ) ? $instance['limit'] : -1; 105 108 106 109 if ( is_admin() && !$category ) { … … 116 119 'show_images' => $show_images, 'show_description' => $show_description, 117 120 'show_name' => $show_name, 'show_rating' => $show_rating, 118 'category' => $category, 'class' => 'linkcat widget' 121 'category' => $category, 'class' => 'linkcat widget', 122 'orderby' => $orderby, 'order' => $order, 123 'limit' => $limit, 119 124 ))); 120 125 } … … 122 127 function update( $new_instance, $old_instance ) { 123 128 $new_instance = (array) $new_instance; 124 $instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0 );129 $instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0 ); 125 130 foreach ( $instance as $field => $val ) { 126 131 if ( isset($new_instance[$field]) ) 127 132 $instance[$field] = 1; 128 133 } 129 $instance['category'] = intval($new_instance['category']); 134 135 $instance['orderby'] = 'name'; 136 if ( in_array( $new_instance['orderby'], array( 'name', 'rating', 'id', 'rand' ) ) ) 137 $instance['orderby'] = $new_instance['orderby']; 138 139 $instance['category'] = intval( $new_instance['category'] ); 140 $instance['limit'] = ! empty( $new_instance['limit'] ) ? intval( $new_instance['limit'] ) : -1; 130 141 131 142 return $instance; … … 135 146 136 147 //Defaults 137 $instance = wp_parse_args( (array) $instance, array( 'images' => true, 'name' => true, 'description' => false, 'rating' => false, 'category' => false ) ); 138 $link_cats = get_terms( 'link_category'); 148 $instance = wp_parse_args( (array) $instance, array( 'images' => true, 'name' => true, 'description' => false, 'rating' => false, 'category' => false, 'orderby' => 'name', 'limit' => -1 ) ); 149 $link_cats = get_terms( 'link_category' ); 150 if ( ! $limit = intval( $instance['limit'] ) ) 151 $limit = -1; 139 152 ?> 140 153 <p> … … 149 162 } 150 163 ?> 151 </select></p> 164 </select> 165 <label for="<?php echo $this->get_field_id('orderby'); ?>"><?php _e( 'Sort by:' ); ?></label> 166 <select name="<?php echo $this->get_field_name('orderby'); ?>" id="<?php echo $this->get_field_id('orderby'); ?>" class="widefat"> 167 <option value="name"<?php selected( $instance['orderby'], 'name' ); ?>><?php _e( 'Link title' ); ?></option> 168 <option value="rating"<?php selected( $instance['orderby'], 'rating' ); ?>><?php _e( 'Link rating' ); ?></option> 169 <option value="id"<?php selected( $instance['orderby'], 'id' ); ?>><?php _e( 'Link ID' ); ?></option> 170 <option value="rand"<?php selected( $instance['orderby'], 'rand' ); ?>><?php _e( 'Random' ); ?></option> 171 </select> 172 </p> 152 173 <p> 153 174 <input class="checkbox" type="checkbox" <?php checked($instance['images'], true) ?> id="<?php echo $this->get_field_id('images'); ?>" name="<?php echo $this->get_field_name('images'); ?>" /> … … 159 180 <input class="checkbox" type="checkbox" <?php checked($instance['rating'], true) ?> id="<?php echo $this->get_field_id('rating'); ?>" name="<?php echo $this->get_field_name('rating'); ?>" /> 160 181 <label for="<?php echo $this->get_field_id('rating'); ?>"><?php _e('Show Link Rating'); ?></label> 182 </p> 183 <p> 184 <label for="<?php echo $this->get_field_id('limit'); ?>"><?php _e( 'Number of links to show:' ); ?></label> 185 <input id="<?php echo $this->get_field_id('limit'); ?>" name="<?php echo $this->get_field_name('limit'); ?>" type="text" value="<?php echo $limit == -1 ? '' : intval( $limit ); ?>" size="3" /> 161 186 </p> 162 187 <?php
Note: See TracChangeset
for help on using the changeset viewer.