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

Social Network Buttons: Add dedicated icon/padding/margin fields #1161

Closed
116 changes: 62 additions & 54 deletions widgets/social-media-buttons/social-media-buttons.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function get_widget_form(){
$network_names[ $key ] = $value['label'];
}

$useable_multi_units = array( 'px', '%', 'em' );
return array(
'title' => array(
'type' => 'text',
Expand Down Expand Up @@ -113,36 +114,19 @@ function get_widget_form(){
'default' => true
),
'icon_size' => array(
'type' => 'select',
'type' => 'measurement',
'label' => __( 'Icon size', 'so-widgets-bundle' ),
'options' => array(
'1' => __( 'Normal', 'so-widgets-bundle' ),
'1.33' => __( 'Medium', 'so-widgets-bundle' ),
'1.66' => __( 'Large', 'so-widgets-bundle' ),
'2' => __( 'Extra large', 'so-widgets-bundle' )
)
'default' => '1em',
),
'rounding' => array(
'type' => 'select',
'type' => 'measurement',
'label' => __( 'Rounding', 'so-widgets-bundle' ),
'default' => '0.25',
'options' => array(
'0' => __( 'None', 'so-widgets-bundle' ),
'0.25' => __( 'Slightly rounded', 'so-widgets-bundle' ),
'0.5' => __( 'Very rounded', 'so-widgets-bundle' ),
'1.5' => __( 'Completely rounded', 'so-widgets-bundle' ),
),
'default' => '0.25em',
),
'padding' => array(
'type' => 'select',
'type' => 'measurement',
'label' => __( 'Padding', 'so-widgets-bundle' ),
'default' => '1',
'options' => array(
'0.5' => __( 'Low', 'so-widgets-bundle' ),
'1' => __( 'Medium', 'so-widgets-bundle' ),
'1.4' => __( 'High', 'so-widgets-bundle' ),
'1.8' => __( 'Very high', 'so-widgets-bundle' ),
),
'default' => '1em',
),
'align' => array(
'type' => 'select',
Expand All @@ -166,18 +150,31 @@ function get_widget_form(){
'justify' => __( 'Justify', 'so-widgets-bundle' ),
),
),
'margin' => array(
'type' => 'select',
'label' => __( 'Margin', 'so-widgets-bundle' ),
'default' => '0.1',
'options' => array(
'0.1' => __( 'Low', 'so-widgets-bundle' ),
'0.2' => __( 'Medium', 'so-widgets-bundle' ),
'0.3' => __( 'High', 'so-widgets-bundle' ),
'0.4' => __( 'Very high', 'so-widgets-bundle' ),
'margin' => array(
'type' => 'multi-measurement',
'autofill' => true,
'label' => __( 'Margin', 'so-widgets-bundle' ),
'default' => '0.1em 0.1em 0.1em 0em',
'measurements' => array(
'top' => array(
'label' => __( 'Margin Top', 'so-widgets-bundle' ),
'units' => $useable_multi_units,
),
'right' => array(
'label' => __( 'Margin Right', 'so-widgets-bundle' ),
'units' => $useable_multi_units,
),
'bottom' => array(
'label' => __( 'Margin Bottom', 'so-widgets-bundle' ),
'units' => $useable_multi_units,
),
'left' => array(
'label' => __( 'Margin Left', 'so-widgets-bundle' ),
'units' => $useable_multi_units,
),
),
)
)
),
),
),
);
}
Expand All @@ -196,6 +193,31 @@ function modify_instance( $instance ) {
$instance['networks'][$name] = $network;
}
}

if ( ! empty( $instance['design'] ) && ! isset( $instance['design']['icon_size_unit'] ) ) {
$instance['design']['icon_size'] = $instance['design']['icon_size'] . 'em';
$instance['design']['icon_size_unit'] = 'em';
$instance['design']['rounding'] = $instance['design']['rounding'] . 'em';
$instance['design']['rounding_unit'] = 'em';
$instance['design']['padding'] = $instance['design']['padding'] . 'em';
$instance['design']['padding_unit'] = 'em';

// The margin value was previously changed based on the align setting.
$top = $right = $bottom = $left = $instance['design']['margin'] . 'em';
switch ( $instance['design']['align'] ) {
case 'left':
$left = '0em';
Misplon marked this conversation as resolved.
Show resolved Hide resolved
break;
case 'right':
$right = '0em';
break;
case 'center':
$left = $right = ( $instance['design']['margin'] * 0.5 ) . 'em';
break;
}
$instance['design']['margin'] = "$top $right $bottom $left";
}

return $instance;
}

Expand Down Expand Up @@ -227,32 +249,18 @@ function get_style_name( $instance ) {
function get_less_variables( $instance ) {
if( empty( $instance ) ) return;

$design = $instance['design'];
$m = $design['margin'];
$top = $right = $bottom = $left = $m . 'em';
switch ( $design['align'] ) {
case 'left':
$left = '0';
break;
case 'right':
$right = '0';
break;
case 'center':
$left = $right = ( $m * 0.5 ) . 'em';
break;
}
$margin = $top . ' ' . $right . ' ' . $bottom . ' ' . $left;

// Get responsive breakpoint and make sure it's properly formatted
$breakpoint = $this->get_global_settings( 'responsive_breakpoint' );

$design = $instance['design'];
return array(
'icon_size' => $design['icon_size'] . 'em',
'rounding' => $design['rounding'] . 'em',
'padding' => $design['padding'] . 'em',
'icon_size' => $design['icon_size'],
'rounding' => $design['rounding'],
'padding' => $design['padding'],
'align' => $design['align'],
'mobile_align' => ! empty( $design['mobile_align'] ) ? $design['mobile_align'] : '',
'responsive_breakpoint' => ! empty( $breakpoint ) ? $breakpoint : '',
'margin' => $margin
'margin' => $design['margin'],
);
}

Expand Down