Skip to content
This repository has been archived by the owner on Dec 2, 2022. It is now read-only.

Commit

Permalink
Fix #66
Browse files Browse the repository at this point in the history
  • Loading branch information
kprovance committed May 10, 2020
1 parent 4f02ecc commit 587216f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 11 deletions.
7 changes: 7 additions & 0 deletions ReduxCore/inc/classes/class-redux-helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
*/
class Redux_Helpers {

/**
* Resuable supported unit array.
*
* @var array
*/
public static $array_units = array( '', '%', 'in', 'cm', 'mm', 'em', 'rem', 'ex', 'pt', 'pc', 'px', 'vh', 'vw', 'vmin', 'vmax', 'ch' );

/**
* Retrieve section array from field ID.
*
Expand Down
13 changes: 7 additions & 6 deletions ReduxCore/inc/fields/dimensions/class-redux-dimensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,18 @@ public function render() {
* and reset them with default values to avoid errors.
*/

$arr_units = array( '', false, '%', 'in', 'cm', 'mm', 'em', 'ex', 'pt', 'pc', 'px', 'rem', 'vh', 'vw', 'vmin', 'vmax', 'ch' );
$arr_units = Redux_Helpers::$array_units;

$unit_check = $arr_units;
$unit_check[] = false;

// If units field has a value but is not an acceptable value, unset the variable.
if ( isset( $this->field['units'] ) && ! Redux_Helpers::array_in_array( $this->field['units'], $arr_units ) ) {
if ( isset( $this->field['units'] ) && ! Redux_Helpers::array_in_array( $this->field['units'], $unit_check ) ) {
unset( $this->field['units'] );
}

$arr_units = array( '', '%', 'in', 'cm', 'mm', 'em', 'ex', 'pt', 'pc', 'px', 'rem', 'vh', 'vw', 'vmin', 'vmax', 'ch' );

// If there is a default unit value but is not an accepted value, unset the variable.
if ( isset( $this->value['units'] ) && ! Redux_Helpers::array_in_array( $this->value['units'], $arr_units ) ) {
if ( isset( $this->value['units'] ) && ! Redux_Helpers::array_in_array( $this->value['units'], $unit_check ) ) {
unset( $this->value['units'] );
}

Expand Down Expand Up @@ -201,7 +202,7 @@ class="redux-dimensions redux-dimensions-units select ' . esc_attr( $this->field

// Extended units, show 'em all.
if ( $this->field['units_extended'] ) {
$test_units = array( 'px', 'em', 'rem', '%', 'in', 'cm', 'mm', 'ex', 'pt', 'pc', 'vh', 'vw', 'vmin', 'vmax', 'ch' );
$test_units = $arr_units;
} else {
$test_units = array( 'px', 'em', 'rem', '%' );
}
Expand Down
11 changes: 7 additions & 4 deletions ReduxCore/inc/fields/spacing/class-redux-spacing.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,18 @@ public function render() {
* and reset them with default values to avoid errors.
*/

$unit_arr = array( '', false, '%', 'in', 'cm', 'mm', 'em', 'rem', 'ex', 'pt', 'pc', 'px', 'vh', 'vw', 'vmin', 'vmax', 'ch' );
$unit_arr = Redux_Helpers::$array_units;

$unit_check = $unit_arr;
$unit_check[] = false;

// If units field has a value but is not an acceptable value, unset the variable.
if ( ! Redux_Helpers::array_in_array( $this->field['units'], $unit_arr ) ) {
if ( ! Redux_Helpers::array_in_array( $this->field['units'], $unit_check ) ) {
$this->field['units'] = 'px';
}

// If there is a default unit value but is not an accepted value, unset the variable.
if ( ! Redux_Helpers::array_in_array( $this->value['units'], $unit_arr ) ) {
if ( ! Redux_Helpers::array_in_array( $this->value['units'], $unit_check ) ) {
$this->value['units'] = 'px';
}

Expand Down Expand Up @@ -280,7 +283,7 @@ class="redux-spacing-left redux-spacing-input mini ' . esc_attr( $this->field['c
echo '<select data-placeholder="' . esc_html__( 'Units', 'redux-framework' ) . '" class="redux-spacing redux-spacing-units select ' . esc_attr( $this->field['class'] ) . '" original-title="' . esc_html__( 'Units', 'redux-framework' ) . '" id="' . esc_attr( $this->field['id'] ) . '_units"' . esc_attr( $select2_data ) . '>';

if ( $this->field['units_extended'] ) {
$test_units = array( 'px', 'em', 'rem', '%', 'in', 'cm', 'mm', 'ex', 'pt', 'pc' );
$test_units = $unit_arr;
} else {
$test_units = array( 'px', 'em', 'pt', 'rem', '%' );
}
Expand Down
25 changes: 24 additions & 1 deletion sample/sample-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,29 @@
'subsection' => true,
'fields' => array(
array(
'id' => 'section-tester',
'type' => 'section',
'title' => __('Section with Indent', 'redux'),
'indent' => true
),
array(
'id' => 'opt-test-info',
'type' => 'info',
'style' => 'info',
'desc' => __('An info field!', 'redux')
),
array(
'id' => 'opt-test-field',
'type' => 'switch',
'title' => __('A switch field', 'redux'),
'default' => true
),
array(
'id' => 'section-end',
'type' => 'section',
'indent' => false, // Indent all options below until the next 'section' option is set.
),
/* array(
'id' => 'section-start',
'type' => 'section',
'title' => esc_html__( 'Section Example', 'your-domain-here' ),
Expand All @@ -1262,7 +1285,7 @@
'id' => 'section-end',
'type' => 'section',
'indent' => false, // Indent all options below until the next 'section' option is set.
),
),*/
array(
'id' => 'section-info',
'type' => 'info',
Expand Down

0 comments on commit 587216f

Please sign in to comment.