'widget-themeidol-tweets', 'description' => esc_html__( 'Display an official Twitter Embedded Timeline widget.', 'themeidol-all-widget' ) ) ); if ( is_active_widget( false, false, $this->id_base ) && $this->themeidol_tweets_option( 'twitter_script' ) ) { add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); } } /** * Enqueue scripts for front-end. */ public function enqueue_scripts() { wp_enqueue_script( 'themeidol-twitter-widgets', THEMEIDOL_WIDGET_JS_URL . 'twitter-widgets.js', array( 'jquery' ), '1.0', true ); } /** * Custom functions for the plugin */ /** * Plugin Options Defaults * * Sane Defaults Logic * Plugin will not save default settings to the database without explicit user action * and Plugin will function properly out-of-the-box without user configuration. * * @param string $option - Name of the option to retrieve. * @return mixed */ function themeidol_tweets_option_default( $option = 'enable' ) { $themeidol_options_default = array ( 'twitter_script' => true, ); if( isset( $themeidol_options_default[$option] ) ) { return $themeidol_options_default[$option]; } return ''; } /** * Retrieve the plugin option. * * @param string $option - Name of the option to retrieve. * @return mixed */ function themeidol_tweets_option( $option = 'twitter_script' ) { $themeidol_options_default = array ( 'twitter_script' => true, ); $themeidol_tweets_options = apply_filters( 'themeidol_tweets_options', $themeidol_options_default ); if ( isset( $themeidol_tweets_options[$option] ) ) { return $themeidol_tweets_options[$option]; } else { return $this->themeidol_tweets_option_default( $option ); } } /** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ function widget( $args, $instance ) { // Defaults $defaults = $this->defaults(); // Merge the user-selected arguments with the defaults. $instance = wp_parse_args( (array) $instance, $defaults ); // Open the output of the widget. echo $args['before_widget']; ?> id_base ) . $args['after_title']; ?> 'width', 'twitter_widget_height' => 'height', 'twitter_widget_tweet_limit' => 'tweet-limit', 'twitter_widget_theme' => 'theme', 'twitter_widget_link_color' => 'link-color', 'twitter_widget_border_color' => 'border-color', ); foreach ( $data_attribs as $key => $val ) { if ( ! empty( $instance[ $key ] ) ) { $timeline .= ' data-' . esc_attr( $val ) . '="' . esc_attr( $instance[ $key ] ) . '"'; } } // Chrome Settings if ( ! empty( $instance['twitter_widget_chrome'] ) && is_array( $instance['twitter_widget_chrome'] ) ) { $timeline .= ' data-chrome="' . esc_attr( join ( ' ', $instance['twitter_widget_chrome'] ) ) . '"'; } // Widget Timeline Route switch ( $instance['twitter_timeline_type'] ) { case 'username': $timeline .= ' href="https://twitter.com/' . esc_attr( $instance['twitter_widget_username'] ) . '"'; break; case 'widget-id': default: $timeline .= ' data-widget-id="' . esc_attr( $instance['twitter_widget_id'] ) . '"'; break; } // Close Twitter Markup $timeline .= '>'; $timeline .= esc_html__( 'Tweets by @', 'themeidol-all-widget' ) . esc_attr($instance['twitter_widget_username']); $timeline .= ''; // Output Markup echo $timeline; ?> = 200 $instance['twitter_widget_height'] = max ( $twitter_widget_height, 200 ); } else { $instance['twitter_widget_height'] = ''; } $twitter_widget_tweet_limit = absint( $new_instance['twitter_widget_tweet_limit'] ); $instance['twitter_widget_tweet_limit'] = ( $twitter_widget_tweet_limit ? $twitter_widget_tweet_limit : null ); $instance['twitter_widget_theme'] = $new_instance['twitter_widget_theme']; if ( ! in_array( $instance['twitter_widget_theme'], array( 'light', 'dark' ) ) ) { $instance['twitter_widget_theme'] = 'light'; } $instance['twitter_widget_link_color'] = sanitize_hex_color( $new_instance['twitter_widget_link_color'] ); $instance['twitter_widget_border_color'] = sanitize_hex_color( $new_instance['twitter_widget_border_color'] ); $instance['twitter_widget_chrome'] = array(); $chrome_settings = array( 'noheader', 'nofooter', 'noborders', 'noscrollbar', 'transparent' ); if ( isset( $new_instance['twitter_widget_chrome'] ) ) { foreach ( $new_instance['twitter_widget_chrome'] as $chrome ) { if ( in_array( $chrome, $chrome_settings ) ) { $instance['twitter_widget_chrome'][] = $chrome; } } } return $instance; } /** * Back-end widget form. * * @see WP_Widget::form() * * @param array $instance Previously saved values from database. */ function form( $instance ) { // Defaults $defaults = $this->defaults(); // Merge the user-selected arguments with the defaults. $instance = wp_parse_args( (array) $instance, $defaults ); // Controls $twitter_timeline_type = array ( 'username' => esc_html__( 'Username', 'themeidol-all-widget'), 'widget-id' => esc_html__( 'Widget ID', 'themeidol-all-widget'), ); $twitter_widget_theme = array ( 'light' => esc_html__( 'Light', 'themeidol-all-widget'), 'dark' => esc_html__( 'Dark', 'themeidol-all-widget'), ); ?>
id="get_field_id( 'twitter_widget_chrome_header' ); ?>" name="get_field_name( 'twitter_widget_chrome' ); ?>[]" value="noheader" />
id="get_field_id( 'twitter_widget_chrome_footer' ); ?>" name="get_field_name( 'twitter_widget_chrome' ); ?>[]" value="nofooter" />
id="get_field_id( 'twitter_widget_chrome_border' ); ?>" name="get_field_name( 'twitter_widget_chrome' ); ?>[]" value="noborders" />
id="get_field_id( 'twitter_widget_chrome_scrollbar' ); ?>" name="get_field_name( 'twitter_widget_chrome' ); ?>[]" value="noscrollbar" />
id="get_field_id( 'twitter_widget_chrome_transparent' ); ?>" name="get_field_name( 'twitter_widget_chrome' ); ?>[]" value="transparent" />