Repository navigation
Expose conditional logic hooks and retain older Pro compatibility #3608
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
Draft
Crabcyborg
wants to merge
10
commits into
master
Choose a base branch
from
feat/lookup-dynamic-sort
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+396
−297
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
220b6e5
feat(builder): refresh source sort fields
Crabcyborg 8e0499f
Merge remote-tracking branch 'origin/master' into HEAD
Crabcyborg dca981d
Integrate current master and rebuild page-specific admin scripts
Crabcyborg 6a8d5ee
Merge master into feat/lookup-dynamic-sort
Crabcyborg ff79346
Merge remote-tracking branch 'origin/master' into feat/lookup-dynamic…
Crabcyborg 9155fa0
Merge origin/master into feat/lookup-dynamic-sort
Crabcyborg acb84a7
Merge remote-tracking branch 'origin/master' into feat/lookup-dynamic…
Crabcyborg df9f8a8
Guard Order by refresh and reset it for form sources
Crabcyborg e3b050f
Expose builder conditional logic and source field hooks
Crabcyborg 2aa9167
Delegate rule comparisons and editor behavior with legacy fallbacks
Crabcyborg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| <?php | ||
|
|
||
| if ( ! defined( 'ABSPATH' ) ) { | ||
| die( 'You are not allowed to call this page directly.' ); | ||
| } | ||
|
|
||
| /** | ||
| * Compatibility for callers of the field comparison API when Pro does not provide it. | ||
| */ | ||
| class FrmLegacyConditionalLogicHelper { | ||
|
|
||
| /** | ||
| * @param array|string $observed_value | ||
| * @param string $cond | ||
| * @param array|string $hide_opt | ||
| * | ||
| * @return bool | ||
| */ | ||
| public static function value_meets_condition( $observed_value, $cond, $hide_opt ) { | ||
| $hide_opt = self::get_value_for_comparison( $hide_opt ); | ||
| $observed_value = self::get_value_for_comparison( $observed_value ); | ||
|
|
||
| if ( is_array( $observed_value ) ) { | ||
| return self::array_value_condition( $observed_value, $cond, $hide_opt ); | ||
| } | ||
|
|
||
| $m = false; | ||
|
|
||
| if ( $cond === '==' ) { | ||
| $m = $observed_value == $hide_opt; // phpcs:ignore Universal.Operators.StrictComparisons | ||
| } elseif ( $cond === '!=' ) { | ||
| $m = $observed_value != $hide_opt; // phpcs:ignore Universal.Operators.StrictComparisons | ||
| } elseif ( $cond === '>' ) { | ||
| $m = $observed_value > $hide_opt; | ||
| } elseif ( $cond === '>=' ) { | ||
| $m = $observed_value >= $hide_opt; | ||
| } elseif ( $cond === '<' ) { | ||
| $m = $observed_value < $hide_opt; | ||
| } elseif ( $cond === '<=' ) { | ||
| $m = $observed_value <= $hide_opt; | ||
| } elseif ( $cond === 'LIKE' || $cond === 'not LIKE' ) { | ||
| $m = stripos( $observed_value, $hide_opt ); | ||
| $m = $cond === 'not LIKE' ? $m === false : $m !== false; | ||
| } elseif ( $cond === '%LIKE' ) { | ||
| // Ends with | ||
| $length = strlen( $hide_opt ); | ||
| $substr = substr( $observed_value, strlen( $observed_value ) - $length ); | ||
| $m = 0 === strcasecmp( $substr, $hide_opt ); | ||
| } elseif ( 'LIKE%' === $cond ) { | ||
| // Starts with | ||
| $length = strlen( $hide_opt ); | ||
| $substr = substr( $observed_value, 0, $length ); | ||
| $m = 0 === strcasecmp( $substr, $hide_opt ); | ||
| }//end if | ||
|
|
||
| return $m; | ||
| } | ||
|
|
||
| /** | ||
| * Trim and sanitize the values | ||
| * | ||
| * @since 2.05 | ||
| * | ||
| * @param array|string $value | ||
| * | ||
| * @return array|string | ||
| */ | ||
| private static function get_value_for_comparison( $value ) { | ||
| // Remove white space from hide_opt | ||
| if ( ! is_array( $value ) ) { | ||
| $value = trim( $value ); | ||
| } | ||
|
|
||
| FrmAppHelper::sanitize_value( 'wp_kses_post', $value ); | ||
|
|
||
| return $value; | ||
| } | ||
|
|
||
| /** | ||
| * @param array $observed_value | ||
| * @param string $cond | ||
| * @param array|string $hide_opt | ||
| * | ||
| * @return bool | ||
| */ | ||
| public static function array_value_condition( $observed_value, $cond, $hide_opt ) { | ||
| $m = false; | ||
|
|
||
| if ( $cond === '==' ) { | ||
| if ( is_array( $hide_opt ) ) { | ||
| $m = array_intersect( $hide_opt, $observed_value ); | ||
| $m = $m !== array(); | ||
| } else { | ||
| // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict | ||
| $m = in_array( $hide_opt, $observed_value ); | ||
| } | ||
| } elseif ( $cond === '!=' ) { | ||
| // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict | ||
| $m = ! in_array( $hide_opt, $observed_value ); | ||
| } elseif ( $cond === '>' ) { | ||
| $m = min( $observed_value ) > $hide_opt; | ||
| } elseif ( $cond === '<' ) { | ||
| $m = max( $observed_value ) < $hide_opt; | ||
| } elseif ( $cond === 'LIKE' || $cond === 'not LIKE' ) { | ||
| foreach ( $observed_value as $ob ) { | ||
| $m = strpos( $ob, $hide_opt ); | ||
|
|
||
| if ( $m !== false ) { | ||
| $m = true; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if ( $cond === 'not LIKE' ) { | ||
| $m = $m === false; | ||
| } | ||
| } elseif ( $cond === '%LIKE' ) { | ||
| // Ends with | ||
| foreach ( $observed_value as $ob ) { | ||
| if ( $hide_opt === substr( $ob, strlen( $ob ) - strlen( $hide_opt ) ) ) { | ||
| $m = true; | ||
| break; | ||
| } | ||
| } | ||
| } elseif ( $cond === 'LIKE%' ) { | ||
| // Starts with | ||
| foreach ( $observed_value as $ob ) { | ||
| if ( str_starts_with( $ob, $hide_opt ) ) { | ||
| $m = true; | ||
| break; | ||
| } | ||
| } | ||
| }//end if | ||
|
|
||
| return $m; | ||
| } | ||
| } |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Writing functions within loops tends to result in errors due to the way the function creates a closure around the loop. For example: