'jetpack_widget_social_icons', 'description' => __( 'Add social-media icons to your site.', 'jetpack' ), 'show_instance_in_rest' => true, 'customize_selective_refresh' => true, ); parent::__construct( 'jetpack_widget_social_icons', /** This filter is documented in modules/widgets/facebook-likebox.php */ apply_filters( 'jetpack_widget_name', __( 'Social Icons', 'jetpack' ) ), $widget_ops ); $this->defaults = array( 'title' => __( 'Follow Us', 'jetpack' ), 'icon-size' => 'medium', 'new-tab' => false, 'icons' => array( array( 'url' => '', ), ), ); // Enqueue admin scrips and styles, only in the customizer or the old widgets page. if ( is_customize_preview() || 'widgets.php' === $pagenow ) { add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) ); add_action( 'admin_print_footer_scripts', array( $this, 'render_admin_js' ) ); } add_filter( 'widget_types_to_hide_from_legacy_widget_block', array( $this, 'hide_widget_in_block_editor' ) ); } /** * Remove the "Social Icons" 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[] = self::ID_BASE; return $widget_types; } /** * Script & styles for admin widget form. */ public function enqueue_admin_scripts() { wp_enqueue_script( 'jetpack-widget-social-icons-script', plugins_url( 'social-icons/social-icons-admin.js', __FILE__ ), array( 'jquery', 'jquery-ui-sortable' ), '20170506', true ); wp_enqueue_style( 'jetpack-widget-social-icons-admin', plugins_url( 'social-icons/social-icons-admin.css', __FILE__ ), array(), '20170506' ); } /** * Styles for front-end widget. */ public function enqueue_icon_scripts() { wp_enqueue_style( 'jetpack-widget-social-icons-styles', plugins_url( 'social-icons/social-icons.css', __FILE__ ), array(), '20170506' ); } /** * JavaScript for admin widget form. */ public function render_admin_js() { ?> array( 'style' => true, 'version' => true, 'xmlns' => true, 'xmlns:xlink' => true, ), 'defs' => array(), 'symbol' => array( 'id' => true, 'viewbox' => true, ), 'path' => array( 'd' => true, 'style' => true, ), ); echo wp_kses( $svg_contents, $allowed_tags ); } } /** * 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 = wp_parse_args( $instance, $this->defaults ); // Enqueue front end assets. $this->enqueue_icon_scripts(); add_action( 'wp_footer', array( $this, 'include_svg_icons' ), 9999 ); /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped if ( ! empty( $title ) ) { echo $args['before_title'] . $title . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } if ( ! empty( $instance['icons'] ) ) : // Get supported social icons. $social_icons = $this->get_supported_icons(); $default_icon = $this->get_svg_icon( array( 'icon' => 'chain' ) ); ?>
defaults['icon-size']; $instance['url-icons'] = array_key_exists( 'url-icons', $new_instance ) ? $new_instance['url-icons'] : array(); if ( in_array( $new_instance['icon-size'], array( 'small', 'medium', 'large' ), true ) ) { $instance['icon-size'] = $new_instance['icon-size']; } $instance['new-tab'] = isset( $new_instance['new-tab'] ) ? (bool) $new_instance['new-tab'] : false; $instance['icons'] = array(); if ( array_key_exists( 'url-icons', $new_instance ) ) { foreach ( $new_instance['url-icons'] as $url ) { $url = filter_var( $url, FILTER_SANITIZE_URL ); if ( ! empty( $url ) ) { $instance['icons'][] = array( 'url' => $url, ); } } } return $instance; } /** * Back-end widget form. * * @see WP_Widget::form() * * @param array $instance Previously saved values from database. * * @return string|void */ public function form( $instance ) { $instance = wp_parse_args( $instance, $this->defaults ); $title = sanitize_text_field( $instance['title'] ); $sizes = array( 'small' => __( 'Small', 'jetpack' ), 'medium' => __( 'Medium', 'jetpack' ), 'large' => __( 'Large', 'jetpack' ), ); $new_tab = isset( $instance['new-tab'] ) ? (bool) $instance['new-tab'] : false; ?>
/>
'', 'url-icon-name' => '', 'url-value' => '', ); $args = wp_parse_args( $args, $defaults ); ?> '', ); // Parse args. $args = wp_parse_args( $args, $defaults ); // Define an icon. if ( false === array_key_exists( 'icon', $args ) ) { return esc_html__( 'Please define an SVG icon filename.', 'jetpack' ); } // Set aria hidden. $aria_hidden = ' aria-hidden="true"'; // Begin SVG markup. $svg = ''; return $svg; } /** * Returns an array of supported social links (URL, icon, and label). * * @return array $social_links_icons */ public function get_supported_icons() { $social_links_icons = array( array( 'url' => array( '500px.com' ), 'icon' => '500px', 'label' => '500px', ), array( 'url' => array( '#https?:\/\/(www\.)?amazon\.(com|cn|in|fr|de|it|nl|es|co|ca)\/#', ), 'icon' => 'amazon', 'label' => 'Amazon', ), array( 'url' => array( 'apple.com' ), 'icon' => 'apple', 'label' => 'Apple', ), array( 'url' => array( 'itunes.com' ), 'icon' => 'apple', 'label' => 'iTunes', ), array( 'url' => array( 'bandcamp.com' ), 'icon' => 'bandcamp', 'label' => 'Bandcamp', ), array( 'url' => array( 'behance.net' ), 'icon' => 'behance', 'label' => 'Behance', ), array( 'url' => array( 'blogger.com', 'blogspot.com', ), 'icon' => 'blogger', 'label' => 'Blogger', ), array( 'url' => array( 'bsky.app' ), 'icon' => 'bluesky', 'label' => 'Bluesky', ), array( 'url' => array( 'codepen.io' ), 'icon' => 'codepen', 'label' => 'CodePen', ), array( 'url' => array( 'deviantart.com' ), 'icon' => 'deviantart', 'label' => 'DeviantArt', ), array( 'url' => array( 'digg.com' ), 'icon' => 'digg', 'label' => 'Digg', ), array( 'url' => array( '#discord\.gg|discordapp\.com#' ), 'icon' => 'discord', 'label' => 'Discord', ), array( 'url' => array( 'dribbble.com' ), 'icon' => 'dribbble', 'label' => 'Dribbble', ), array( 'url' => array( 'dropbox.com' ), 'icon' => 'dropbox', 'label' => 'Dropbox', ), array( 'url' => array( 'etsy.com' ), 'icon' => 'etsy', 'label' => 'Etsy', ), array( 'url' => array( 'eventbrite.com' ), 'icon' => 'eventbrite', 'label' => 'Eventbrite', ), array( 'url' => array( 'facebook.com' ), 'icon' => 'facebook', 'label' => 'Facebook', ), array( 'url' => array( 'flickr.com' ), 'icon' => 'flickr', 'label' => 'Flickr', ), array( 'url' => array( 'foursquare.com' ), 'icon' => 'foursquare', 'label' => 'Foursquare', ), array( 'url' => array( 'ghost.org' ), 'icon' => 'ghost', 'label' => 'Ghost', ), array( 'url' => array( 'goodreads.com' ), 'icon' => 'goodreads', 'label' => 'Goodreads', ), array( 'url' => array( '#google\.(com|co\.uk|ca|cn|it)#' ), 'icon' => 'google', 'label' => 'Google', ), array( 'url' => array( 'github.com' ), 'icon' => 'github', 'label' => 'GitHub', ), array( 'url' => array( 'instagram.com' ), 'icon' => 'instagram', 'label' => 'Instagram', ), array( 'url' => array( 'linkedin.com' ), 'icon' => 'linkedin', 'label' => 'LinkedIn', ), array( 'url' => array( 'mailto:' ), 'icon' => 'mail', 'label' => __( 'Email', 'jetpack' ), ), array( 'url' => jetpack_mastodon_get_instance_list(), 'icon' => 'mastodon', 'label' => 'Mastodon', ), array( 'url' => array( 'meetup.com' ), 'icon' => 'meetup', 'label' => 'Meetup', ), array( 'url' => array( 'medium.com' ), 'icon' => 'medium', 'label' => 'Medium', ), array( 'url' => array( 'nextdoor.com' ), 'icon' => 'nextdoor', 'label' => 'Nextdoor', ), array( 'url' => array( 'patreon.com' ), 'icon' => 'patreon', 'label' => 'Patreon', ), array( 'url' => array( 'pinterest.' ), 'icon' => 'pinterest', 'label' => 'Pinterest', ), array( 'url' => array( 'getpocket.com' ), 'icon' => 'pocket', 'label' => 'Pocket', ), array( 'url' => array( 'ravelry.com' ), 'icon' => 'ravelry', 'label' => 'Ravelry', ), array( 'url' => array( 'reddit.com' ), 'icon' => 'reddit', 'label' => 'Reddit', ), array( 'url' => array( 'skype.com' ), 'icon' => 'skype', 'label' => 'Skype', ), array( 'url' => array( 'skype:' ), 'icon' => 'skype', 'label' => 'Skype', ), array( 'url' => array( 'slideshare.net' ), 'icon' => 'slideshare', 'label' => 'SlideShare', ), array( 'url' => array( 'sms:' ), 'icon' => 'sms', 'label' => 'SMS', ), array( 'url' => array( 'snapchat.com' ), 'icon' => 'snapchat', 'label' => 'Snapchat', ), array( 'url' => array( 'soundcloud.com' ), 'icon' => 'soundcloud', 'label' => 'SoundCloud', ), array( 'url' => array( 'spotify.com' ), 'icon' => 'spotify', 'label' => 'Spotify', ), array( 'url' => array( 'stackoverflow.com' ), 'icon' => 'stackoverflow', 'label' => 'Stack Overflow', ), array( 'url' => array( 'strava.com' ), 'icon' => 'strava', 'label' => 'Strava', ), array( 'url' => array( 'stumbleupon.com' ), 'icon' => 'stumbleupon', 'label' => 'StumbleUpon', ), array( 'url' => array( '#https?:\/\/(www\.)?(telegram|t)\.me#' ), 'icon' => 'telegram', 'label' => 'Telegram', ), array( 'url' => array( 'threads.net' ), 'icon' => 'threads', 'label' => 'Threads', ), array( 'url' => array( 'tiktok.com' ), 'icon' => 'tiktok', 'label' => 'TikTok', ), array( 'url' => array( 'tumblr.com' ), 'icon' => 'tumblr', 'label' => 'Tumblr', ), array( 'url' => array( 'twitch.tv' ), 'icon' => 'twitch', 'label' => 'Twitch', ), array( 'url' => array( 'twitter.com' ), 'icon' => 'twitter', 'label' => 'Twitter', ), array( 'url' => array( 'vimeo.com' ), 'icon' => 'vimeo', 'label' => 'Vimeo', ), array( 'url' => array( 'vk.com' ), 'icon' => 'vk', 'label' => 'VK', ), array( 'url' => array( 'whatsapp.com' ), 'icon' => 'whatsapp', 'label' => 'WhatsApp', ), array( 'url' => array( 'woocommerce.com' ), 'icon' => 'woocommerce', 'label' => 'WooCommerce', ), array( 'url' => array( '#wordpress\.(com|org)#' ), 'icon' => 'wordpress', 'label' => 'WordPress', ), array( 'url' => array( 'yelp.com' ), 'icon' => 'yelp', 'label' => 'Yelp', ), array( 'url' => array( 'x.com' ), 'icon' => 'x', 'label' => 'X', ), array( 'url' => array( 'xanga.com' ), 'icon' => 'xanga', 'label' => 'Xanga', ), array( 'url' => array( 'youtube.com' ), 'icon' => 'youtube', 'label' => 'YouTube', ), // keep feed at the end so that more specific icons can take precedence. array( 'url' => array( '/feed/', // WordPress default feed url. '/feeds/', // Blogspot and others. '/blog/feed', // No trailing slash WordPress feed, could use /feed but may match unexpectedly. 'format=RSS', // Squarespace and others. '/rss', // Tumblr. '/.rss', // Reddit. '/rss.xml', // Moveable Type, Typepad. 'http://rss.', // Old custom format. 'https://rss.', // Old custom format. 'rss=1', '/feed=rss', // Catches feed=rss / feed=rss2. '?feed=rss', // WordPress non-permalink - Catches feed=rss / feed=rss2. '?feed=rdf', // WordPress non-permalink. '?feed=atom', // WordPress non-permalink. 'http://feeds.', // FeedBurner. 'https://feeds.', // FeedBurner. '/feed.xml', // Feedburner Alias, and others. '/index.xml', // Moveable Type, and others. '/atom.xml', // Typepad, Squarespace. '.atom', // Shopify blog. '/atom', // Some non-WordPress feeds. 'index.rdf', // Typepad. ), 'icon' => 'feed', 'label' => __( 'RSS Feed', 'jetpack' ), ), ); /** * Filter the list of services matching Social Media Icons available in the Social Icons SVG sprite. * * @since 12.3 * * @param array $social_links_icons Array of social links icons. */ return apply_filters( 'jetpack_social_icons_supported_icons', $social_links_icons ); } } // Jetpack_Widget_Social_Icons /** * Register and load the widget. * * @access public * @return void */ function jetpack_widget_social_icons_load() { register_widget( 'Jetpack_Widget_Social_Icons' ); } add_action( 'widgets_init', 'jetpack_widget_social_icons_load' );