'widget-oceanwp-twitter twitter-widget', 'description' => esc_html__( 'Pulls in tweets from your twitter account.', 'ocean-extra' ), 'customize_selective_refresh' => true, ) ); } /** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget( $args, $instance ) { $instance['lang'] = substr( strtoupper( get_locale() ), 0, 2 ); echo $args['before_widget']; $title = isset( $instance['title'] ) ? $instance['title'] : ''; $title = apply_filters( 'widget_title', $title ); if ( ! empty( $title ) ) { echo $args['before_title'] . $title . $args['after_title']; } // Start tag output // This tag is transformed into the widget markup by Twitter's echo '' . esc_html__( 'My Tweets', 'ocean-extra' ) . ''; // End tag output echo $args['after_widget']; } /** * Sanitize widget form values as they are saved. * * @see WP_Widget::update() * * @param array $new_instance Values just sent to be saved. * @param array $old_instance Previously saved values from database. * * @return array Updated safe values to be saved. */ public function update( $new_instance, $old_instance ) { $instance = array(); $instance['title'] = sanitize_text_field( $new_instance['title'] ); $width = (int) $new_instance['width']; if ( $width ) { // From publish.twitter.com: 220 <= width <= 1200 $instance['width'] = min( max( $width, 220 ), 1200 ); } else { $instance['width'] = ''; } $height = (int) $new_instance['height']; if ( $height ) { // From publish.twitter.com: height >= 200 $instance['height'] = max( $height, 200 ); } else { $instance['height'] = ''; } $tweet_limit = (int) $new_instance['tweet-limit']; if ( $tweet_limit ) { $instance['tweet-limit'] = min( max( $tweet_limit, 1 ), 20 ); /** * A timeline with a specified limit is expanded to the height of those Tweets. * The specified height value no longer applies, so reject the height value * when a valid limit is set: a widget attempting to save both limit 5 and * height 400 would be saved with just limit 5. */ $instance['height'] = ''; } else { $instance['tweet-limit'] = null; } $instance['username'] = sanitize_text_field( $new_instance['username'] ); $hex_regex = '/#([a-f]|[A-F]|[0-9]){3}(([a-f]|[A-F]|[0-9]){3})?\b/'; foreach ( array( 'link-color', 'border-color' ) as $color ) { $new_color = sanitize_text_field( $new_instance[ $color ] ); if ( preg_match( $hex_regex, $new_color ) ) { $instance[ $color ] = $new_color; } } $instance['theme'] = 'light'; if ( in_array( $new_instance['theme'], array( 'light', 'dark' ) ) ) { $instance['theme'] = $new_instance['theme']; } $instance['chrome'] = array(); $chrome_settings = array( 'noheader', 'nofooter', 'noborders', 'transparent', 'noscrollbar', ); if ( isset( $new_instance['chrome'] ) ) { foreach ( $new_instance['chrome'] as $chrome ) { if ( in_array( $chrome, $chrome_settings ) ) { $instance['chrome'][] = $chrome; } } } return $instance; } /** * Back-end widget form. * * @see WP_Widget::form() * * @param array $instance Previously saved values from database. */ public function form( $instance ) { $defaults = array( 'title' => esc_html__( 'Follow me on Twitter', 'ocean-extra' ), 'width' => '', 'height' => '400', 'username' => '', 'link-color' => '#f96e5b', 'border-color' => '#e8e8e8', 'theme' => 'light', 'chrome' => array(), 'tweet-limit' => 5, ); $instance = wp_parse_args( (array) $instance, $defaults ); ?>
id="get_field_id( 'chrome-noheader' ); ?>" name="get_field_name( 'chrome' ); ?>[]" value="noheader" />
id="get_field_id( 'chrome-nofooter' ); ?>" name="get_field_name( 'chrome' ); ?>[]" value="nofooter" />
id="get_field_id( 'chrome-noborders' ); ?>" name="get_field_name( 'chrome' ); ?>[]" value="noborders" />
id="get_field_id( 'chrome-noscrollbar' ); ?>" name="get_field_name( 'chrome' ); ?>[]" value="noscrollbar" />
id="get_field_id( 'chrome-transparent' ); ?>" name="get_field_name( 'chrome' ); ?>[]" value="transparent" />