PluginProbe ʕ •ᴥ•ʔ
Jetpack – WP Security, Backup, Speed, & Growth / 14.7.1
Jetpack – WP Security, Backup, Speed, & Growth v14.7.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.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 1 year ago contact-info 5 years ago eu-cookie-law 1 year ago facebook-likebox 11 years ago flickr 2 years ago gallery 1 year ago goodreads 1 year ago google-translate 1 year ago image-widget 1 year ago instagram 1 year ago internet-defense-league 2 years ago milestone 1 year ago my-community 8 years ago simple-payments 1 year ago social-icons 1 year ago social-media-icons 1 year ago top-posts 1 year ago wordpress-post-widget 2 years ago authors.php 1 year ago blog-stats.php 1 year ago class-jetpack-eu-cookie-law-widget.php 1 year ago class-jetpack-instagram-widget.php 1 year ago contact-info.php 1 year ago customizer-controls.css 1 year ago customizer-utils.js 1 year ago facebook-likebox.php 1 year ago flickr.php 1 year ago gallery.php 1 year ago goodreads.php 1 year ago google-translate.php 1 year ago gravatar-profile.css 1 year ago gravatar-profile.php 1 year ago image-widget.php 1 year ago internet-defense-league.php 1 year ago mailchimp.php 1 year 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 1 year ago twitter-timeline.php 1 year ago upcoming-events.php 1 year ago wordpress-post-widget.php 1 year ago
facebook-likebox.php
454 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 * @return string|void
242 */
243 public function form( $instance ) {
244 $instance = wp_parse_args(
245 (array) $instance,
246 array(
247 'title' => '',
248 'like_args' => $this->get_default_args(),
249 )
250 );
251 $like_args = $this->normalize_facebook_args( $instance['like_args'] );
252 ?>
253
254 <p>
255 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>">
256 <?php esc_html_e( 'Title', 'jetpack' ); ?>
257 <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" />
258 </label>
259 </p>
260
261 <p>
262 <label for="<?php echo esc_attr( $this->get_field_id( 'href' ) ); ?>">
263 <?php esc_html_e( 'Facebook Page URL', 'jetpack' ); ?>
264 <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" />
265 <br />
266 <small><?php esc_html_e( 'The widget only works with Facebook Pages.', 'jetpack' ); ?></small>
267 </label>
268 </p>
269
270 <p>
271 <label for="<?php echo esc_attr( $this->get_field_id( 'width' ) ); ?>">
272 <?php esc_html_e( 'Width in pixels', 'jetpack' ); ?>
273 <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;" />
274 <small>
275 <?php
276 echo esc_html(
277 sprintf(
278 /* translators: %s is the minimum pixel width */
279 __( 'Minimum: %s', 'jetpack' ),
280 $this->min_width
281 )
282 );
283 echo ' / ';
284 echo esc_html(
285 sprintf(
286 /* translators: %s is the maximum pixel width */
287 __( 'Maximum: %s', 'jetpack' ),
288 $this->max_width
289 )
290 );
291 ?>
292 </small>
293 </label>
294 </p>
295
296 <p>
297 <label for="<?php echo esc_attr( $this->get_field_id( 'height' ) ); ?>">
298 <?php esc_html_e( 'Height in pixels', 'jetpack' ); ?>
299 <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;" />
300 <small>
301 <?php
302 echo esc_html(
303 sprintf(
304 /* translators: %s is the minimum pixel height */
305 __( 'Minimum: %s', 'jetpack' ),
306 $this->min_height
307 )
308 );
309 echo ' / ';
310 echo esc_html(
311 sprintf(
312 /* translators: %s is the maximum pixel height */
313 __( 'Maximum: %s', 'jetpack' ),
314 $this->max_height
315 )
316 );
317 ?>
318 </small>
319 </label>
320 </p>
321
322 <p>
323 <label for="<?php echo esc_attr( $this->get_field_id( 'show_faces' ) ); ?>">
324 <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'] ); ?> />
325 <?php esc_html_e( 'Show Faces', 'jetpack' ); ?>
326 <br />
327 <small><?php esc_html_e( 'Show profile photos in the plugin.', 'jetpack' ); ?></small>
328 </label>
329 </p>
330
331 <p>
332 <label for="<?php echo esc_attr( $this->get_field_id( 'stream' ) ); ?>">
333 <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'] ); ?> />
334 <?php esc_html_e( 'Show Timeline', 'jetpack' ); ?>
335 <br />
336 <small><?php esc_html_e( 'Show Page Posts.', 'jetpack' ); ?></small>
337 </label>
338 </p>
339
340 <p>
341 <label for="<?php echo esc_attr( $this->get_field_id( 'cover' ) ); ?>">
342 <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'] ); ?> />
343 <?php esc_html_e( 'Show Cover Photo', 'jetpack' ); ?>
344 <br />
345 </label>
346 </p>
347
348 <p>
349 <label for="<?php echo esc_attr( $this->get_field_id( 'small_header' ) ); ?>">
350 <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'] ); ?> />
351 <?php esc_html_e( 'Use Small Header', 'jetpack' ); ?>
352 <br />
353 </label>
354 </p>
355
356 <?php
357 }
358
359 /**
360 * Facebook Likebox default options.
361 */
362 public function get_default_args() {
363 $defaults = array(
364 'href' => '',
365 'width' => $this->default_width,
366 'height' => $this->default_height,
367 'show_faces' => 'true',
368 'stream' => '',
369 'cover' => 'true',
370 'small_header' => '',
371 );
372
373 /**
374 * Filter Facebook Likebox default options.
375 *
376 * @module widgets
377 *
378 * @since 1.3.1
379 *
380 * @param array $defaults Array of default options.
381 */
382 return apply_filters( 'jetpack_facebook_likebox_defaults', $defaults );
383 }
384
385 /**
386 * Normalize the Facebook Likebox options.
387 *
388 * @param array $args Array of arguments.
389 */
390 public function normalize_facebook_args( $args ) {
391 $args = wp_parse_args( (array) $args, $this->get_default_args() );
392
393 // Validate the Facebook Page URL.
394 if ( $this->is_valid_facebook_url( $args['href'] ) ) {
395 $temp = explode( '?', $args['href'] );
396 $args['href'] = str_replace( array( 'http://facebook.com', 'https://facebook.com' ), array( 'http://www.facebook.com', 'https://www.facebook.com' ), $temp[0] );
397 } else {
398 $args['href'] = '';
399 }
400
401 $args['width'] = $this->normalize_int_value( (int) $args['width'], $this->max_width, $this->min_width );
402 $args['height'] = $this->normalize_int_value( (int) $args['height'], $this->max_height, $this->min_height );
403 $args['show_faces'] = (bool) $args['show_faces'];
404 $args['stream'] = (bool) $args['stream'];
405 $args['cover'] = (bool) $args['cover'];
406 $args['small_header'] = (bool) $args['small_header'];
407
408 // The height used to be dependent on other widget settings
409 // If the user changes those settings but doesn't customize the height,
410 // let's intelligently assign a new height.
411 if ( in_array( $args['height'], array( 580, 110, 432 ), true ) ) {
412 if ( $args['show_faces'] && $args['stream'] ) {
413 $args['height'] = 580;
414 } elseif ( ! $args['show_faces'] && ! $args['stream'] ) {
415 $args['height'] = 130;
416 } else {
417 $args['height'] = 432;
418 }
419 }
420
421 return $args;
422 }
423
424 /**
425 * Check if URL is a valid Facebook Page URL.
426 *
427 * @param string $url URL to check.
428 */
429 public function is_valid_facebook_url( $url ) {
430 return str_contains( $url, 'facebook.com' );
431 }
432
433 /**
434 * Normalize an integer value within a given range.
435 *
436 * @param int $value Value to normalize.
437 * @param int $max Maximum value.
438 * @param int $min Minimum value.
439 *
440 * @return int Normalized value.
441 */
442 public function normalize_int_value( $value, $max = 0, $min = 0 ) {
443 $value = (int) $value;
444
445 if ( $value > $max ) {
446 $value = $max;
447 } elseif ( $value < $min ) {
448 $value = $min;
449 }
450
451 return (int) $value;
452 }
453 }
454