PluginProbe ʕ •ᴥ•ʔ
Jetpack – WP Security, Backup, Speed, & Growth / 14.1.1
Jetpack – WP Security, Backup, Speed, & Growth v14.1.1
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 2 years ago facebook-likebox 11 years ago flickr 2 years ago gallery 2 years ago goodreads 2 years ago google-translate 4 years ago image-widget 8 years ago instagram 6 years ago internet-defense-league 2 years ago milestone 2 years ago my-community 8 years ago simple-payments 2 years ago social-icons 4 years ago social-media-icons 5 years ago top-posts 8 years ago wordpress-post-widget 2 years ago authors.php 1 year ago blog-stats.php 2 years ago class-jetpack-eu-cookie-law-widget.php 1 year ago class-jetpack-instagram-widget.php 1 year ago contact-info.php 2 years ago customizer-controls.css 9 years ago customizer-utils.js 6 years ago facebook-likebox.php 2 years ago flickr.php 1 year ago gallery.php 2 years ago goodreads.php 1 year ago google-translate.php 2 years ago gravatar-profile.css 10 years ago gravatar-profile.php 2 years ago image-widget.php 1 year ago internet-defense-league.php 3 years ago mailchimp.php 3 years ago milestone.php 5 years ago my-community.php 1 year ago rsslinks-widget.php 3 years ago simple-payments.php 1 year ago social-icons.php 1 year ago social-media-icons.php 1 year ago top-posts.php 1 year ago twitter-timeline-admin.js 6 years ago twitter-timeline.php 3 years ago upcoming-events.php 2 years ago wordpress-post-widget.php 4 years ago
social-media-icons.php
362 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 }
88
89 /**
90 * Enqueue Style.
91 *
92 * @access public
93 * @return void
94 */
95 public function enqueue_style() {
96 wp_register_style( 'jetpack_social_media_icons_widget', plugins_url( 'social-media-icons/style.css', __FILE__ ), array(), '20150602' );
97 wp_enqueue_style( 'jetpack_social_media_icons_widget' );
98 }
99
100 /**
101 * Check Genericons.
102 *
103 * @access private
104 * @return bool
105 */
106 private function check_genericons() {
107 global $wp_styles;
108 foreach ( $wp_styles->queue as $handle ) {
109 if ( false !== stristr( $handle, 'genericons' ) ) {
110 return $handle;
111 }
112 }
113 return false;
114 }
115
116 /**
117 * Widget Front End.
118 *
119 * @access public
120 * @param mixed $args Arguments.
121 * @param mixed $instance Instance.
122 * @return void
123 */
124 public function widget( $args, $instance ) {
125 $instance = wp_parse_args( (array) $instance, $this->defaults );
126 /** This filter is documented in core/src/wp-includes/default-widgets.php */
127 $instance['title'] = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
128
129 /*
130 * Enqueue frontend assets.
131 */
132
133 if ( ! $this->check_genericons() ) {
134 wp_enqueue_style( 'genericons' );
135 }
136
137 $this->enqueue_style();
138
139 $index = 10;
140 $html = array();
141 /* Translators: 1. Username. 2. Service name. */
142 $alt_text = esc_attr__( 'View %1$s&#8217;s profile on %2$s', 'jetpack' );
143 foreach ( $this->services as $service => $data ) {
144 list( $service_name, $url ) = $data;
145 if ( ! isset( $instance[ $service . '_username' ] ) ) {
146 continue;
147 }
148 $link_username = $instance[ $service . '_username' ];
149 $username = $link_username;
150 if ( empty( $username ) ) {
151 continue;
152 }
153 $index += 10;
154 $predefined_url = false;
155
156 /** Check if full URL entered in configuration, use it instead of tinkering */
157 if (
158 in_array(
159 wp_parse_url( $username, PHP_URL_SCHEME ),
160 array( 'http', 'https' ),
161 true
162 )
163 ) {
164 $predefined_url = $username;
165
166 /*
167 * In case of a predefined link we only display the service name
168 * for screen readers
169 */
170 $alt_text = '%2$s';
171 }
172
173 if ( 'googleplus' === $service
174 && ! is_numeric( $username )
175 && ! str_starts_with( $username, '+' )
176 ) {
177 $link_username = '+' . $username;
178 }
179 if ( 'youtube' === $service && str_starts_with( $username, 'UC' ) ) {
180 $link_username = 'channel/' . $username;
181 } elseif ( 'youtube' === $service ) {
182 $link_username = 'user/' . $username;
183 }
184
185 if ( ! $predefined_url ) {
186 $predefined_url = sprintf( $url, $link_username );
187 }
188 /**
189 * Fires for each profile link in the social icons widget. Can be used
190 * to change the links for certain social networks if needed. All URLs
191 * will be passed through `esc_attr` on output.
192 *
193 * @module widgets
194 *
195 * @since 3.8.0
196 *
197 * @param string $url the currently processed URL
198 * @param string $service the lowercase service slug, e.g. 'facebook', 'youtube', etc.
199 */
200 $link = apply_filters(
201 'jetpack_social_media_icons_widget_profile_link',
202 $predefined_url,
203 $service
204 );
205 $html[ $index ] = sprintf(
206 '<a href="%1$s" class="genericon genericon-%2$s" target="_blank"><span class="screen-reader-text">%3$s</span></a>',
207 esc_attr( $link ),
208 esc_attr( $service ),
209 sprintf( $alt_text, esc_html( $username ), $service_name )
210 );
211 }
212 /**
213 * Fires at the end of the list of Social Media accounts.
214 * Can be used to add a new Social Media Site to the Social Media Icons Widget.
215 * The filter function passed the array of HTML entries that will be sorted
216 * by key, each wrapped in a list item element and output as an unsorted list.
217 *
218 * @module widgets
219 *
220 * @since 3.8.0
221 *
222 * @param array $html Associative array of HTML snippets per each icon.
223 */
224 $html = apply_filters( 'jetpack_social_media_icons_widget_array', $html );
225 ksort( $html );
226 $html = '<ul><li>' . implode( '</li><li>', $html ) . '</li></ul>';
227 if ( ! empty( $instance['title'] ) ) {
228 $html = $args['before_title'] . $instance['title'] . $args['after_title'] . $html;
229 }
230 $html = $args['before_widget'] . $html . $args['after_widget'];
231
232 /** This action is documented in modules/widgets/gravatar-profile.php */
233 do_action( 'jetpack_stats_extra', 'widget_view', 'social_media_icons' );
234
235 /**
236 * Filters the Social Media Icons widget output.
237 *
238 * @module widgets
239 *
240 * @since 3.6.0
241 *
242 * @param string $html Social Media Icons widget html output.
243 */
244 echo apply_filters( 'jetpack_social_media_icons_widget_output', $html ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
245 }
246
247 /**
248 * Widget Settings.
249 *
250 * @access public
251 * @param mixed $instance Instance.
252 * @return void
253 */
254 public function form( $instance ) {
255 $instance = wp_parse_args( (array) $instance, $this->defaults );
256 ?>
257 <p>
258 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_attr_e( 'Title:', 'jetpack' ); ?></label>
259 <input
260 class="widefat"
261 id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"
262 name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>"
263 type="text"
264 value="<?php echo esc_attr( $instance['title'] ); ?>"
265 />
266 </p>
267 <?php
268 foreach ( $this->services as $service => $data ) {
269 list( $service_name, $url ) = $data; // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
270 ?>
271 <p>
272 <label for="<?php echo esc_attr( $this->get_field_id( $service . '_username' ) ); ?>">
273 <?php
274 printf(
275 /* translators: %s is a social network name, e.g. Facebook. */
276 esc_html__( '%s username:', 'jetpack' ),
277 esc_html( $service_name )
278 );
279 ?>
280 </label>
281 <input
282 class="widefat"
283 id="<?php echo esc_attr( $this->get_field_id( $service . '_username' ) ); ?>"
284 name="<?php echo esc_attr( $this->get_field_name( $service . '_username' ) ); ?>"
285 type="text"
286 value="<?php echo esc_attr( $instance[ $service . '_username' ] ); ?>"
287 />
288 </p>
289 <?php
290 }
291 }
292
293 /**
294 * Update Widget Settings.
295 *
296 * @access public
297 * @param array $new_instance New Instance.
298 * @param array|null $old_instance Old Instance.
299 * @return array Instance.
300 */
301 public function update( $new_instance, $old_instance ) {
302 $instance = (array) $old_instance;
303 foreach ( $new_instance as $field => $value ) {
304 $instance[ $field ] = sanitize_text_field( $new_instance[ $field ] );
305 }
306 // Stats.
307 $stats = $instance;
308 unset( $stats['title'] );
309 $stats = array_filter( $stats );
310 $stats = array_keys( $stats );
311 $stats = array_map( array( $this, 'remove_username' ), $stats );
312 foreach ( $stats as $val ) {
313 /**
314 * Fires for each Social Media account being saved in the Social Media Widget settings.
315 *
316 * @module widgets
317 *
318 * @since 3.6.0
319 *
320 * @param string social-media-links-widget-svcs Type of action to track.
321 * @param string $val Name of the Social Media account being saved.
322 */
323 do_action( 'jetpack_bump_stats_extras', 'social-media-links-widget-svcs', $val );
324 }
325 return $instance;
326 }
327
328 /**
329 * Remove username from value before to save stats.
330 *
331 * @access public
332 * @param string $val Value.
333 * @return string Value.
334 */
335 public function remove_username( $val ) {
336 return str_replace( '_username', '', $val );
337 }
338 } // End Class.
339
340 /**
341 * Register and load the widget.
342 *
343 * @access public
344 * @return void
345 */
346 function wpcom_social_media_icons_widget_load_widget() {
347 $transient = 'wpcom_social_media_icons_widget::is_active';
348 $has_widget = get_transient( $transient );
349
350 if ( false === $has_widget ) {
351 $is_active_widget = is_active_widget( false, false, 'wpcom_social_media_icons_widget', false );
352 $has_widget = (int) ! empty( $is_active_widget );
353 set_transient( $transient, $has_widget, 1 * HOUR_IN_SECONDS );
354 }
355
356 // [DEPRECATION]: Only register widget if active widget exists already
357 if ( $has_widget ) {
358 register_widget( 'wpcom_social_media_icons_widget' );
359 }
360 }
361 add_action( 'widgets_init', 'wpcom_social_media_icons_widget_load_widget' );
362