PluginProbe ʕ •ᴥ•ʔ
Jetpack – WP Security, Backup, Speed, & Growth / 13.5.2
Jetpack – WP Security, Backup, Speed, & Growth v13.5.2
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.3.0.1 7.3.1 7.3.1.1 7.3.2 7.3.3 7.3.4 7.3.5 7.4 7.4.1 7.4.2 7.4.3 7.4.4 7.4.5 7.5 7.5.0.1 7.5.1 7.5.2 7.5.3 7.5.4 7.5.5 7.5.6 7.5.7 7.6 7.6.1 7.6.2 7.6.3 7.6.4 7.7 7.7.1 7.7.2 7.7.3 7.7.4 7.7.5 7.7.6 7.8 7.8.1 7.8.2 7.8.3 7.8.4 7.9 7.9.1 7.9.2 7.9.3 7.9.4 8.0 8.0.1 8.0.2 8.0.3 8.1 8.1.1 8.1.2 8.1.3 8.1.4 8.2 8.2.0.1 8.2.1 8.2.2 8.2.3 8.2.4 8.2.5 8.2.6 8.3 8.3.1 8.3.2 8.3.3 8.4 8.4.1 8.4.2 8.4.3 8.4.4 8.4.5 8.5 8.5.1 8.5.2 8.5.3 8.6 8.6.1 8.6.2 8.6.3 8.6.4 8.7 8.7.0.1 8.7.1 8.7.2 8.7.3 8.7.4 8.8 8.8.1 8.8.2 8.8.3 8.8.4 8.8.5 8.9 8.9.1 8.9.2 8.9.3 8.9.4 9.0 9.0.1 9.0.2 9.0.3 9.0.4 9.0.5 9.1 9.1.1 9.1.2 9.1.3 9.2 9.2.1 9.2.2 9.2.3 9.2.4 9.3 9.3.1 9.3.2 9.3.3 9.3.4 9.3.5 9.4 9.4.1 9.4.2 9.4.3 9.4.4 9.5 9.5.1 9.5.2 9.5.3 9.5.4 9.5.5 9.6 9.6.1 9.6.2 9.6.3 9.6.4 9.7 9.7.1 9.7.2 15.7-beta.2 9.7.3 15.7.1 9.8 15.8-a.1 9.8.1 15.8-a.3 9.8.2 2.0.9 9.8.3 2.1.7 9.9 2.2.10 9.9.1 2.3.10 9.9.2 2.4.7 9.9.3 2.5.5 2.6.6 2.7.5 2.8.5 2.9.6 3.0.6 3.1.5 3.2.5 3.3.6 3.4.6 3.5.6 3.6.4 3.7.5 3.8.5 3.9.10 4.0.7 4.1.4 4.2.5 4.3.5 4.4.5 4.5.3 4.6.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 / facebook-likebox.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 3 years ago migrate-to-core 3 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 3 years ago blog-stats.php 2 years ago class-jetpack-eu-cookie-law-widget.php 2 years ago class-jetpack-instagram-widget.php 2 years 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 2 years ago gallery.php 2 years ago goodreads.php 2 years ago google-translate.php 2 years ago gravatar-profile.css 10 years ago gravatar-profile.php 2 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 2 years ago rsslinks-widget.php 3 years ago simple-payments.php 2 years ago social-icons.php 2 years ago social-media-icons.php 2 years ago top-posts.php 2 years 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
facebook-likebox.php
453 lines
1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2
3 // phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files.
4
5 add_action( 'widgets_init', 'jetpack_facebook_likebox_init' );
6 /**
7 * Register the widget for use in Appearance -> Widgets
8 */
9 function jetpack_facebook_likebox_init() {
10 register_widget( 'WPCOM_Widget_Facebook_LikeBox' );
11 }
12
13 /**
14 * Facebook Page Plugin (formerly known as the Like Box)
15 * Display a Facebook Page Plugin as a widget (replaces the old like box plugin)
16 * https://developers.facebook.com/docs/plugins/page-plugin
17 */
18 class WPCOM_Widget_Facebook_LikeBox extends WP_Widget {
19 /**
20 * Default height.
21 *
22 * @var int
23 */
24 private $default_height = 580;
25
26 /**
27 * Default width.
28 *
29 * @var int
30 */
31 private $default_width = 340;
32
33 /**
34 * Max width.
35 *
36 * @var int
37 */
38 private $max_width = 500;
39
40 /**
41 * Min width.
42 *
43 * @var int
44 */
45 private $min_width = 180;
46
47 /**
48 * Max height.
49 *
50 * @var int
51 */
52 private $max_height = 9999;
53
54 /**
55 * Min height/
56 *
57 * @var int
58 */
59 private $min_height = 130;
60
61 /**
62 * WPCOM_Widget_Facebook_LikeBox constructor.
63 */
64 public function __construct() {
65 parent::__construct(
66 'facebook-likebox',
67 /**
68 * Filter the name of a widget included in the Extra Sidebar Widgets module.
69 *
70 * @module widgets
71 *
72 * @since 2.1.2
73 *
74 * @param string $widget_name Widget title.
75 */
76 apply_filters( 'jetpack_widget_name', __( 'Facebook Page Plugin', 'jetpack' ) ),
77 array(
78 'classname' => 'widget_facebook_likebox',
79 'description' => __( 'Use the Facebook Page Plugin to connect visitors to your Facebook Page', 'jetpack' ),
80 'customize_selective_refresh' => true,
81 )
82 );
83
84 if ( is_active_widget( false, false, $this->id_base ) || is_active_widget( false, false, 'monster' ) || is_customize_preview() ) {
85 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
86 }
87 }
88
89 /**
90 * Enqueue scripts.
91 */
92 public function enqueue_scripts() {
93 wp_enqueue_script( 'jetpack-facebook-embed' );
94 wp_enqueue_style(
95 'jetpack_facebook_likebox',
96 plugins_url( 'facebook-likebox/style.css', __FILE__ ),
97 array(),
98 JETPACK__VERSION
99 );
100 // Inline styles. @see wp_maybe_inline_styles()
101 wp_style_add_data( 'jetpack_facebook_likebox', 'path', plugin_dir_path( __FILE__ ) . 'facebook-likebox/style.css' );
102 }
103
104 /**
105 * Display the widget.
106 *
107 * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget.
108 * @param array $instance The settings for the particular instance of the widget.
109 */
110 public function widget( $args, $instance ) {
111 $before_widget = isset( $args['before_widget'] ) ? $args['before_widget'] : '';
112 $before_title = isset( $args['before_title'] ) ? $args['before_title'] : '';
113 $after_title = isset( $args['after_title'] ) ? $args['after_title'] : '';
114 $after_widget = isset( $args['after_widget'] ) ? $args['after_widget'] : '';
115 $like_args = $this->get_default_args();
116
117 if ( isset( $instance['like_args'] ) ) {
118 $like_args = $this->normalize_facebook_args( $instance['like_args'] );
119 }
120
121 if ( empty( $like_args['href'] ) || ! $this->is_valid_facebook_url( $like_args['href'] ) ) {
122 if ( current_user_can( 'edit_theme_options' ) ) {
123 echo $before_widget; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
124
125 $error_link = wp_kses(
126 sprintf(
127 /* translators: %s: link to widgets administration screen. */
128 __( 'It looks like your Facebook URL is incorrectly configured. Please check it in your <a href="%1$s">widget settings</a>.', 'jetpack' ),
129 esc_url( admin_url( 'widgets.php' ) )
130 ),
131 array( 'a' => array( 'href' => array() ) )
132 );
133 printf(
134 '<p>%s</p>',
135 $error_link // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
136 );
137
138 echo $after_widget; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
139 }
140 echo '<!-- Invalid Facebook Page URL -->';
141 return;
142 }
143
144 /** This filter is documented in core/src/wp-includes/default-widgets.php */
145 $title = apply_filters( 'widget_title', $instance['title'] );
146 $page_url = set_url_scheme( $like_args['href'], 'https' );
147
148 $like_args['show_faces'] = (bool) $like_args['show_faces'] ? 'true' : 'false';
149 $like_args['stream'] = (bool) $like_args['stream'] ? 'timeline' : 'false';
150 $like_args['cover'] = (bool) $like_args['cover'] ? 'false' : 'true';
151 $like_args['small_header'] = (bool) $like_args['small_header'] ? 'true' : 'false';
152
153 /**
154 * Filter Facebook Likebox's widget call to action button
155 *
156 * @module widgets
157 *
158 * @since 8.4.0
159 *
160 * @param bool True value hides the call to action button
161 */
162 $hide_cta = apply_filters( 'jetpack_facebook_likebox_hide_cta', false );
163
164 echo $before_widget; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
165
166 if ( ! empty( $title ) ) :
167 echo $before_title; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
168
169 $likebox_widget_title = '<a href="' . esc_url( $page_url ) . '">' . $title . '</a>';
170 /**
171 * Filter Facebook Likebox's widget title.
172 *
173 * @module widgets
174 *
175 * @since 3.3.0
176 *
177 * @param string $likebox_widget_title Likebox Widget title (including a link to the Page URL).
178 * @param string $title Widget title as set in the widget settings.
179 * @param string $page_url Facebook Page URL.
180 */
181 $likebox_widget_title = apply_filters( 'jetpack_facebook_likebox_title', $likebox_widget_title, $title, $page_url );
182
183 echo wp_kses(
184 $likebox_widget_title,
185 array( 'a' => array( 'href' => array() ) )
186 );
187
188 echo $after_title; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
189 endif;
190
191 ?>
192 <div id="fb-root"></div>
193 <div class="fb-page" data-href="<?php echo esc_url( $page_url ); ?>" data-width="<?php echo (int) $like_args['width']; ?>" data-height="<?php echo (int) $like_args['height']; ?>" data-hide-cover="<?php echo esc_attr( $like_args['cover'] ); ?>" data-show-facepile="<?php echo esc_attr( $like_args['show_faces'] ); ?>" data-tabs="<?php echo esc_attr( $like_args['stream'] ); ?>" data-hide-cta="<?php echo esc_attr( $hide_cta ? 'true' : 'false' ); ?>" data-small-header="<?php echo esc_attr( $like_args['small_header'] ); ?>">
194 <div class="fb-xfbml-parse-ignore"><blockquote cite="<?php echo esc_url( $page_url ); ?>"><a href="<?php echo esc_url( $page_url ); ?>"><?php echo esc_html( $title ); ?></a></blockquote></div>
195 </div>
196 <?php
197 wp_enqueue_script( 'jetpack-facebook-embed' );
198
199 echo $after_widget; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
200
201 /** This action is documented in modules/widgets/gravatar-profile.php */
202 do_action( 'jetpack_stats_extra', 'widget_view', 'facebook-likebox' );
203 }
204
205 /**
206 * Update widget.
207 *
208 * @see WP_Widget::update()
209 *
210 * @param array $new_instance New widget instance data.
211 * @param array $old_instance Old widget instance data.
212 */
213 public function update( $new_instance, $old_instance ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
214 $instance = array();
215
216 $instance['title'] = trim( wp_strip_all_tags( stripslashes( $new_instance['title'] ) ) );
217
218 // Set up widget values.
219 $instance['like_args'] = array(
220 'href' => trim( wp_strip_all_tags( stripslashes( $new_instance['href'] ) ) ),
221 'width' => (int) $new_instance['width'],
222 'height' => (int) $new_instance['height'],
223 'show_faces' => isset( $new_instance['show_faces'] ),
224 'stream' => isset( $new_instance['stream'] ),
225 'cover' => isset( $new_instance['cover'] ),
226 'small_header' => isset( $new_instance['small_header'] ),
227 );
228
229 $instance['like_args'] = $this->normalize_facebook_args( $instance['like_args'] );
230
231 // Include the new instance's args in the array's top level to support updating from the Widgets page.
232 $instance = array_merge( $instance, array_intersect_key( $instance['like_args'], $new_instance ) );
233
234 return $instance;
235 }
236
237 /**
238 * Outputs the widget settings form.
239 *
240 * @param array $instance Current settings.
241 */
242 public function form( $instance ) {
243 $instance = wp_parse_args(
244 (array) $instance,
245 array(
246 'title' => '',
247 'like_args' => $this->get_default_args(),
248 )
249 );
250 $like_args = $this->normalize_facebook_args( $instance['like_args'] );
251 ?>
252
253 <p>
254 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>">
255 <?php esc_html_e( 'Title', 'jetpack' ); ?>
256 <input type="text" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>" class="widefat" />
257 </label>
258 </p>
259
260 <p>
261 <label for="<?php echo esc_attr( $this->get_field_id( 'href' ) ); ?>">
262 <?php esc_html_e( 'Facebook Page URL', 'jetpack' ); ?>
263 <input type="text" name="<?php echo esc_attr( $this->get_field_name( 'href' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'href' ) ); ?>" value="<?php echo esc_url( $like_args['href'] ); ?>" class="widefat" />
264 <br />
265 <small><?php esc_html_e( 'The widget only works with Facebook Pages.', 'jetpack' ); ?></small>
266 </label>
267 </p>
268
269 <p>
270 <label for="<?php echo esc_attr( $this->get_field_id( 'width' ) ); ?>">
271 <?php esc_html_e( 'Width in pixels', 'jetpack' ); ?>
272 <input type="number" class="smalltext" min="<?php echo esc_attr( $this->min_width ); ?>" max="<?php echo esc_attr( $this->max_width ); ?>" maxlength="3" name="<?php echo esc_attr( $this->get_field_name( 'width' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'width' ) ); ?>" value="<?php echo esc_attr( $like_args['width'] ); ?>" style="text-align: center;" />
273 <small>
274 <?php
275 echo esc_html(
276 sprintf(
277 /* translators: %s is the minimum pixel width */
278 __( 'Minimum: %s', 'jetpack' ),
279 $this->min_width
280 )
281 );
282 echo ' / ';
283 echo esc_html(
284 sprintf(
285 /* translators: %s is the maximum pixel width */
286 __( 'Maximum: %s', 'jetpack' ),
287 $this->max_width
288 )
289 );
290 ?>
291 </small>
292 </label>
293 </p>
294
295 <p>
296 <label for="<?php echo esc_attr( $this->get_field_id( 'height' ) ); ?>">
297 <?php esc_html_e( 'Height in pixels', 'jetpack' ); ?>
298 <input type="number" class="smalltext" min="<?php echo esc_attr( $this->min_height ); ?>" max="<?php echo esc_attr( $this->max_height ); ?>" maxlength="3" name="<?php echo esc_attr( $this->get_field_name( 'height' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'height' ) ); ?>" value="<?php echo esc_attr( $like_args['height'] ); ?>" style="text-align: center;" />
299 <small>
300 <?php
301 echo esc_html(
302 sprintf(
303 /* translators: %s is the minimum pixel height */
304 __( 'Minimum: %s', 'jetpack' ),
305 $this->min_height
306 )
307 );
308 echo ' / ';
309 echo esc_html(
310 sprintf(
311 /* translators: %s is the maximum pixel height */
312 __( 'Maximum: %s', 'jetpack' ),
313 $this->max_height
314 )
315 );
316 ?>
317 </small>
318 </label>
319 </p>
320
321 <p>
322 <label for="<?php echo esc_attr( $this->get_field_id( 'show_faces' ) ); ?>">
323 <input type="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'show_faces' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'show_faces' ) ); ?>" <?php checked( $like_args['show_faces'] ); ?> />
324 <?php esc_html_e( 'Show Faces', 'jetpack' ); ?>
325 <br />
326 <small><?php esc_html_e( 'Show profile photos in the plugin.', 'jetpack' ); ?></small>
327 </label>
328 </p>
329
330 <p>
331 <label for="<?php echo esc_attr( $this->get_field_id( 'stream' ) ); ?>">
332 <input type="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'stream' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'stream' ) ); ?>" <?php checked( $like_args['stream'] ); ?> />
333 <?php esc_html_e( 'Show Timeline', 'jetpack' ); ?>
334 <br />
335 <small><?php esc_html_e( 'Show Page Posts.', 'jetpack' ); ?></small>
336 </label>
337 </p>
338
339 <p>
340 <label for="<?php echo esc_attr( $this->get_field_id( 'cover' ) ); ?>">
341 <input type="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'cover' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'cover' ) ); ?>" <?php checked( $like_args['cover'] ); ?> />
342 <?php esc_html_e( 'Show Cover Photo', 'jetpack' ); ?>
343 <br />
344 </label>
345 </p>
346
347 <p>
348 <label for="<?php echo esc_attr( $this->get_field_id( 'small_header' ) ); ?>">
349 <input type="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'small_header' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'small_header' ) ); ?>" <?php checked( $like_args['small_header'] ); ?> />
350 <?php esc_html_e( 'Use Small Header', 'jetpack' ); ?>
351 <br />
352 </label>
353 </p>
354
355 <?php
356 }
357
358 /**
359 * Facebook Likebox default options.
360 */
361 public function get_default_args() {
362 $defaults = array(
363 'href' => '',
364 'width' => $this->default_width,
365 'height' => $this->default_height,
366 'show_faces' => 'true',
367 'stream' => '',
368 'cover' => 'true',
369 'small_header' => '',
370 );
371
372 /**
373 * Filter Facebook Likebox default options.
374 *
375 * @module widgets
376 *
377 * @since 1.3.1
378 *
379 * @param array $defaults Array of default options.
380 */
381 return apply_filters( 'jetpack_facebook_likebox_defaults', $defaults );
382 }
383
384 /**
385 * Normalize the Facebook Likebox options.
386 *
387 * @param array $args Array of arguments.
388 */
389 public function normalize_facebook_args( $args ) {
390 $args = wp_parse_args( (array) $args, $this->get_default_args() );
391
392 // Validate the Facebook Page URL.
393 if ( $this->is_valid_facebook_url( $args['href'] ) ) {
394 $temp = explode( '?', $args['href'] );
395 $args['href'] = str_replace( array( 'http://facebook.com', 'https://facebook.com' ), array( 'http://www.facebook.com', 'https://www.facebook.com' ), $temp[0] );
396 } else {
397 $args['href'] = '';
398 }
399
400 $args['width'] = $this->normalize_int_value( (int) $args['width'], $this->max_width, $this->min_width );
401 $args['height'] = $this->normalize_int_value( (int) $args['height'], $this->max_height, $this->min_height );
402 $args['show_faces'] = (bool) $args['show_faces'];
403 $args['stream'] = (bool) $args['stream'];
404 $args['cover'] = (bool) $args['cover'];
405 $args['small_header'] = (bool) $args['small_header'];
406
407 // The height used to be dependent on other widget settings
408 // If the user changes those settings but doesn't customize the height,
409 // let's intelligently assign a new height.
410 if ( in_array( $args['height'], array( 580, 110, 432 ), true ) ) {
411 if ( $args['show_faces'] && $args['stream'] ) {
412 $args['height'] = 580;
413 } elseif ( ! $args['show_faces'] && ! $args['stream'] ) {
414 $args['height'] = 130;
415 } else {
416 $args['height'] = 432;
417 }
418 }
419
420 return $args;
421 }
422
423 /**
424 * Check if URL is a valid Facebook Page URL.
425 *
426 * @param string $url URL to check.
427 */
428 public function is_valid_facebook_url( $url ) {
429 return str_contains( $url, 'facebook.com' );
430 }
431
432 /**
433 * Normalize an integer value within a given range.
434 *
435 * @param int $value Value to normalize.
436 * @param int $max Maximum value.
437 * @param int $min Minimum value.
438 *
439 * @return int Normalized value.
440 */
441 public function normalize_int_value( $value, $max = 0, $min = 0 ) {
442 $value = (int) $value;
443
444 if ( $value > $max ) {
445 $value = $max;
446 } elseif ( $value < $min ) {
447 $value = $min;
448 }
449
450 return (int) $value;
451 }
452 }
453