Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Facebook widget: hide-cta and small-header #13744

Merged
merged 8 commits into from
Mar 17, 2020
85 changes: 54 additions & 31 deletions modules/widgets/facebook-likebox.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,21 @@ function widget( $args, $instance ) {
$title = apply_filters( 'widget_title', $instance['title'] );
$page_url = set_url_scheme( $like_args['href'], 'https' );

$like_args['show_faces'] = (bool) $like_args['show_faces'] ? 'true' : 'false';
$like_args['stream'] = (bool) $like_args['stream'] ? 'timeline' : 'false';
$like_args['cover'] = (bool) $like_args['cover'] ? 'false' : 'true';
$like_args['show_faces'] = (bool) $like_args['show_faces'] ? 'true' : 'false';
$like_args['stream'] = (bool) $like_args['stream'] ? 'timeline' : 'false';
$like_args['cover'] = (bool) $like_args['cover'] ? 'false' : 'true';
$like_args['small_header'] = (bool) $like_args['small_header'] ? 'true' : 'false';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the current default value for this header? If I update Jetpack, will my header change unless I go to the widget options and toggle this new option?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed this by adding a value of true to small_header to get_default_args function. I think that's what you wanted here but let me know if I'm wrong 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should default to false, since that's the default value in the Page Plugin. The idea is for the widget to look the same when folks will update Jetpack, so the large header has to stay until you decide to have a smaller header instead.


/**
* Filter Facebook Likebox's widget call to action button
*
* @module widgets
*
* @since 8.4.0
*
* @param bool True value hides the call to action button
*/
$hide_cta = apply_filters( 'jetpack_facebook_likebox_hide_cta', false );

echo $before_widget;

Expand All @@ -105,7 +117,7 @@ function widget( $args, $instance ) {

?>
<div id="fb-root"></div>
<div class="fb-page" data-href="<?php echo esc_url( $page_url ); ?>" data-width="<?php echo intval( $like_args['width'] ); ?>" data-height="<?php echo intval( $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'] ); ?>">
<div class="fb-page" data-href="<?php echo esc_url( $page_url ); ?>" data-width="<?php echo intval( $like_args['width'] ); ?>" data-height="<?php echo intval( $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'] ); ?>">
<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>
</div>
<?php
Expand All @@ -126,12 +138,13 @@ function update( $new_instance, $old_instance ) {

// Set up widget values
$instance['like_args'] = array(
'href' => trim( strip_tags( stripslashes( $new_instance['href'] ) ) ),
'width' => (int) $new_instance['width'],
'height' => (int) $new_instance['height'],
'show_faces' => isset( $new_instance['show_faces'] ),
'stream' => isset( $new_instance['stream'] ),
'cover' => isset( $new_instance['cover'] ),
'href' => trim( strip_tags( stripslashes( $new_instance['href'] ) ) ),
'width' => (int) $new_instance['width'],
'height' => (int) $new_instance['height'],
'show_faces' => isset( $new_instance['show_faces'] ),
'stream' => isset( $new_instance['stream'] ),
'cover' => isset( $new_instance['cover'] ),
'small_header' => isset( $new_instance['small_header'] ),
);

$instance['like_args'] = $this->normalize_facebook_args( $instance['like_args'] );
Expand All @@ -151,31 +164,31 @@ function form( $instance ) {

<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>">
<?php _e( 'Title', 'jetpack' ); ?>
<?php esc_html_e( 'Title', 'jetpack' ); ?>
<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" />
</label>
</p>

<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'href' ) ); ?>">
<?php _e( 'Facebook Page URL', 'jetpack' ); ?>
<?php esc_html_e( 'Facebook Page URL', 'jetpack' ); ?>
<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" />
<br />
<small><?php _e( 'The widget only works with Facebook Pages.', 'jetpack' ); ?></small>
<small><?php esc_html_e( 'The widget only works with Facebook Pages.', 'jetpack' ); ?></small>
</label>
</p>

<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'width' ) ); ?>">
<?php _e( 'Width in pixels', 'jetpack' ); ?>
<?php esc_html_e( 'Width in pixels', 'jetpack' ); ?>
<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;" />
<small><?php echo sprintf( __( 'Minimum: %s', 'jetpack' ), $this->min_width ); ?> / <?php echo sprintf( __( 'Maximum: %s', 'jetpack' ), $this->max_width ); ?></small>
</label>
</p>

<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'height' ) ); ?>">
<?php _e( 'Height in pixels', 'jetpack' ); ?>
<?php esc_html_e( 'Height in pixels', 'jetpack' ); ?>
<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;" />
<small><?php echo sprintf( __( 'Minimum: %s', 'jetpack' ), $this->min_height ); ?> / <?php echo sprintf( __( 'Maximum: %s', 'jetpack' ), $this->max_height ); ?></small>
</label>
Expand All @@ -184,25 +197,33 @@ function form( $instance ) {
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'show_faces' ) ); ?>">
<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'] ); ?> />
<?php _e( 'Show Faces', 'jetpack' ); ?>
<?php esc_html_e( 'Show Faces', 'jetpack' ); ?>
<br />
<small><?php _e( 'Show profile photos in the plugin.', 'jetpack' ); ?></small>
<small><?php esc_html_e( 'Show profile photos in the plugin.', 'jetpack' ); ?></small>
</label>
</p>

<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'stream' ) ); ?>">
<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'] ); ?> />
<?php _e( 'Show Timeline', 'jetpack' ); ?>
<?php esc_html_e( 'Show Timeline', 'jetpack' ); ?>
<br />
<small><?php _e( 'Show Page Posts.', 'jetpack' ); ?></small>
<small><?php esc_html_e( 'Show Page Posts.', 'jetpack' ); ?></small>
</label>
</p>

<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'cover' ) ); ?>">
<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'] ); ?> />
<?php _e( 'Show Cover Photo', 'jetpack' ); ?>
<?php esc_html_e( 'Show Cover Photo', 'jetpack' ); ?>
<br />
</label>
</p>

<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'small_header' ) ); ?>">
<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'] ); ?> />
<?php esc_html_e( 'Use Small Header', 'jetpack' ); ?>
<br />
</label>
</p>
Expand All @@ -212,12 +233,13 @@ function form( $instance ) {

function get_default_args() {
$defaults = array(
'href' => '',
'width' => $this->default_width,
'height' => $this->default_height,
'show_faces' => 'true',
'stream' => '',
'cover' => 'true',
'href' => '',
'width' => $this->default_width,
'height' => $this->default_height,
'show_faces' => 'true',
'stream' => '',
'cover' => 'true',
'small_header' => '',
);

/**
Expand All @@ -243,11 +265,12 @@ function normalize_facebook_args( $args ) {
$args['href'] = '';
}

$args['width'] = $this->normalize_int_value( (int) $args['width'], $this->default_width, $this->max_width, $this->min_width );
$args['height'] = $this->normalize_int_value( (int) $args['height'], $this->default_height, $this->max_height, $this->min_height );
$args['show_faces'] = (bool) $args['show_faces'];
$args['stream'] = (bool) $args['stream'];
$args['cover'] = (bool) $args['cover'];
$args['width'] = $this->normalize_int_value( (int) $args['width'], $this->default_width, $this->max_width, $this->min_width );
$args['height'] = $this->normalize_int_value( (int) $args['height'], $this->default_height, $this->max_height, $this->min_height );
$args['show_faces'] = (bool) $args['show_faces'];
$args['stream'] = (bool) $args['stream'];
$args['cover'] = (bool) $args['cover'];
$args['small_header'] = (bool) $args['small_header'];

// The height used to be dependent on other widget settings
// If the user changes those settings but doesn't customize the height,
Expand Down