Skip to content

Remove buttons settings tab#2115

Merged
Crabcyborg merged 7 commits into
masterfrom
remove-buttons-settings
Nov 26, 2024
Merged

Remove buttons settings tab#2115
Crabcyborg merged 7 commits into
masterfrom
remove-buttons-settings

Conversation

@truongwp
Copy link
Copy Markdown
Contributor

Related PR: https://github.com/Strategy11/formidable-pro/pull/5479

In the related PR, we won't use frm_add_form_style_tab_options and frm_add_form_button_options hooks to print hidden inputs anymore. If these hooks are still used by custom code, we will keep the Buttons settings tab, and show the deprecation notices. If these hooks aren't used, we remove the Buttons settings tab completely.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Nov 18, 2024

Walkthrough

The pull request introduces several modifications to the FrmFormsController class and the settings-buttons.php view file. Key changes include the enhancement of the get_settings_tabs method to conditionally manage settings visibility, the transition of the delete_all method to public access, and the addition of a new method for renaming forms. Additionally, the settings-buttons.php file now includes logic to conditionally deprecate hooks based on the version of the Pro plugin, improving error handling.

Changes

File Path Change Summary
classes/controllers/FrmFormsController.php - Updated get_settings_tabs to conditionally remove 'buttons' section.
- Changed delete_all from private to public.
- Added rename_form method for AJAX renaming of forms.
- Refined maybe_trigger_redirect for better post-submission handling.
classes/views/frm-forms/settings-buttons.php - Introduced $should_deprecate_hook to conditionally deprecate hooks based on FrmProDb class version.

Possibly related PRs

Suggested labels

action: needs qa

Suggested reviewers

  • lauramekaj1

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 6c2cd1b and 1eb0eaf.

