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.6.1 11.6.2 11.7 11.7.1 11.7.2 11.7.3 11.8 11.8.3 11.8.4 11.8.5 11.8.6 11.9 11.9.1 11.9.2 11.9.3 12.0 12.0.1 12.0.2 12.1 12.1.1 12.1.2 12.2 12.2.1 12.2.2 12.3 12.3.1 12.4 12.4.1 12.5 12.5.1 12.6 12.6.1 12.6.2 12.6.3 12.7 12.7.1 12.7.2 12.8 12.8.1 12.8.2 12.9 12.9.1 12.9.2 12.9.3 12.9.4 13.0 13.0.1 13.1 13.1.1 13.1.2 13.1.3 13.1.4 13.2 13.2.1 13.2.2 13.2.3 13.3 13.3.1 13.3.2 13.4 13.4.1 13.4.2 13.4.3 13.4.4 13.5 13.5.1 13.6 13.6.1 13.7 13.7.1 13.8 13.8.1 13.8.2 13.9 13.9.1 14.0 14.1 14.2 14.2.1 14.3 14.4 14.4.1 14.5 14.6 14.7 14.8 14.9 14.9.1 15.0 15.0.1 15.0.2 15.1 15.1.1 15.2 15.3 15.3.1 15.4 15.5 15.6 15.7 15.7-a.1 15.7-a.3 15.7-a.5 15.7-a.7 15.7-beta
jetpack / modules / widgets / social-media-icons.php
jetpack / modules / widgets Last commit date
authors 7 months ago contact-info 7 months ago eu-cookie-law 7 months ago facebook-likebox 11 years ago flickr 7 months ago gallery 7 months ago goodreads 7 months ago google-translate 1 year ago image-widget 7 months ago instagram 4 months ago internet-defense-league 1 year ago milestone 4 months ago my-community 7 months ago social-icons 4 months ago social-media-icons 7 months ago top-posts 7 months ago wordpress-post-widget 2 weeks ago authors.php 7 months ago blog-stats.php 7 months ago class-jetpack-eu-cookie-law-widget.php 1 month ago class-jetpack-instagram-widget.php 6 months ago contact-info.php 1 month ago customizer-controls.css 7 months ago customizer-utils.js 1 year ago facebook-likebox.php 1 month ago flickr.php 7 months ago gallery.php 1 month ago goodreads.php 1 month ago google-translate.php 1 month ago gravatar-profile.css 7 months ago gravatar-profile.php 1 month ago image-widget.php 7 months ago internet-defense-league.php 7 months ago mailchimp.php 7 months ago milestone.php 7 months ago my-community.php 1 month ago rsslinks-widget.php 2 weeks ago simple-payments.php 7 months ago social-icons.php 1 month ago social-media-icons.php 7 months ago top-posts.php 1 month ago twitter-timeline-admin.js 1 year ago twitter-timeline.php 2 weeks ago upcoming-events.php 7 months ago wordpress-post-widget.php 7 months ago
social-media-icons.php
366 lines
1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName.php
2 /**
3 * Social Media Icons Widget
4 *
5 * This widget is now deprecated.
6 * Any new features should go into modules/widgets/social-icons.php instead.
7 *
8 * @see https://github.com/Automattic/jetpack/pull/8498
9 *
10 * @package automattic/jetpack
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit( 0 );
15 }
16
17 // phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files.
18
19 /**
20 * WPCOM_social_media_icons_widget class.
21 *
22 * @extends WP_Widget
23 *
24 * phpcs:disable PEAR.NamingConventions.ValidClassName.Invalid
25 */
26 class WPCOM_social_media_icons_widget extends WP_Widget {
27 // phpcs:enable PEAR.NamingConventions.ValidClassName.Invalid
28 /**
29 * Defaults
30 *
31 * @var mixed
32 * @access private
33 */
34 private $defaults;
35
36 /**
37 * Services
38 *
39 * @var mixed
40 * @access private
41 */
42 private $services;
43
44 /**
45 * __construct function.
46 *
47 * @access public
48 * @return void
49 */
50 public function __construct() {
51 parent::__construct(
52 'wpcom_social_media_icons_widget',
53 /** This filter is documented in modules/widgets/facebook-likebox.php */
54 apply_filters( 'jetpack_widget_name', esc_html__( 'Social Media Icons (Deprecated)', 'jetpack' ) ),
55 array(
56 'description' => __( 'A simple widget that displays social media icons.', 'jetpack' ),
57 'customize_selective_refresh' => true,
58 )
59 );
60 $this->defaults = array(
61 'title' => __( 'Social', 'jetpack' ),
62 'facebook_username' => '',
63 'twitter_username' => '',
64 'instagram_username' => '',
65 'pinterest_username' => '',
66 'linkedin_username' => '',
67 'github_username' => '',
68 'youtube_username' => '',
69 'vimeo_username' => '',
70 'googleplus_username' => '',
71 'flickr_username' => '',
72 'wordpress_username' => '',
73 'twitch_username' => '',
74 'tumblr_username' => '',
75 );
76 $this->services = array(
77 'facebook' => array( 'Facebook', 'https://www.facebook.com/%s/' ),
78 'twitter' => array( 'Twitter', 'https://twitter.com/%s/' ),
79 'instagram' => array( 'Instagram', 'https://www.instagram.com/%s/' ),
80 'pinterest' => array( 'Pinterest', 'https://www.pinterest.com/%s/' ),
81 'linkedin' => array( 'LinkedIn', 'https://www.linkedin.com/in/%s/' ),
82 'github' => array( 'GitHub', 'https://github.com/%s/' ),
83 'youtube' => array( 'YouTube', 'https://www.youtube.com/%s/' ),
84 'vimeo' => array( 'Vimeo', 'https://vimeo.com/%s/' ),
85 'googleplus' => array( 'Google+', 'https://plus.google.com/u/0/%s/' ),
86 'flickr' => array( 'Flickr', 'https://www.flickr.com/photos/%s/' ),
87 'wordpress' => array( 'WordPress.org', 'https://profiles.wordpress.org/%s/' ),
88 'twitch' => array( 'Twitch', 'https://www.twitch.tv/%s/' ),
89 'tumblr' => array( 'Tumblr', 'https://%s.tumblr.com' ),
90 );
91 }
92
93 /**
94 * Enqueue Style.
95 *
96 * @access public
97 * @return void
98 */
99 public function enqueue_style() {
100 wp_register_style( 'jetpack_social_media_icons_widget', plugins_url( 'social-media-icons/style.css', __FILE__ ), array(), '20150602' );
101 wp_enqueue_style( 'jetpack_social_media_icons_widget' );
102 }
103
104 /**
105 * Check Genericons.
106 *
107 * @access private
108 * @return bool
109 */
110 private function check_genericons() {
111 global $wp_styles;
112 foreach ( $wp_styles->queue as $handle ) {
113 if ( false !== stristr( $handle, 'genericons' ) ) {
114 return $handle;
115 }
116 }
117 return false;
118 }
119
120 /**
121 * Widget Front End.
122 *
123 * @access public
124 * @param mixed $args Arguments.
125 * @param mixed $instance Instance.
126 * @return void
127 */
128 public function widget( $args, $instance ) {
129 $instance = wp_parse_args( (array) $instance, $this->defaults );
130 /** This filter is documented in core/src/wp-includes/default-widgets.php */
131 $instance['title'] = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
132
133 /*
134 * Enqueue frontend assets.
135 */
136
137 if ( ! $this->check_genericons() ) {
138 wp_enqueue_style( 'genericons' );
139 }
140
141 $this->enqueue_style();
142
143 $index = 10;
144 $html = array();
145 /* Translators: 1. Username. 2. Service name. */
146 $alt_text = esc_attr__( 'View %1$s&#8217;s profile on %2$s', 'jetpack' );
147 foreach ( $this->services as $service => $data ) {
148 list( $service_name, $url ) = $data;
149 if ( ! isset( $instance[ $service . '_username' ] ) ) {
150 continue;
151 }
152 $link_username = $instance[ $service . '_username' ];
153 $username = $link_username;
154 if ( empty( $username ) ) {
155 continue;
156 }
157 $index += 10;
158 $predefined_url = false;
159
160 /** Check if full URL entered in configuration, use it instead of tinkering */
161 if (
162 in_array(
163 wp_parse_url( $username, PHP_URL_SCHEME ),
164 array( 'http', 'https' ),
165 true
166 )
167 ) {
168 $predefined_url = $username;
169
170 /*
171 * In case of a predefined link we only display the service name
172 * for screen readers
173 */
174 $alt_text = '%2$s';
175 }
176
177 if ( 'googleplus' === $service
178 && ! is_numeric( $username )
179 && ! str_starts_with( $username, '+' )
180 ) {
181 $link_username = '+' . $username;
182 }
183 if ( 'youtube' === $service && str_starts_with( $username, 'UC' ) ) {
184 $link_username = 'channel/' . $username;
185 } elseif ( 'youtube' === $service ) {
186 $link_username = 'user/' . $username;
187 }
188
189 if ( ! $predefined_url ) {
190 $predefined_url = sprintf( $url, $link_username );
191 }
192 /**
193 * Fires for each profile link in the social icons widget. Can be used
194 * to change the links for certain social networks if needed. All URLs
195 * will be passed through `esc_attr` on output.
196 *
197 * @module widgets
198 *
199 * @since 3.8.0
200 *
201 * @param string $url the currently processed URL
202 * @param string $service the lowercase service slug, e.g. 'facebook', 'youtube', etc.
203 */
204 $link = apply_filters(
205 'jetpack_social_media_icons_widget_profile_link',
206 $predefined_url,
207 $service
208 );
209 $html[ $index ] = sprintf(
210 '<a href="%1$s" class="genericon genericon-%2$s" target="_blank"><span class="screen-reader-text">%3$s</span></a>',
211 esc_attr( $link ),
212 esc_attr( $service ),
213 sprintf( $alt_text, esc_html( $username ), $service_name )
214 );
215 }
216 /**
217 * Fires at the end of the list of Social Media accounts.
218 * Can be used to add a new Social Media Site to the Social Media Icons Widget.
219 * The filter function passed the array of HTML entries that will be sorted
220 * by key, each wrapped in a list item element and output as an unsorted list.
221 *
222 * @module widgets
223 *
224 * @since 3.8.0
225 *
226 * @param array $html Associative array of HTML snippets per each icon.
227 */
228 $html = apply_filters( 'jetpack_social_media_icons_widget_array', $html );
229 ksort( $html );
230 $html = '<ul><li>' . implode( '</li><li>', $html ) . '</li></ul>';
231 if ( ! empty( $instance['title'] ) ) {
232 $html = $args['before_title'] . $instance['title'] . $args['after_title'] . $html;
233 }
234 $html = $args['before_widget'] . $html . $args['after_widget'];
235
236 /** This action is documented in modules/widgets/gravatar-profile.php */
237 do_action( 'jetpack_stats_extra', 'widget_view', 'social_media_icons' );
238
239 /**
240 * Filters the Social Media Icons widget output.
241 *
242 * @module widgets
243 *
244 * @since 3.6.0
245 *
246 * @param string $html Social Media Icons widget html output.
247 */
248 echo apply_filters( 'jetpack_social_media_icons_widget_output', $html ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
249 }
250
251 /**
252 * Widget Settings.
253 *
254 * @access public
255 * @param mixed $instance Instance.
256 * @return string|void
257 */
258 public function form( $instance ) {
259 $instance = wp_parse_args( (array) $instance, $this->defaults );
260 ?>
261 <p>
262 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_attr_e( 'Title:', 'jetpack' ); ?></label>
263 <input
264 class="widefat"
265 id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"
266 name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>"
267 type="text"
268 value="<?php echo esc_attr( $instance['title'] ); ?>"
269 />
270 </p>
271 <?php
272 foreach ( $this->services as $service => $data ) {
273 list( $service_name, $url ) = $data; // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
274 ?>
275 <p>
276 <label for="<?php echo esc_attr( $this->get_field_id( $service . '_username' ) ); ?>">
277 <?php
278 printf(
279 /* translators: %s is a social network name, e.g. Facebook. */
280 esc_html__( '%s username:', 'jetpack' ),
281 esc_html( $service_name )
282 );
283 ?>
284 </label>
285 <input
286 class="widefat"
287 id="<?php echo esc_attr( $this->get_field_id( $service . '_username' ) ); ?>"
288 name="<?php echo esc_attr( $this->get_field_name( $service . '_username' ) ); ?>"
289 type="text"
290 value="<?php echo esc_attr( $instance[ $service . '_username' ] ); ?>"
291 />
292 </p>
293 <?php
294 }
295 }
296
297 /**
298 * Update Widget Settings.
299 *
300 * @access public
301 * @param array $new_instance New Instance.
302 * @param array|null $old_instance Old Instance.
303 * @return array Instance.
304 */
305 public function update( $new_instance, $old_instance ) {
306 $instance = (array) $old_instance;
307 foreach ( $new_instance as $field => $value ) {
308 $instance[ $field ] = sanitize_text_field( $new_instance[ $field ] );
309 }
310 // Stats.
311 $stats = $instance;
312 unset( $stats['title'] );
313 $stats = array_filter( $stats );
314 $stats = array_keys( $stats );
315 $stats = array_map( array( $this, 'remove_username' ), $stats );
316 foreach ( $stats as $val ) {
317 /**
318 * Fires for each Social Media account being saved in the Social Media Widget settings.
319 *
320 * @module widgets
321 *
322 * @since 3.6.0
323 *
324 * @param string social-media-links-widget-svcs Type of action to track.
325 * @param string $val Name of the Social Media account being saved.
326 */
327 do_action( 'jetpack_bump_stats_extras', 'social-media-links-widget-svcs', $val );
328 }
329 return $instance;
330 }
331
332 /**
333 * Remove username from value before to save stats.
334 *
335 * @access public
336 * @param string $val Value.
337 * @return string Value.
338 */
339 public function remove_username( $val ) {
340 return str_replace( '_username', '', $val );
341 }
342 } // End Class.
343
344 /**
345 * Register and load the widget.
346 *
347 * @access public
348 * @return void
349 */
350 function wpcom_social_media_icons_widget_load_widget() {
351 $transient = 'wpcom_social_media_icons_widget::is_active';
352 $has_widget = get_transient( $transient );
353
354 if ( false === $has_widget ) {
355 $is_active_widget = is_active_widget( false, false, 'wpcom_social_media_icons_widget', false );
356 $has_widget = (int) ! empty( $is_active_widget );
357 set_transient( $transient, $has_widget, 1 * HOUR_IN_SECONDS );
358 }
359
360 // [DEPRECATION]: Only register widget if active widget exists already
361 if ( $has_widget ) {
362 register_widget( 'wpcom_social_media_icons_widget' );
363 }
364 }
365 add_action( 'widgets_init', 'wpcom_social_media_icons_widget_load_widget' );
366