Skip to content

Commit

Permalink
fixes #1825
Browse files Browse the repository at this point in the history
  • Loading branch information
aristath committed Mar 11, 2018
1 parent 05de942 commit 73e1dec
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 51 deletions.
63 changes: 35 additions & 28 deletions core/class-kirki-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,36 +382,43 @@ public static function get_dashicons() {
* @return boolean whether The comparison has succeded (true) or failed (false).
*/
public static function compare_values( $value1, $value2, $operator ) {
$return = false;
if ( '===' === $operator && $value1 === $value2 ) {
$return = true;
} elseif ( '!==' === $operator && $value1 !== $value2 ) {
$return = true;
// @codingStandardsIgnoreLine WordPress.PHP.StrictComparisons.LooseComparison
} elseif ( ( '!=' === $operator || 'not equal' === $operator ) && $value1 != $value2 ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
$return = true;
} elseif ( ( '>=' === $operator || 'greater or equal' === $operator || 'equal or greater' === $operator ) && $value2 >= $value1 ) {
$return = true;
} elseif ( ( '<=' === $operator || 'smaller or equal' === $operator || 'equal or smaller' === $operator ) && $value2 <= $value1 ) {
$return = true;
} elseif ( ( '>' === $operator || 'greater' === $operator ) && $value2 > $value1 ) {
$return = true;
} elseif ( ( '<' === $operator || 'smaller' === $operator ) && $value2 < $value1 ) {
$return = true;
} elseif ( 'contains' === $operator || 'in' === $operator ) {
if ( '===' === $operator ) {
return $value1 === $value2;
}
if ( '!==' === $operator ) {
return $value1 !== $value2;
}
if ( ( '!=' === $operator || 'not equal' === $operator ) ) {
return $value1 != $value2;
}
if ( ( '>=' === $operator || 'greater or equal' === $operator || 'equal or greater' === $operator ) ) {
return $value2 >= $value1;
}
if ( ( '<=' === $operator || 'smaller or equal' === $operator || 'equal or smaller' === $operator ) ) {
return $value2 <= $value1;
}
if ( ( '>' === $operator || 'greater' === $operator ) ) {
return $value2 > $value1;
}
if ( ( '<' === $operator || 'smaller' === $operator ) ) {
return $value2 < $value1;
}
if ( 'contains' === $operator || 'in' === $operator ) {
if ( is_array( $value1 ) && is_array( $value2 ) ){
foreach ( $value2 as $val ){
if ( in_array( $val, $value1 ) ) {
return true;
}
}
}
if ( is_array( $value1 ) && ! is_array( $value2 ) ) {
// @codingStandardsIgnoreLine
$return = ( in_array( $value2, $value1 ) );
} elseif ( is_array( $value2 ) && ! is_array( $value1 ) ) {
// @codingStandardsIgnoreLine
$return = ( in_array( $value1, $value2 ) );
} elseif ( false === strrpos( $value1, $value2 ) && false === strpos( $value2, $value1 ) ) {
$return = false;
return in_array( $value2, $value1 );
}
if ( is_array( $value2 ) && ! is_array( $value1 ) ) {
return in_array( $value1, $value2 );
}
} else {
// @codingStandardsIgnoreLine WordPress.PHP.StrictComparisons.LooseComparison
$return = ( $value1 == $value2 ) ? true : false; // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
return ( false === strrpos( $value1, $value2 ) && false === strpos( $value2, $value1 ) );
}
return (bool) $return;
return $value1 == $value2;
}
}
61 changes: 38 additions & 23 deletions modules/field-dependencies/field-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,48 +103,63 @@ var kirkiDependencies = {
result = null;

if ( '===' === operator ) {
result = value1 === value2;
} else if ( '==' === operator || '=' === operator || 'equals' === operator || 'equal' === operator ) {
result = value1 == value2; // jshint ignore:line
} else if ( '!==' === operator ) {
result = value1 !== value2;
} else if ( '!=' === operator || 'not equal' === operator ) {
result = value1 != value2; // jshint ignore:line
} else if ( '>=' === operator || 'greater or equal' === operator || 'equal or greater' === operator ) {
result = value2 >= value1;
} else if ( '<=' === operator || 'smaller or equal' === operator || 'equal or smaller' === operator ) {
result = value2 <= value1;
} else if ( '>' === operator || 'greater' === operator ) {
result = value2 > value1;
} else if ( '<' === operator || 'smaller' === operator ) {
result = value2 < value1;
} else if ( 'contains' === operator || 'in' === operator ) {
return value1 === value2;
}
if ( '==' === operator || '=' === operator || 'equals' === operator || 'equal' === operator ) {
return value1 == value2;
}
if ( '!==' === operator ) {
return value1 !== value2;
}
if ( '!=' === operator || 'not equal' === operator ) {
return value1 != value2;
}
if ( '>=' === operator || 'greater or equal' === operator || 'equal or greater' === operator ) {
return value2 >= value1;
}
if ( '<=' === operator || 'smaller or equal' === operator || 'equal or smaller' === operator ) {
return value2 <= value1;
}
if ( '>' === operator || 'greater' === operator ) {
return value2 > value1;
}
if ( '<' === operator || 'smaller' === operator ) {
return value2 < value1;
}
if ( 'contains' === operator || 'in' === operator ) {
if ( _.isArray( value1 ) && _.isArray( value2 ) ) {
_.each( value2, function( value ) {
if ( value1.includes( value ) ) {
found = true;
return false;
}
} );
return found;
}
if ( _.isArray( value2 ) ) {
_.each( value2, function( value ) {
if ( value == value1 ) { // jshint ignore:line
found = true;
}
} );
return found;
} else if ( _.isObject( value2 ) ) {
}
if ( _.isObject( value2 ) ) {
if ( ! _.isUndefined( value2[ value1 ] ) ) {
found = true;
}

_.each( value2, function( subValue ) {
if ( value1 === subValue ) {
found = true;
}
} );
return found;
} else if ( _.isString( value2 ) ) {
}
if ( _.isString( value2 ) ) {
return -1 < value1.indexOf( value2 );
}
}
if ( null === result ) {
return true;
}
return result;
return ( null === result ) ? true : result;
}
};

Expand Down

0 comments on commit 73e1dec

Please sign in to comment.