📒 Files selected for processing (1)
  • classes/views/frm-forms/settings-buttons.php (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • classes/views/frm-forms/settings-buttons.php

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (3)
classes/views/frm-forms/settings-buttons.php (2)

6-7: Enhance the deprecation check comment.

The current comment could be more descriptive about the purpose and conditions of the deprecation check.

Consider this improved version:

-// Do not deprecate if the Pro version still use these hooks.
+// Only deprecate hooks if Formidable Pro >= 6.16.2 is active, as older versions still use these hooks.

Line range hint 24-29: Enhance the settings migration notice.

Consider providing more specific guidance on how to access the moved settings.

-<?php esc_html_e( 'Submit button settings were moved to the Submit button in the form builder.', 'formidable' ); ?>
+<?php esc_html_e( 'Submit button settings were moved to the Submit button in the form builder. Click the submit button in the form preview to access these settings.', 'formidable' ); ?>
classes/controllers/FrmFormsController.php (1)

Line range hint 952-991: Improve error handling in create_page_with_shortcode method

In the create_page_with_shortcode() method, die( 0 ); is used for error handling when permissions are insufficient or required parameters are missing. Using die() is not recommended in WordPress AJAX handlers. Consider using wp_send_json_error() or wp_die() with appropriate HTTP status codes and messages to provide better feedback and adhere to WordPress best practices.

Apply this diff to improve error handling:

@@ -954,7 +954,7 @@
     public static function create_page_with_shortcode() {
         if ( ! current_user_can( 'publish_posts' ) ) {
-            die( 0 );
+            wp_send_json_error( __( 'You do not have permission to publish posts.', 'formidable' ), 403 );
         }

         check_ajax_referer( 'frm_ajax', 'nonce' );
@@ -960,7 +960,7 @@
         $type = FrmAppHelper::get_post_param( 'type', '', 'sanitize_text_field' );
         if ( ! $type || ! in_array( $type, array( 'form', 'view' ), true ) ) {
-            die( 0 );
+            wp_send_json_error( __( 'Invalid type parameter.', 'formidable' ), 400 );
         }

         $object_id = FrmAppHelper::get_post_param( 'object_id', '', 'absint' );
@@ -964,7 +964,7 @@
         if ( ! $object_id ) {
-            die( 0 );
+            wp_send_json_error( __( 'Missing object ID.', 'formidable' ), 400 );
         }

         $postarr = array( 'post_type' => 'page' );
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0e23fb2 and 77a8789.

📒 Files selected for processing (2)
  • classes/controllers/FrmFormsController.php (1 hunks)
  • classes/views/frm-forms/settings-buttons.php (2 hunks)
🔇 Additional comments (5)
classes/views/frm-forms/settings-buttons.php (2)

13-17: LGTM! Proper hook deprecation handling.

The conditional logic correctly implements WordPress hook deprecation practices, maintaining backward compatibility while warning about future removal.


32-36: Verify usage of deprecated hooks.

Let's verify if these hooks are still being used in the codebase to ensure we're not breaking any existing functionality.

✅ Verification successful

Hooks are still in active use - deprecation approach is correct

The verification shows that both hooks are actively used in the core functionality:

  • frm_add_form_style_tab_options is used in:

    • Added via FrmHooksController
    • Removed via FrmAppController
    • Used for conditional section display in FrmFormsController
  • frm_add_form_button_options is used in:

    • Checked for conditional section display in FrmFormsController
    • Both hooks control visibility of the 'buttons' section

The current implementation using do_action_deprecated() is the correct approach as it maintains backward compatibility while signaling deprecation to developers.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining usage of these hooks in the codebase
echo "Checking usage of frm_add_form_style_tab_options hook:"
rg "add_action.*frm_add_form_style_tab_options" -B 2 -A 2

echo -e "\nChecking usage of frm_add_form_button_options hook:"
rg "add_action.*frm_add_form_button_options" -B 2 -A 2

Length of output: 929


Script:

#!/bin/bash
# Let's search for any usage of these hooks, including apply_filters and do_action calls
echo "Checking all usage of frm_add_form_style_tab_options hook:"
rg "frm_add_form_style_tab_options" -B 2 -A 2

echo -e "\nChecking all usage of frm_add_form_button_options hook:"
rg "frm_add_form_button_options" -B 2 -A 2

# Let's also check for any potential usage in plugin integrations or add-ons
echo -e "\nChecking for potential plugin integration files:"
fd -e php | grep -i "integration\|addon\|add-on"

Length of output: 3872

classes/controllers/FrmFormsController.php (3)

Line range hint 1050-1053: Evaluate the implications of changing delete_all method visibility to public

The delete_all() method has been changed from private to public. Exposing this method publicly allows it to be called from outside the class, which might introduce security risks or unintended usage. Verify that appropriate permission checks are in place to prevent unauthorized access to this method.

Run the following script to verify if delete_all() is being called externally and ensure permission checks are in place:

#!/bin/bash
# Description: Check for external calls to `delete_all()` method.

# Search for calls to `delete_all()` outside the `FrmFormsController` class.
rg 'FrmFormsController::delete_all\('

Line range hint 1041-1050: Assess the impact of updating form_key in rename_form method

In the rename_form() method, the form_key is updated alongside the form name when a form is renamed. Changing the form_key may have unintended side effects if the form is referenced elsewhere using the old form_key. Ensure that updating the form_key will not break any existing references, shortcodes, or integrations that rely on the original form_key.

Run the following script to find hard-coded references to the old form_key in the codebase:

#!/bin/bash
# Description: Search for hard-coded references to the old form_key.

# Replace 'old_form_key' with the actual old form_key value.
rg 'old_form_key'

1412-1414: Ensure consistent handling of the 'buttons' settings tab

The conditional removal of the 'buttons' section from the settings tabs is appropriate if the associated hooks are not in use. However, verify that there are no unconditional references to $sections['buttons'] elsewhere in the codebase, which could lead to undefined index errors.

Run the following script to check for unconditional usages of $sections['buttons']:

✅ Verification successful

The previous search didn't yield the expected results as it used the wrong pattern. Let me try a more comprehensive search:


Let me correct the syntax and try again:


Let me try a simpler pattern without backreferences:


The 'buttons' section removal is safely implemented

The search results show that $sections['buttons'] is only referenced once in the codebase, and it's properly guarded by the conditional check that verifies if the related hooks are present. There are no other unconditional references to this array key that could cause undefined index errors.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for usages of $sections['buttons'] without prior checks.

# Find all occurrences of $sections['buttons'] in the codebase.
rg --php '$sections\["buttons"\]'

Length of output: 117


Script:

#!/bin/bash
# Search for any references to $sections['buttons'] with different quote styles
rg --php -A 3 -B 3 '\$sections\[(["'\''])buttons\1\]'

Length of output: 463


Script:

#!/bin/bash
# Search for any references to $sections['buttons'] with different quote styles
rg -A 3 -B 3 '\$sections\[(["'\''])buttons\1\]'

# Also search for array access with curly braces syntax
rg -A 3 -B 3 '\$sections\{["'\'']buttons["\'']\}'

Length of output: 435


Script:

#!/bin/bash
# Search for any references to $sections['buttons'] or $sections["buttons"]
rg -A 3 -B 3 '\$sections\[(["'\''])buttons["'\''\]]'

# Also search for the string 'buttons' within the context of $sections
rg -A 3 -B 3 '\$sections.*buttons'

Length of output: 1141

Comment thread classes/views/frm-forms/settings-buttons.php Outdated
@Crabcyborg Crabcyborg modified the milestones: 6.16.2, 6.16.3 Nov 19, 2024
@Crabcyborg Crabcyborg modified the milestones: 6.16.3, 6.16.2 Nov 20, 2024
Copy link
Copy Markdown
Contributor

@Crabcyborg Crabcyborg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @truongwp!

🚀

@Crabcyborg Crabcyborg modified the milestones: 6.16.2, 6.16.3 Nov 20, 2024
@Crabcyborg
Copy link
Copy Markdown
Contributor

It seems something about this update causes the e2e tests to fail.

@Crabcyborg
Copy link
Copy Markdown
Contributor

@lauramekaj1 Maybe you can help with this failing unit test issue we're having here.

This update really just removes the "Buttons" section in form settings. Is there a test that is checking for this somewhere that needs to be updated?

Thank you!

@lauramekaj1
Copy link
Copy Markdown
Contributor

@lauramekaj1 Maybe you can help with this failing unit test issue we're having here.

This update really just removes the "Buttons" section in form settings. Is there a test that is checking for this somewhere that needs to be updated?

Thank you!

@Crabcyborg yes sure I will look into this!

@lauramekaj1
Copy link
Copy Markdown
Contributor

@Crabcyborg @truongwp When I switch to the remove-buttons-settings branch, I'm unable to click on the sections in the form settings. In comparison, everything works fine in the master branch. I've attached a screen recording for reference: https://www.loom.com/share/dc1286c9152c482d839d33fdb8ebacec?sid=41c58beb-a01b-4000-ab2a-acd0f52d85f7

Note: If you have Formidable Forms Pro activated, then deactivate and you should be able to reproduce this issue. Let me know if you need further information!
Thank you!

@Crabcyborg
Copy link
Copy Markdown
Contributor

Thank you @lauramekaj1!

So there's a real bug here.

@truongwp I'm seeing this fatal error in my logs

PHP Fatal error:  Uncaught Error: Unknown named parameter $values

Comment thread classes/views/frm-forms/settings-buttons.php Outdated
@truongwp
Copy link
Copy Markdown
Contributor Author

Thanks @lauramekaj1 and @Crabcyborg. I fixed the fatal error. I'm not sure why it didn't trigger that fatal error when I tested before the commit 43aee7a

@Crabcyborg
Copy link
Copy Markdown
Contributor

@truongwp I don't believe that passing a 'values' string works. I think we need to use the $values variable directly.

@truongwp
Copy link
Copy Markdown
Contributor Author

@Crabcyborg Oh sorry, I fixed it.

@Crabcyborg Crabcyborg merged commit 112e626 into master Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants