'jetpack_widget_social_icons', 'description' => __( 'Add social-media icons to your site.', 'jetpack' ), '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' ) ); } // Enqueue scripts and styles for the display of the widget, on the frontend or in the customizer. if ( is_active_widget( false, $this->id, $this->id_base, true ) || is_customize_preview() ) { add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_icon_scripts' ) ); add_action( 'wp_footer', array( $this, 'include_svg_icons' ), 9999 ); } } /** * 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-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() { ?> defaults ); /** 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'] . esc_html( $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' ) ); // Set target attribute for the link. if ( true === $instance['new-tab'] ) { $target = '_blank'; } else { $target = '_self'; } ?> defaults['icon-size']; 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(); 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; ?>

$this->get_field_id( 'url-icons' ), 'url-icon-name' => $this->get_field_name( 'url-icons' ), 'url-value' => $icon['url'], ) ); } ?>

/>

'', 'url-icon-name' => '', 'url-value' => '', ); $args = wp_parse_args( $args, $defaults ); ?>

', esc_attr( $args['url-icon-id'] ), esc_attr( $args['url-icon-name'] ), esc_attr__( 'Account URL', 'jetpack' ), esc_url( $args['url-value'], array( 'http', 'https', 'mailto', 'skype' ) ) ); ?>

'', ); // 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 = ''; /* * Display the icon. * * The whitespace around `` is intentional - it is a work around to a keyboard navigation bug in Safari 10. * * See https://core.trac.wordpress.org/ticket/38387. */ $svg .= ' '; $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( 'amazon.cn', 'amazon.in', 'amazon.fr', 'amazon.de', 'amazon.it', 'amazon.nl', 'amazon.es', 'amazon.co', 'amazon.ca', 'amazon.com', ), '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( '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( 'facebook.com' ), 'icon' => 'facebook', 'label' => 'Facebook', ), 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' ), ), array( 'url' => array( 'flickr.com' ), 'icon' => 'flickr', 'label' => 'Flickr', ), array( 'url' => array( 'foursquare.com' ), 'icon' => 'foursquare', 'label' => 'Foursquare', ), array( 'url' => array( 'goodreads.com' ), 'icon' => 'goodreads', 'label' => 'Goodreads', ), array( 'url' => array( 'google.com', 'google.co.uk', 'google.ca', 'google.cn', 'google.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' => array( 'meetup.com' ), 'icon' => 'meetup', 'label' => 'Meetup', ), array( 'url' => array( 'medium.com' ), 'icon' => 'medium', 'label' => 'Medium', ), array( 'url' => array( 'pinterest.' ), 'icon' => 'pinterest', 'label' => 'Pinterest', ), array( 'url' => array( 'getpocket.com' ), 'icon' => 'pocket', 'label' => 'Pocket', ), 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( '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( 'stumbleupon.com' ), 'icon' => 'stumbleupon', 'label' => 'StumbleUpon', ), 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( 'wordpress.com', 'wordpress.org' ), 'icon' => 'wordpress', 'label' => 'WordPress', ), array( 'url' => array( 'yelp.com' ), 'icon' => 'yelp', 'label' => 'Yelp', ), array( 'url' => array( 'youtube.com' ), 'icon' => 'youtube', 'label' => 'YouTube', ), ); return $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' );