PluginProbe ʕ •ᴥ•ʔ
Jetpack – WP Security, Backup, Speed, & Growth / 12.2.3
Jetpack – WP Security, Backup, Speed, & Growth v12.2.3
12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 14.4.2 14.5.1 14.6.1 14.7.1 14.8.1 14.9.2 15.0.3 15.1.2 15.2.1 15.3.2 15.4.1 15.5.1 15.6.1 15.7.2 15.8.1 15.9.2 16.0.2 16.1.3 16.2-a.5 16.2-a.3 16.1.2 16.2-a.1 16.1.1 16.1 16.1-beta 16.1-beta.2 16.1-beta.3 16.1-a.5 16.1-a.3 16.0.1 16.1-a.1 16.0 16.0-beta 16.0-a.7 16.0-a.5 15.9.1 16.0-a.3 16.0-a.1 15.9 15.9-beta 15.9-a.7 15.9-a.5 15.9-a.3 15.9-a.1 15.8 15.8-beta 15.8-a.7 15.8-a.5 5.2.5 5.3.4 5.4.4 5.5.5 5.6.5 5.7.5 5.8.4 5.9.4 6.0.4 6.1 6.1.1 6.1.2 6.1.3 6.1.4 6.1.5 6.2 6.2.1 6.2.2 6.2.3 6.2.4 6.2.5 6.3 6.3.1 6.3.2 6.3.3 6.3.4 6.3.5 6.3.6 6.3.7 6.4 6.4.1 6.4.2 6.4.3 6.4.4 6.4.5 6.4.6 6.5 6.5.1 6.5.2 6.5.3 6.5.4 6.6 6.6.1 6.6.2 6.6.3 6.6.4 6.6.5 6.7 6.7.1 6.7.2 6.7.3 6.7.4 6.8 6.8.1 6.8.2 6.8.3 6.8.4 6.8.5 6.9 6.9.1 6.9.2 6.9.3 6.9.4 7.0 7.0.1 7.0.2 7.0.3 7.0.4 7.0.5 7.1 7.1.1 7.1.2 7.1.3 7.1.4 7.1.5 7.2 7.2.1 7.2.1.1 7.2.2 7.2.3 7.2.4 7.2.5 7.3 7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3 4.7.4 4.8.5 4.9.3 5.0.3 5.1.4 trunk 10.0 10.0.1 10.0.2 10.1 10.1.1 10.1.2 10.2 10.2.1 10.2.2 10.2.3 10.3 10.3.1 10.3.2 10.4 10.4.1 10.4.2 10.5 10.5.1 10.5.2 10.5.3 10.6 10.6.1 10.6.2 10.7 10.7.1 10.7.2 10.8 10.8.1 10.8.2 10.9 10.9.1 10.9.2 10.9.3 11.0 11.0.1 11.0.2 11.1 11.1.1 11.1.2 11.1.3 11.1.4 11.2 11.2.1 11.2.2 11.3 11.3.1 11.3.2 11.3.3 11.3.4 11.4 11.4.1 11.4.2 11.5 11.5.1 11.5.2 11.5.3 11.6 11.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 8 years ago contact-info 5 years ago eu-cookie-law 4 years ago facebook-likebox 11 years ago flickr 4 years ago gallery 4 years ago goodreads 5 years ago google-translate 4 years ago image-widget 8 years ago instagram 6 years ago migrate-to-core 3 years ago milestone 3 years ago my-community 8 years ago simple-payments 4 years ago social-icons 4 years ago social-media-icons 5 years ago top-posts 8 years ago wordpress-post-widget 3 years ago authors.php 3 years ago blog-stats.php 3 years ago class-jetpack-eu-cookie-law-widget.php 3 years ago class-jetpack-instagram-widget.php 3 years ago contact-info.php 3 years ago customizer-controls.css 9 years ago customizer-utils.js 6 years ago facebook-likebox.php 3 years ago flickr.php 3 years ago gallery.php 3 years ago goodreads.php 3 years ago google-translate.php 3 years ago gravatar-profile.css 10 years ago gravatar-profile.php 3 years ago image-widget.php 3 years ago internet-defense-league.php 3 years ago mailchimp.php 3 years ago milestone.php 5 years ago my-community.php 3 years ago rsslinks-widget.php 3 years ago simple-payments.php 3 years ago social-icons.php 3 years ago social-media-icons.php 3 years ago top-posts.php 3 years ago twitter-timeline-admin.js 6 years ago twitter-timeline.php 3 years ago upcoming-events.php 3 years ago wordpress-post-widget.php 4 years ago
social-media-icons.php
357 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 // phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files.
14
15 /**
16 * WPCOM_social_media_icons_widget class.
17 *
18 * @extends WP_Widget
19 *
20 * phpcs:disable PEAR.NamingConventions.ValidClassName.Invalid
21 */
22 class WPCOM_social_media_icons_widget extends WP_Widget {
23 // phpcs:enable PEAR.NamingConventions.ValidClassName.Invalid
24 /**
25 * Defaults
26 *
27 * @var mixed
28 * @access private
29 */
30 private $defaults;
31
32 /**
33 * Services
34 *
35 * @var mixed
36 * @access private
37 */
38 private $services;
39
40 /**
41 * __construct function.
42 *
43 * @access public
44 * @return void
45 */
46 public function __construct() {
47 parent::__construct(
48 'wpcom_social_media_icons_widget',
49 /** This filter is documented in modules/widgets/facebook-likebox.php */
50 apply_filters( 'jetpack_widget_name', esc_html__( 'Social Media Icons (Deprecated)', 'jetpack' ) ),
51 array(
52 'description' => __( 'A simple widget that displays social media icons.', 'jetpack' ),
53 'customize_selective_refresh' => true,
54 )
55 );
56 $this->defaults = array(
57 'title' => __( 'Social', 'jetpack' ),
58 'facebook_username' => '',
59 'twitter_username' => '',
60 'instagram_username' => '',
61 'pinterest_username' => '',
62 'linkedin_username' => '',
63 'github_username' => '',
64 'youtube_username' => '',
65 'vimeo_username' => '',
66 'googleplus_username' => '',
67 'flickr_username' => '',
68 'wordpress_username' => '',
69 'twitch_username' => '',
70 'tumblr_username' => '',
71 );
72 $this->services = array(
73 'facebook' => array( 'Facebook', 'https://www.facebook.com/%s/' ),
74 'twitter' => array( 'Twitter', 'https://twitter.com/%s/' ),
75 'instagram' => array( 'Instagram', 'https://www.instagram.com/%s/' ),
76 'pinterest' => array( 'Pinterest', 'https://www.pinterest.com/%s/' ),
77 'linkedin' => array( 'LinkedIn', 'https://www.linkedin.com/in/%s/' ),
78 'github' => array( 'GitHub', 'https://github.com/%s/' ),
79 'youtube' => array( 'YouTube', 'https://www.youtube.com/%s/' ),
80 'vimeo' => array( 'Vimeo', 'https://vimeo.com/%s/' ),
81 'googleplus' => array( 'Google+', 'https://plus.google.com/u/0/%s/' ),
82 'flickr' => array( 'Flickr', 'https://www.flickr.com/photos/%s/' ),
83 'wordpress' => array( 'WordPress.org', 'https://profiles.wordpress.org/%s/' ),
84 'twitch' => array( 'Twitch', 'https://www.twitch.tv/%s/' ),
85 'tumblr' => array( 'Tumblr', 'https://%s.tumblr.com' ),
86 );
87 if ( is_active_widget( false, false, $this->id_base ) || is_customize_preview() ) {
88 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ) );
89 }
90 }
91
92 /**
93 * Enqueue Style.
94 *
95 * @access public
96 * @return void
97 */
98 public function enqueue_style() {
99 wp_register_style( 'jetpack_social_media_icons_widget', plugins_url( 'social-media-icons/style.css', __FILE__ ), array(), '20150602' );
100 wp_enqueue_style( 'jetpack_social_media_icons_widget' );
101 }
102
103 /**
104 * Check Genericons.
105 *
106 * @access private
107 * @return Bool.
108 */
109 private function check_genericons() {
110 global $wp_styles;
111 foreach ( $wp_styles->queue as $handle ) {
112 if ( false !== stristr( $handle, 'genericons' ) ) {
113 return $handle;
114 }
115 }
116 return false;
117 }
118
119 /**
120 * Widget Front End.
121 *
122 * @access public
123 * @param mixed $args Arguments.
124 * @param mixed $instance Instance.
125 * @return void
126 */
127 public function widget( $args, $instance ) {
128 $instance = wp_parse_args( (array) $instance, $this->defaults );
129 /** This filter is documented in core/src/wp-includes/default-widgets.php */
130 $instance['title'] = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
131 if ( ! $this->check_genericons() ) {
132 wp_enqueue_style( 'genericons' );
133 }
134 $index = 10;
135 $html = array();
136 /* Translators: 1. Username. 2. Service name. */
137 $alt_text = esc_attr__( 'View %1$s&#8217;s profile on %2$s', 'jetpack' );
138 foreach ( $this->services as $service => $data ) {
139 list( $service_name, $url ) = $data;
140 if ( ! isset( $instance[ $service . '_username' ] ) ) {
141 continue;
142 }
143 $link_username = $instance[ $service . '_username' ];
144 $username = $link_username;
145 if ( empty( $username ) ) {
146 continue;
147 }
148 $index += 10;
149 $predefined_url = false;
150
151 /** Check if full URL entered in configuration, use it instead of tinkering */
152 if (
153 in_array(
154 wp_parse_url( $username, PHP_URL_SCHEME ),
155 array( 'http', 'https' ),
156 true
157 )
158 ) {
159 $predefined_url = $username;
160
161 /*
162 * In case of a predefined link we only display the service name
163 * for screen readers
164 */
165 $alt_text = '%2$s';
166 }
167
168 if ( 'googleplus' === $service
169 && ! is_numeric( $username )
170 && substr( $username, 0, 1 ) !== '+'
171 ) {
172 $link_username = '+' . $username;
173 }
174 if ( 'youtube' === $service && 'UC' === substr( $username, 0, 2 ) ) {
175 $link_username = 'channel/' . $username;
176 } elseif ( 'youtube' === $service ) {
177 $link_username = 'user/' . $username;
178 }
179
180 if ( ! $predefined_url ) {
181 $predefined_url = sprintf( $url, $link_username );
182 }
183 /**
184 * Fires for each profile link in the social icons widget. Can be used
185 * to change the links for certain social networks if needed. All URLs
186 * will be passed through `esc_attr` on output.
187 *
188 * @module widgets
189 *
190 * @since 3.8.0
191 *
192 * @param string $url the currently processed URL
193 * @param string $service the lowercase service slug, e.g. 'facebook', 'youtube', etc.
194 */
195 $link = apply_filters(
196 'jetpack_social_media_icons_widget_profile_link',
197 $predefined_url,
198 $service
199 );
200 $html[ $index ] = sprintf(
201 '<a href="%1$s" class="genericon genericon-%2$s" target="_blank"><span class="screen-reader-text">%3$s</span></a>',
202 esc_attr( $link ),
203 esc_attr( $service ),
204 sprintf( $alt_text, esc_html( $username ), $service_name )
205 );
206 }
207 /**
208 * Fires at the end of the list of Social Media accounts.
209 * Can be used to add a new Social Media Site to the Social Media Icons Widget.
210 * The filter function passed the array of HTML entries that will be sorted
211 * by key, each wrapped in a list item element and output as an unsorted list.
212 *
213 * @module widgets
214 *
215 * @since 3.8.0
216 *
217 * @param array $html Associative array of HTML snippets per each icon.
218 */
219 $html = apply_filters( 'jetpack_social_media_icons_widget_array', $html );
220 ksort( $html );
221 $html = '<ul><li>' . implode( '</li><li>', $html ) . '</li></ul>';
222 if ( ! empty( $instance['title'] ) ) {
223 $html = $args['before_title'] . $instance['title'] . $args['after_title'] . $html;
224 }
225 $html = $args['before_widget'] . $html . $args['after_widget'];
226
227 /** This action is documented in modules/widgets/gravatar-profile.php */
228 do_action( 'jetpack_stats_extra', 'widget_view', 'social_media_icons' );
229
230 /**
231 * Filters the Social Media Icons widget output.
232 *
233 * @module widgets
234 *
235 * @since 3.6.0
236 *
237 * @param string $html Social Media Icons widget html output.
238 */
239 echo apply_filters( 'jetpack_social_media_icons_widget_output', $html ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
240 }
241
242 /**
243 * Widget Settings.
244 *
245 * @access public
246 * @param mixed $instance Instance.
247 * @return void
248 */
249 public function form( $instance ) {
250 $instance = wp_parse_args( (array) $instance, $this->defaults );
251 ?>
252 <p>
253 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_attr_e( 'Title:', 'jetpack' ); ?></label>
254 <input
255 class="widefat"
256 id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"
257 name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>"
258 type="text"
259 value="<?php echo esc_attr( $instance['title'] ); ?>"
260 />
261 </p>
262 <?php
263 foreach ( $this->services as $service => $data ) {
264 list( $service_name, $url ) = $data; // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
265 ?>
266 <p>
267 <label for="<?php echo esc_attr( $this->get_field_id( $service . '_username' ) ); ?>">
268 <?php
269 printf(
270 /* translators: %s is a social network name, e.g. Facebook. */
271 esc_html__( '%s username:', 'jetpack' ),
272 esc_html( $service_name )
273 );
274 ?>
275 </label>
276 <input
277 class="widefat"
278 id="<?php echo esc_attr( $this->get_field_id( $service . '_username' ) ); ?>"
279 name="<?php echo esc_attr( $this->get_field_name( $service . '_username' ) ); ?>"
280 type="text"
281 value="<?php echo esc_attr( $instance[ $service . '_username' ] ); ?>"
282 />
283 </p>
284 <?php
285 }
286 }
287
288 /**
289 * Update Widget Settings.
290 *
291 * @access public
292 * @param mixed $new_instance New Instance.
293 * @param mixed $old_instance Old Instance.
294 * @return Instance.
295 */
296 public function update( $new_instance, $old_instance ) {
297 $instance = (array) $old_instance;
298 foreach ( $new_instance as $field => $value ) {
299 $instance[ $field ] = sanitize_text_field( $new_instance[ $field ] );
300 }
301 // Stats.
302 $stats = $instance;
303 unset( $stats['title'] );
304 $stats = array_filter( $stats );
305 $stats = array_keys( $stats );
306 $stats = array_map( array( $this, 'remove_username' ), $stats );
307 foreach ( $stats as $val ) {
308 /**
309 * Fires for each Social Media account being saved in the Social Media Widget settings.
310 *
311 * @module widgets
312 *
313 * @since 3.6.0
314 *
315 * @param string social-media-links-widget-svcs Type of action to track.
316 * @param string $val Name of the Social Media account being saved.
317 */
318 do_action( 'jetpack_bump_stats_extras', 'social-media-links-widget-svcs', $val );
319 }
320 return $instance;
321 }
322
323 /**
324 * Remove username from value before to save stats.
325 *
326 * @access public
327 * @param mixed $val Value.
328 * @return Value.
329 */
330 public function remove_username( $val ) {
331 return str_replace( '_username', '', $val );
332 }
333 } // End Class.
334
335 /**
336 * Register and load the widget.
337 *
338 * @access public
339 * @return void
340 */
341 function wpcom_social_media_icons_widget_load_widget() {
342 $transient = 'wpcom_social_media_icons_widget::is_active';
343 $has_widget = get_transient( $transient );
344
345 if ( false === $has_widget ) {
346 $is_active_widget = is_active_widget( false, false, 'wpcom_social_media_icons_widget', false );
347 $has_widget = (int) ! empty( $is_active_widget );
348 set_transient( $transient, $has_widget, 1 * HOUR_IN_SECONDS );
349 }
350
351 // [DEPRECATION]: Only register widget if active widget exists already
352 if ( $has_widget ) {
353 register_widget( 'wpcom_social_media_icons_widget' );
354 }
355 }
356 add_action( 'widgets_init', 'wpcom_social_media_icons_widget_load_widget' );
357