Widgets */ function jetpack_twitter_timeline_widget_init() { register_widget( 'Jetpack_Twitter_Timeline_Widget' ); } add_action( 'widgets_init', 'jetpack_twitter_timeline_widget_init' ); /** * Widget class. */ class Jetpack_Twitter_Timeline_Widget extends WP_Widget { /** * Register widget with WordPress. */ public function __construct() { parent::__construct( 'twitter_timeline', /** This filter is documented in modules/widgets/facebook-likebox.php */ apply_filters( 'jetpack_widget_name', esc_html__( 'Twitter Timeline', 'jetpack' ) ), array( 'classname' => 'widget_twitter_timeline', 'description' => __( 'Display an official Twitter Embedded Timeline widget.', 'jetpack' ), 'customize_selective_refresh' => true, ) ); if ( is_customize_preview() ) { add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); } add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) ); add_filter( 'widget_types_to_hide_from_legacy_widget_block', array( $this, 'hide_widget_in_block_editor' ) ); } /** * Remove the "Twitter Timeline" widget from the Legacy Widget block * * @param array $widget_types List of widgets that are currently removed from the Legacy Widget block. * @return array $widget_types New list of widgets that will be removed. */ public function hide_widget_in_block_editor( $widget_types ) { $widget_types[] = 'twitter_timeline'; return $widget_types; } /** * Enqueue scripts. */ public function enqueue_scripts() { if ( ! class_exists( 'Jetpack_AMP_Support' ) || ! Jetpack_AMP_Support::is_amp_request() ) { wp_enqueue_script( 'jetpack-twitter-timeline' ); } } /** * Enqueue script to improve admin UI * * @param string $hook Page hook. */ public function admin_scripts( $hook ) { // This is still 'widgets.php' when managing widgets via the Customizer. if ( 'widgets.php' === $hook ) { wp_enqueue_script( 'twitter-timeline-admin', Assets::get_file_url_for_environment( '_inc/build/widgets/twitter-timeline-admin.min.js', 'modules/widgets/twitter-timeline-admin.js' ), array( 'jquery' ), JETPACK__VERSION, 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 ) { $output = ''; // Twitter deprecated `data-widget-id` on 2018-05-25, // with cease support deadline on 2018-07-27. $explicit_widget_id = isset( $instance['type'] ) && 'widget-id' === $instance['type']; $implicit_widget_id = empty( $instance['type'] ) && ! empty( $instance['widget-id'] ) && is_numeric( $instance['widget-id'] ); if ( $explicit_widget_id || $implicit_widget_id ) { if ( current_user_can( 'edit_theme_options' ) ) { $output .= $args['before_widget'] . $args['before_title'] . esc_html__( 'Twitter Timeline', 'jetpack' ) . $args['after_title'] . '
' . esc_html__( "The Twitter Timeline widget can't display tweets based on searches or hashtags. To display a simple list of tweets instead, change the Widget ID to a Twitter username. Otherwise, delete this widget.", 'jetpack' ) . '
' . '' . esc_html__( '(Only administrators will see this message.)', 'jetpack' ) . '
' . $args['after_widget']; } echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped return; } $this->enqueue_scripts(); $instance['lang'] = substr( strtoupper( get_locale() ), 0, 2 ); $output .= $args['before_widget']; $title = isset( $instance['title'] ) ? $instance['title'] : ''; /** This filter is documented in core/src/wp-includes/default-widgets.php */ $title = apply_filters( 'widget_title', $title ); if ( ! empty( $title ) ) { $output .= $args['before_title'] . $title . $args['after_title']; } $possible_data_attribs = array( 'width', 'height', 'theme', 'border-color', 'tweet-limit', 'lang', ); $data_attrs = ''; foreach ( $possible_data_attribs as $att ) { if ( ! empty( $instance[ $att ] ) && ! is_array( $instance[ $att ] ) ) { $data_attrs .= ' data-' . esc_attr( $att ) . '="' . esc_attr( $instance[ $att ] ) . '"'; } } /** This filter is documented in modules/shortcodes/tweet.php */ $partner = apply_filters( 'jetpack_twitter_partner_id', 'jetpack' ); if ( ! empty( $partner ) ) { $data_attrs .= ' data-partner="' . esc_attr( $partner ) . '"'; } /** * Allow the activation of Do Not Track for the Twitter Timeline Widget. * * @see https://developer.twitter.com/en/docs/twitter-for-websites/timelines/guides/parameter-reference.html * * @module widgets * * @since 6.9.0 * * @param bool false Should the Twitter Timeline use the DNT attribute? Default to false. */ $dnt = apply_filters( 'jetpack_twitter_timeline_default_dnt', false ); if ( true === $dnt ) { $data_attrs .= ' data-dnt="true"'; } if ( ! empty( $instance['chrome'] ) && is_array( $instance['chrome'] ) ) { $data_attrs .= ' data-chrome="' . esc_attr( implode( ' ', $instance['chrome'] ) ) . '"'; } $timeline_placeholder = __( 'My Tweets', 'jetpack' ); /** * Filter the Timeline placeholder text. * * @module widgets * * @since 3.4.0 * * @param string $timeline_placeholder Timeline placeholder text. */ $timeline_placeholder = apply_filters( 'jetpack_twitter_timeline_placeholder', $timeline_placeholder ); $type = ( isset( $instance['type'] ) ? $instance['type'] : '' ); $widget_id = ( isset( $instance['widget-id'] ) ? $instance['widget-id'] : '' ); if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) { $width = ! empty( $instance['width'] ) ? $instance['width'] : 600; $height = ! empty( $instance['height'] ) ? $instance['height'] : 480; $output .= '
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"
/>