-
Notifications
You must be signed in to change notification settings - Fork 42
More form builder optimizations #3512
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f10ce50
Further optimize when CSS layout classes special HTML is initialized
Crabcyborg c7b6f9a
Defer radio button work
Crabcyborg 6d77a5c
Delay when field settings options are added
Crabcyborg 910b1a4
Update how the batch loading works
Crabcyborg 0eaada9
Update the e2e tests
Crabcyborg b1d2259
Merge branch 'master' into more_form_builder_optimzations
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
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,105 @@ | ||
| <?php | ||
|
|
||
| if ( ! defined( 'ABSPATH' ) ) { | ||
| die( 'You are not allowed to call this page directly.' ); | ||
| } | ||
|
|
||
| /** | ||
| * Shares repeated builder option lists while keeping saved selections in the form. | ||
| * | ||
| * @since x.x | ||
| */ | ||
| class FrmBuilderSelectHelper { | ||
|
|
||
| /** | ||
| * @var array<string,array> | ||
| */ | ||
| private static $templates = array(); | ||
|
|
||
| /** | ||
| * Render a select, deferring unselected options only when its registry can be delivered. | ||
| * | ||
| * @since x.x | ||
| * | ||
| * @param array $attributes Select attributes. | ||
| * @param array $options Option labels keyed by value, in display order. | ||
| * @param array<int|string>|string $selected Selected values. | ||
| * @param array $option_attributes Additional option attributes keyed by value. | ||
| * | ||
| * @return void | ||
| */ | ||
| public static function render( $attributes, $options, $selected, $option_attributes = array() ) { | ||
| $records = array(); | ||
|
|
||
| foreach ( $options as $value => $label ) { | ||
| $records[] = array( | ||
| 'value' => (string) $value, | ||
| 'label' => html_entity_decode( (string) $label, ENT_QUOTES, 'UTF-8' ), | ||
| 'attributes' => $option_attributes[ $value ] ?? array(), | ||
| ); | ||
| } | ||
|
|
||
| $selected = array_map( 'strval', (array) $selected ); | ||
|
|
||
| if ( ! isset( $attributes['multiple'] ) && ! array_intersect( $selected, array_keys( $options ) ) ) { | ||
| // Match the browser's default selection when the saved value is no longer available. | ||
| foreach ( $records as $record ) { | ||
| if ( ! isset( $record['attributes']['disabled'] ) ) { | ||
| $selected = array( $record['value'] ); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| $defer = wp_doing_ajax() | ||
| ? 'frm_load_field' === FrmAppHelper::get_post_param( 'action', '', 'sanitize_text_field' ) | ||
| : FrmAppHelper::is_form_builder_page( false ); | ||
|
|
||
| if ( $defer && $records ) { | ||
| $key = md5( wp_json_encode( $records ) ); | ||
| self::$templates[ $key ] = $records; | ||
| $attributes['data-frm-options'] = $key; | ||
| } | ||
|
|
||
| echo '<select'; | ||
| FrmAppHelper::array_to_html_params( $attributes, true ); | ||
| echo '>'; | ||
|
|
||
| foreach ( $records as $record ) { | ||
| $is_selected = in_array( $record['value'], $selected, true ); | ||
|
|
||
| if ( $defer && ! $is_selected ) { | ||
| continue; | ||
| } | ||
|
|
||
| $params = $record['attributes']; | ||
| $params['value'] = $record['value']; | ||
| FrmHtmlHelper::echo_dropdown_option( $options[ $record['value'] ], $is_selected, $params ); | ||
| } | ||
| echo '</select>'; | ||
| } | ||
|
|
||
| /** | ||
| * Get option lists collected during this request, including AJAX field batches. | ||
| * | ||
| * @since x.x | ||
| * | ||
| * @return array<string,array> | ||
| */ | ||
| public static function get_templates() { | ||
| return self::$templates; | ||
| } | ||
|
|
||
| /** | ||
| * Deliver the initial page's shared options alongside the builder script. | ||
| * | ||
| * @since x.x | ||
| * | ||
| * @return void | ||
| */ | ||
| public static function print_templates() { | ||
| if ( self::$templates ) { | ||
| wp_add_inline_script( 'formidable_admin', 'frm_admin_js.selectOptions = ' . wp_json_encode( self::$templates ) . ';', 'before' ); | ||
| } | ||
| } | ||
| } | ||
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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.
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.
Using
md5(),sha1()function is not recommended to generate secure passwords. Due to its fast nature to compute passwords too quickly, these functions can become really easy to crack a password using brute force attack.It is recommended to use PHP's password hashing function
password_hash()to create a secure password hash.