Skip to content

Commit

Permalink
Merge pull request #6 from jeherve/tweet-limit-notice
Browse files Browse the repository at this point in the history
Twitter Timeline `undefined index` & html5 input.
Migrate the tweet-limit to use input type="number" and set a min and max of 1 and 20, respectively.
Fix the undefined index by setting a default.
  • Loading branch information
georgestephanis committed Dec 21, 2013
2 parents fc73798 + 0c6edd3 commit 045c47f
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions modules/widgets/twitter-timeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ public function widget( $args, $instance ) {
* @return array Updated safe values to be saved.
*/
public function update( $new_instance, $old_instance ) {
$non_hex_regex = '/[^a-f0-9]/';
$instance = array();
$instance['title'] = sanitize_text_field( $new_instance['title'] );
$instance['width'] = (int) $new_instance['width'];
$instance['height'] = (int) $new_instance['height'];
$instance['width'] = ( 0 !== (int) $new_instance['width'] ) ? (int) $new_instance['width'] : 225;
$instance['height'] = ( 0 !== (int) $new_instance['height'] ) ? (int) $new_instance['height'] : 400;
$instance['tweet-limit'] = (int) $new_instance['tweet-limit'];
$non_hex_regex = '/[^a-f0-9]/';
$instance = array();
$instance['title'] = sanitize_text_field( $new_instance['title'] );
$instance['width'] = (int) $new_instance['width'];
$instance['height'] = (int) $new_instance['height'];
$instance['width'] = ( 0 !== (int) $new_instance['width'] ) ? (int) $new_instance['width'] : 225;
$instance['height'] = ( 0 !== (int) $new_instance['height'] ) ? (int) $new_instance['height'] : 400;
$instance['tweet-limit'] = ( 0 !== (int) $new_instance['tweet-limit'] ) ? (int) $new_instance['tweet-limit'] : null;

// If they entered something that might be a full URL, try to parse it out
if ( is_string( $new_instance['widget-id'] ) ) {
Expand Down Expand Up @@ -151,6 +151,7 @@ public function form( $instance ) {
'border-color' => '#e8e8e8',
'theme' => 'light',
'chrome' => array(),
'tweet-limit' => null,
);

$instance = wp_parse_args( (array) $instance, $defaults );
Expand All @@ -173,7 +174,7 @@ public function form( $instance ) {

<p>
<label for="<?php echo $this->get_field_id( 'tweet-limit' ); ?>"><?php esc_html_e( '# of Tweets Shown:', 'jetpack' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'tweet-limit' ); ?>" name="<?php echo $this->get_field_name( 'tweet-limit' ); ?>" type="text" value="<?php echo esc_attr( $instance['tweet-limit'] ); ?>" />
<input class="widefat" id="<?php echo $this->get_field_id( 'tweet-limit' ); ?>" name="<?php echo $this->get_field_name( 'tweet-limit' ); ?>" type="number" min="1" max="20" value="<?php echo esc_attr( $instance['tweet-limit'] ); ?>" />
</p>

<p><small>
Expand Down

0 comments on commit 045c47f

Please sign in to comment.