-
Notifications
You must be signed in to change notification settings - Fork 41
Testing mode #2443
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
Testing mode #2443
Changes from all commits
Commits
Show all changes
115 commits
Select commit
Hold shift + click to select a range
045aa4a
Testing mode (wip, first commit)
Crabcyborg 6f1e2e5
Add comments, use clip
Crabcyborg 9822012
Merge branch 'master' into testing_mode
Crabcyborg 9bae301
Set up scss for testing mode and move CSS from style tag to new scss …
Crabcyborg 6e5abba
Move the test mode scss file, use the toggle element, use the new styles
Crabcyborg 4feac3c
Drop weird js file
Crabcyborg 1c41084
Disable the toggle, update the name of the dropdown option
Crabcyborg 4dd07ba
Merge branch 'master' into testing_mode
Crabcyborg 9ab0a0f
Add more elements to test mode container (pagination, fill form butto…
Crabcyborg 2c23032
Some style fixes
Crabcyborg ad1d742
Change pagination from anchor tags to inputs
Crabcyborg fcbf37c
Disable test mode controls conditionally
Crabcyborg 8290d53
Move more code out of views, remove the validation changes
Crabcyborg 4fece62
Use helper function for options, fix wrong word used in comment
Crabcyborg 745e74c
Match design better
Crabcyborg ef3f7b0
Reflect the current selected test mode role
Crabcyborg 8c6a67f
Only check get param if enabled
Crabcyborg 34a4b84
Add id to fill button
Crabcyborg 3ae5a73
Add new actions for test mode, and add reset button to test mode cont…
Crabcyborg a02db73
Add logged out to role options
Crabcyborg db51478
Add the test mode container above an error message and add a hook for…
Crabcyborg 15caaf6
Only add filter when the check passes
Crabcyborg fa50288
Fix scss spacing, fix phpcs issues
Crabcyborg 4126414
Add spinner to autofill button, add AI to autofill button and add AI …
Crabcyborg 87251e8
Add show hidden fields toggle
Crabcyborg 70196c6
Merge branch 'master' into testing_mode
Crabcyborg fb70296
Use shorter fill button text
Crabcyborg 338c6ff
Use edit forms cap
Crabcyborg ffe6bf5
Add enabled form actions multi-select
Crabcyborg d63cd61
Add ID to the dropdown options
Crabcyborg aa15d44
phpcs fixes
Crabcyborg 43af616
Typo fix
Crabcyborg eaaef0b
Move dropdown script code
Crabcyborg 1f4c2ab
Clean up
Crabcyborg 23a1f04
Move style enqueue code
Crabcyborg 1ecb188
Move script to a script file and stop using jQuery
Crabcyborg a69d7e6
Clean up
Crabcyborg c2bea3a
Clean up
Crabcyborg 3b326e9
Disable the enabled form actions dropdown
Crabcyborg abb21e9
Fix a bootstrap multiselect dropdown conflict
Crabcyborg ff91f10
Add new pill to the preview dropdown and align it to the right
Crabcyborg 867c75b
Add upsell
Crabcyborg 5ef963c
Improve upsell logic
Crabcyborg 7ffe401
Separate logic
Crabcyborg e96e056
Use version 3 upsell
Crabcyborg f7e3052
Add comments
Crabcyborg 8312400
Add the install message
Crabcyborg 8557f93
Add suggestion to activate the AI add-on
Crabcyborg b7b93b5
Make sure that the editable roles function exists
Crabcyborg 966549a
Move more logic out of view and into smaller functions
Crabcyborg d8db265
Prevent showing hidden field from another page
Crabcyborg 1822ecc
Fix issues with the multiselect dropdown when submitting to another p…
Crabcyborg 6553800
Merge branch 'master' into testing_mode
Crabcyborg bd4b805
Also init multiselect on form complete
Crabcyborg e5ea649
Merge branch 'master' into testing_mode
Crabcyborg 01c9b27
Show a note and leave out the test mode container when using a conver…
Crabcyborg 32eb949
Merge branch 'master' into testing_mode
Crabcyborg 646c9ae
Merge branch 'master' into testing_mode
Crabcyborg 0d93af2
Merge branch 'master' into testing_mode
Crabcyborg 7aa2b16
Try to move upgrade message logic into a new modular file
Crabcyborg 3a76c88
Pull upgrade modal JS into new upgrade popup file
Crabcyborg 0191fb8
Work on adding the upgrade modal to the test mode container
Crabcyborg cc415c4
Merge branch 'master' into testing_mode
Crabcyborg 3809e64
Disable chunk format
Crabcyborg df70deb
Working on AI activation pop-up
Crabcyborg 7e623bc
Continue working on getting an upsell pop-up into test mode
Crabcyborg 4cfd9e9
Start pulling addon state into a new script file
Crabcyborg 7064962
Fix some bugs
Crabcyborg c7e46ff
Add some comments
Crabcyborg 2912ac3
Add todo comment
Crabcyborg bb0dd4f
Stop hard coding one click
Crabcyborg fd1264e
Align declarations
Crabcyborg bd2909d
Update styles, remove some alerts
Crabcyborg bc2d395
Add button to install Test Mode add-on
Crabcyborg 14cb555
Tweak the spacing of the testing mode controls
Crabcyborg a035173
Add some responsive styling
Crabcyborg 9fdfca9
Merge branch 'master' into testing_mode
Crabcyborg 4ebec6f
Use ajax url global
Crabcyborg ede7e06
Update js
Crabcyborg 1b28177
Change where the new pill is shown in preview dropdown
Crabcyborg 4dc1570
Ignore testing mode compiled file
Crabcyborg 09b608a
Use const
Crabcyborg 0163755
Fix typo order (phpcs fixer)
Crabcyborg 9a78053
Fix some phpcs issues
Crabcyborg 1a293b1
Fix addonError function
Crabcyborg 478a7f6
Add missing save and reload settings
Crabcyborg 8e73946
Use const
Crabcyborg d91e6cb
Fix missing function reference
Crabcyborg 37508f0
Tweak spacing
Crabcyborg 4981722
Change how form key is determined
Crabcyborg 19f052d
Add rounding to dropdowns and use a custom carat image
Crabcyborg a4f9536
Update dropdown font size
Crabcyborg 8f71987
Apply more styles for the dropdown to prevent style conflicts
Crabcyborg 41da71b
Also set font weight
Crabcyborg c5d4f73
Also set font weight
Crabcyborg 045e0bc
Use cursor pointer
Crabcyborg bed5ef8
More tweaks to select styling
Crabcyborg 58c0989
Add some styles to the AI button
Crabcyborg 9d6559a
Improve how the spinner is added to the autofill button
Crabcyborg 34e8038
Add a tooltip for enabled form actions
Crabcyborg 60a5cae
Add new frm_additional_timestamp_text filter
Crabcyborg 4065edf
Merge branch 'master' into testing_mode
Crabcyborg 4a4f953
Add hover styling to test mode buttons
Crabcyborg eed2318
Move selected role logic out of view and into a filter so we can move…
Crabcyborg 1f8c6fc
Fix comment syntax
Crabcyborg 958fa71
Add some comments
Crabcyborg 0f89530
Add some z-index rules to avoid layering issues with repeater fields
Crabcyborg 61da2af
Tweak some test mode styles
Crabcyborg 7cd0781
Merge branch 'master' into testing_mode
Crabcyborg 2410d94
Merge branch 'master' into testing_mode
Crabcyborg 5731a68
Merge branch 'master' into testing_mode
Crabcyborg 7166d3d
Put test mode dropdown option behind new feature check
Crabcyborg 0944011
Run eslint fix
Crabcyborg 8696e23
Fix issue with setting fieldsUpdated when the variable does not exist…
Crabcyborg 6a1decc
Add more comments
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,376 @@ | ||
| <?php | ||
| if ( ! defined( 'ABSPATH' ) ) { | ||
| die( 'You are not allowed to call this page directly.' ); | ||
| } | ||
|
|
||
| /** | ||
| * @since x.x | ||
| */ | ||
| class FrmTestModeController { | ||
|
|
||
| /** | ||
| * Maybe add the test mode container. | ||
| * | ||
| * @since x.x | ||
| * | ||
| * @param string $html | ||
| * @return string | ||
| */ | ||
| public static function maybe_add_test_mode_container( $html ) { | ||
| if ( '' === $html || ! self::should_add_test_mode_container() ) { | ||
| return $html; | ||
| } | ||
|
|
||
| /** | ||
| * @since x.x | ||
| */ | ||
| do_action( 'frm_test_mode_container' ); | ||
|
|
||
| if ( false !== strpos( $html, '<div class="frm_form_fields' ) ) { | ||
| $html = preg_replace( | ||
| '/<div class="frm_form_fields/', | ||
| self::get_testing_mode_container() . '<div class="frm_form_fields', | ||
| $html, | ||
| 1 | ||
| ); | ||
| } else { | ||
| // If there no form, add before an error message. | ||
| $html = '<div class="with_frm_style">' . self::get_testing_mode_container() . '</div>' . $html; | ||
| } | ||
|
|
||
| return $html; | ||
| } | ||
|
|
||
| /** | ||
| * @since x.x | ||
| * | ||
| * @return bool | ||
| */ | ||
| public static function should_add_test_mode_container() { | ||
| if ( ! current_user_can( 'frm_edit_forms' ) ) { | ||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * Filter this so the add-on can enable it when applicable in other cases (like when submitting with AJAX). | ||
| * | ||
| * @since x.x | ||
| * | ||
| * @param bool $is_test_mode | ||
| */ | ||
| return (bool) apply_filters( 'frm_test_mode', (bool) FrmAppHelper::simple_get( 'testmode' ) ); | ||
| } | ||
|
|
||
| /** | ||
| * Get the testing mode container. | ||
| * | ||
| * @since x.x | ||
| * | ||
| * @return string | ||
| */ | ||
| private static function get_testing_mode_container() { | ||
| return FrmAppHelper::clip( | ||
| function () { | ||
| self::render_testing_mode_container(); | ||
| } | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Render the testing mode container. | ||
| * | ||
| * @since x.x | ||
| * | ||
| * @return void | ||
| */ | ||
| private static function render_testing_mode_container() { | ||
| $form_key = self::get_form_key_from_request(); | ||
| if ( ! $form_key ) { | ||
| return; | ||
| } | ||
|
|
||
| $form = FrmForm::getOne( $form_key ); | ||
| if ( ! $form ) { | ||
| return; | ||
| } | ||
|
|
||
| if ( ! empty( $form->options['chat'] ) ) { | ||
| echo '<div class="frm_note_style">' . esc_html__( 'Test Mode is currently not supported for conversational forms.', 'formidable' ) . '</div>'; | ||
| return; | ||
| } | ||
|
|
||
| $enabled = self::test_mode_addon_exists(); | ||
| $ai_enabled = class_exists( 'FrmAIAppHelper' ); | ||
| $roles = self::get_roles(); | ||
| $selected_role = self::get_selected_role(); | ||
| $pagination = apply_filters( 'frm_test_mode_pagination_buttons', false ); | ||
| $disabled_required_fields_toggle_args = self::get_disabled_required_fields_toggle_args(); | ||
| $show_all_hidden_fields_toggle_args = self::get_show_all_hidden_fields_toggle_args(); | ||
| $form_id = is_numeric( $form_key ) ? $form_key : FrmForm::get_id_by_key( $form_key ); | ||
| $should_show_upsell = self::should_show_upsell(); | ||
| $should_suggest_test_mode_install = ! $enabled && ! $should_show_upsell; | ||
| $should_suggest_ai_install = $enabled && ! $ai_enabled; | ||
| $should_show_warning = $should_suggest_test_mode_install || $should_suggest_ai_install; | ||
| $form_actions = FrmFormAction::get_action_for_form( $form_id ); | ||
| $enabled_form_actions = self::get_enabled_form_action_ids( $form_actions ); | ||
| $test_mode_install_span_attrs = array( | ||
| 'data-upgrade' => __( 'Test Mode Controls', 'formidable' ), | ||
| 'data-content' => 'test-mode', | ||
| 'data-medium' => 'test-mode', | ||
| 'data-requires' => 'Business', | ||
| 'style' => 'margin-left: auto;', | ||
| ); | ||
| $ai_install_span_attrs = array( | ||
| 'data-upgrade' => __( 'Autofilled forms with AI', 'formidable' ), | ||
| 'data-content' => 'ai-autofill', | ||
| 'data-medium' => 'test-mode', | ||
| 'data-requires' => 'Business', | ||
| 'style' => 'margin-left: auto;', | ||
| ); | ||
|
|
||
| $oneclick_data = FrmAddonsController::install_link( 'ai' ); | ||
| if ( isset( $oneclick_data['url'] ) ) { | ||
| $ai_install_span_attrs['data-oneclick'] = json_encode( $oneclick_data ); | ||
| } | ||
|
|
||
| $oneclick_data = FrmAddonsController::install_link( 'test-mode' ); | ||
| if ( isset( $oneclick_data['url'] ) ) { | ||
| $test_mode_install_span_attrs['data-oneclick'] = json_encode( $oneclick_data ); | ||
| } | ||
|
|
||
| self::include_svg(); | ||
|
|
||
| include FrmAppHelper::plugin_path() . '/classes/views/test-mode/container.php'; | ||
| } | ||
|
|
||
| /** | ||
| * This is required for the speaker icon in the upsell to appear, | ||
| * and for the lock icon in the upgrade modals. | ||
| * It is also required for the tooltip icon used for the enabled form actions setting. | ||
| * | ||
| * @since x.x | ||
| * | ||
| * @return void | ||
| */ | ||
| private static function include_svg() { | ||
| FrmAppHelper::include_svg(); | ||
| } | ||
|
|
||
| /** | ||
| * Check GET and POST to determine the current form key. | ||
| * | ||
| * @since x.x | ||
| * | ||
| * @return false|string | ||
| */ | ||
| private static function get_form_key_from_request() { | ||
| $form_key = FrmAppHelper::simple_get( 'form' ); | ||
| if ( $form_key ) { | ||
| return $form_key; | ||
| } | ||
|
|
||
| $form_key = FrmAppHelper::get_post_param( 'form', '', 'sanitize_text_field' ); | ||
| if ( $form_key ) { | ||
| return $form_key; | ||
| } | ||
|
|
||
| $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'sanitize_text_field' ); | ||
| if ( $form_id && is_numeric( $form_id ) ) { | ||
| return FrmForm::get_key_by_id( $form_id ); | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * Check the request data to determine which action IDs are currently enabled. | ||
| * | ||
| * @since x.x | ||
| * | ||
| * @param array $form_actions | ||
| * @return array | ||
| */ | ||
| private static function get_enabled_form_action_ids( $form_actions ) { | ||
| $all_form_action_ids = wp_list_pluck( $form_actions, 'ID' ); | ||
|
|
||
| /** | ||
| * Filters the list of enabled form action IDs. | ||
| * This way the add-on can modify it when required. | ||
| * | ||
| * @since x.x | ||
| * | ||
| * @param array $all_form_action_ids | ||
| */ | ||
| return apply_filters( 'frm_test_mode_enabled_form_action_ids', $all_form_action_ids ); | ||
| } | ||
|
|
||
| /** | ||
| * Determine if the upsell should be shown. | ||
| * | ||
| * @since x.x | ||
| * | ||
| * @return bool | ||
| */ | ||
| private static function should_show_upsell() { | ||
| if ( self::test_mode_addon_exists() ) { | ||
| return false; | ||
| } | ||
|
|
||
| return ! in_array( FrmAddonsController::license_type(), array( 'plus', 'business', 'elite' ) ); | ||
| } | ||
|
|
||
| /** | ||
| * Determine if the Test Mode add-on is installed and active. | ||
| * | ||
| * @since x.x | ||
| * | ||
| * @return bool | ||
| */ | ||
| private static function test_mode_addon_exists() { | ||
| if ( ! function_exists( 'load_formidable_test_mode' ) ) { | ||
| return false; | ||
| } | ||
|
|
||
| return FrmAppHelper::pro_is_installed(); | ||
| } | ||
|
|
||
| /** | ||
| * Get the list of roles that can be selected in the test mode container. | ||
| * | ||
| * @since x.x | ||
| * | ||
| * @return array | ||
| */ | ||
| private static function get_roles() { | ||
| if ( ! function_exists( 'get_editable_roles' ) ) { | ||
| require_once ABSPATH . 'wp-admin/includes/user.php'; | ||
| } | ||
|
|
||
| $roles = get_editable_roles(); | ||
| $roles['loggedout'] = array( | ||
| 'name' => __( 'Logged Out', 'formidable' ), | ||
| ); | ||
| return $roles; | ||
| } | ||
|
|
||
| /** | ||
| * Get the selected role for test mode. | ||
| * | ||
| * @since x.x | ||
| * | ||
| * @return string | ||
| */ | ||
| private static function get_selected_role() { | ||
| $selected_role = ''; | ||
|
|
||
| /** | ||
| * Filters the selected role for test mode so the add-on can modify it when required. | ||
| * | ||
| * @since x.x | ||
| * | ||
| * @param string $selected_role | ||
| */ | ||
| return apply_filters( 'frm_test_mode_selected_role', $selected_role ); | ||
| } | ||
|
|
||
| /** | ||
| * Get the arguments for the disabled required fields toggle. | ||
| * | ||
| * @since x.x | ||
| * | ||
| * @return array | ||
| */ | ||
| private static function get_disabled_required_fields_toggle_args() { | ||
| /** | ||
| * Filters the arguments for the disabled required fields toggle so the add-on can modify it. | ||
| * | ||
| * @since x.x | ||
| * | ||
| * @param array $args | ||
| */ | ||
| return (array) apply_filters( | ||
| 'frm_test_mode_disable_required_fields_toggle_args', | ||
| array( | ||
| 'echo' => true, | ||
| 'off_label' => __( 'Disable Required Fields', 'formidable' ), | ||
| 'show_labels' => true, | ||
| 'disabled' => true, | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Get the arguments for the show all hidden fields toggle. | ||
| * | ||
| * @since x.x | ||
| * | ||
| * @return array | ||
| */ | ||
| private static function get_show_all_hidden_fields_toggle_args() { | ||
| /** | ||
| * Filters the arguments for the show all hidden fields toggle so the add-on can modify it. | ||
| * | ||
| * @since x.x | ||
| * | ||
| * @param array $args | ||
| */ | ||
| return (array) apply_filters( | ||
| 'frm_test_mode_show_all_hidden_fields_toggle_args', | ||
| array( | ||
| 'echo' => true, | ||
| 'off_label' => __( 'Show All Hidden Fields', 'formidable' ), | ||
| 'show_labels' => true, | ||
| 'disabled' => true, | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Register and enqueue the required scripts for the test mode container Lite functionality. | ||
| * | ||
| * @since x.x | ||
| * | ||
| * @return void | ||
| */ | ||
| public static function register_and_enqueue_required_scripts() { | ||
| // These are used for the upgrade pop-up. | ||
| FrmAppController::enqueue_dialog_assets(); | ||
| FrmAppController::upgrade_overlay_html(); | ||
|
|
||
| $version = FrmAppHelper::plugin_version(); | ||
|
|
||
| wp_enqueue_style( 'frm_testing_mode', FrmAppHelper::plugin_url() . '/css/frm_testing_mode.css', array(), $version ); | ||
|
Crabcyborg marked this conversation as resolved.
|
||
| wp_enqueue_script( 'frm_testing_mode', FrmAppHelper::plugin_url() . '/js/frm_testing_mode.js', array( 'jquery', 'formidable_dom' ), $version, true ); | ||
|
|
||
| // These are used in addon-state.js. | ||
| $admin_script_strings = array( | ||
| 'active' => __( 'Active', 'formidable' ), | ||
| 'installed' => __( 'Installed', 'formidable' ), | ||
| 'not_installed' => __( 'Not Installed', 'formidable' ), | ||
| ); | ||
| wp_localize_script( 'frm_testing_mode', 'frm_admin_js', $admin_script_strings ); | ||
|
|
||
| self::register_and_enqueue_multiselect_dropdown_requirements(); | ||
| } | ||
|
Crabcyborg marked this conversation as resolved.
|
||
|
|
||
| /** | ||
| * Register and enqueue the required scripts for the multiselect dropdown. | ||
| * | ||
| * @since x.x | ||
| * | ||
| * @return void | ||
| */ | ||
| private static function register_and_enqueue_multiselect_dropdown_requirements() { | ||
| // Enqueue multiselect dropdown requirements. | ||
| $plugin_url = FrmAppHelper::plugin_url(); | ||
| $version = FrmAppHelper::plugin_version(); | ||
|
|
||
| wp_register_script( 'popper', FrmAppHelper::plugin_url() . '/js/popper.min.js', array( 'jquery' ), '1.16.0', true ); | ||
| wp_register_script( 'bootstrap_tooltip', $plugin_url . '/js/bootstrap.min.js', array( 'jquery', 'popper' ), '4.6.1', true ); | ||
| wp_register_script( 'bootstrap-multiselect', $plugin_url . '/js/bootstrap-multiselect.js', array( 'jquery', 'bootstrap_tooltip', 'popper' ), '1.1.1', true ); | ||
| wp_register_script( 'formidable_dom', $plugin_url . '/js/admin/dom.js', array( 'jquery', 'jquery-ui-dialog', 'wp-i18n' ), $version, true ); | ||
|
|
||
| wp_enqueue_script( 'bootstrap-multiselect' ); | ||
| wp_enqueue_script( 'formidable_dom' ); | ||
| } | ||
| } | ||
|
Crabcyborg marked this conversation as resolved.
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.