-
Notifications
You must be signed in to change notification settings - Fork 91
gppa-colorpicker-choice-template.php
: Added Color Picker choice template for GPPA to work with Jet Sloth Color Picker plugin.
#1081
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
gppa-colorpicker-choice-template.php
: Added Color Picker choice template for GPPA to work with Jet Sloth Color Picker plugin.
#1081
Conversation
…plate for GPPA to work with Jet Sloth Color Picker plugin.
Caution Review failedThe pull request is closed. WalkthroughA new PHP file has been added that defines the Changes
Sequence Diagram(s)sequenceDiagram
participant Admin as Form Editor (Admin)
participant JS as Editor JavaScript
participant PHP as GPPA_Compatibility_JetSloth_Color_Picker_Template (PHP)
participant PA as Populate Anything Plugin
Admin->>JS: Open Populate Anything field editor
JS->>JS: Apply filter to template rows
JS->>JS: Add "Color Picker" template row if context is 'choices'
PA->>PHP: Filter gppa_input_choice (process template)
PHP->>PA: Add 'colorPicker_color' to choice if template present
PA->>PA: Process template value for color picker
Possibly related PRs
Suggested reviewers
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 1
🧹 Nitpick comments (2)
gp-populate-anything/gppa-colorpicker-choice-template.php (2)
16-21
: Prevent class re-declaration & add PHPDoc
To avoid fatal errors if this file is loaded more than once, wrap the class definition in aclass_exists
guard. Also, adding a PHPDoc block for the class improves maintainability.- class GPPA_Color_Picker_Template { + if ( ! class_exists( 'GPPA_Color_Picker_Template' ) ) { + /** + * Adds a custom "Color Picker" choice template for GPPA. + */ + class GPPA_Color_Picker_Template {…and close the guard after instantiation:
- new GPPA_Color_Picker_Template(); + new GPPA_Color_Picker_Template(); + }
23-31
: Improve template existence check
Currently you rely onrgar()
truthiness which skips empty templates. For consistency, useisset()
to detect the presence of the key, even if set to an empty string.- if ( rgar( $templates, 'colorPicker_color' ) ) { + if ( isset( $templates['colorPicker_color'] ) ) { $choice['colorPicker_color'] = gp_populate_anything()->process_template( $field, 'colorPicker_color', $object, 'choices', $objects ); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
gp-populate-anything/gppa-colorpicker-choice-template.php
(1 hunks)
🔇 Additional comments (2)
gp-populate-anything/gppa-colorpicker-choice-template.php (2)
33-51
: JS registration of template row is correctly implemented
Using thegform_editor_js
action to inject agppa_template_rows
filter and escaping the label withesc_js()
is spot-on. No changes needed here.
54-55
: Instantiate the class to activate hooks
Instantiating the class at the end ensures your filters and actions are registered. This is correct.
<?php | ||
/** | ||
* Gravity Perks // Populate Anything // Add Custom Template Row for Color Picker | ||
* https://gravitywiz.com/documentation/gravity-forms-populate-anything/ | ||
* | ||
* Instructions Video: https://www.loom.com/share/c062a781a86242de9f1ebb92492a408c | ||
* | ||
* Adds "Color Picker" template row to the Populate Anything interface and processes its value (with Jet Sloth's Color Picker plugin). | ||
* | ||
* Plugin Name: GP Populate Anything — Color Picker Choice Template | ||
* Plugin URI: https://gravitywiz.com/documentation/gravity-forms-populate-anything/ | ||
* Description: Adds a custom template row and value processing for "Color Picker" in Populate Anything. | ||
* Author: Gravity Wiz | ||
* Version: 1.0 | ||
*/ |
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.
🛠️ Refactor suggestion
Add security guard and text domain header
It’s best practice to prevent direct access by checking ABSPATH
at the top of the file, and to include a Text Domain
(and optionally Domain Path
) in the plugin header so translations work correctly.
Example diff:
1a2,5
+ if ( ! defined( 'ABSPATH' ) ) {
+ exit; // Exit if accessed directly.
+ }
15a20,21
+ * Text Domain: gp-populate-anything
+ * Domain Path: /languages
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
<?php | |
/** | |
* Gravity Perks // Populate Anything // Add Custom Template Row for Color Picker | |
* https://gravitywiz.com/documentation/gravity-forms-populate-anything/ | |
* | |
* Instructions Video: https://www.loom.com/share/c062a781a86242de9f1ebb92492a408c | |
* | |
* Adds "Color Picker" template row to the Populate Anything interface and processes its value (with Jet Sloth's Color Picker plugin). | |
* | |
* Plugin Name: GP Populate Anything — Color Picker Choice Template | |
* Plugin URI: https://gravitywiz.com/documentation/gravity-forms-populate-anything/ | |
* Description: Adds a custom template row and value processing for "Color Picker" in Populate Anything. | |
* Author: Gravity Wiz | |
* Version: 1.0 | |
*/ | |
<?php | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; // Exit if accessed directly. | |
} | |
/** | |
* Gravity Perks // Populate Anything // Add Custom Template Row for Color Picker | |
* https://gravitywiz.com/documentation/gravity-forms-populate-anything/ | |
* | |
* Instructions Video: https://www.loom.com/share/c062a781a86242de9f1ebb92492a408c | |
* | |
* Adds "Color Picker" template row to the Populate Anything interface and processes its value (with Jet Sloth's Color Picker plugin). | |
* | |
* Plugin Name: GP Populate Anything — Color Picker Choice Template | |
* Plugin URI: https://gravitywiz.com/documentation/gravity-forms-populate-anything/ | |
* Description: Adds a custom template row and value processing for "Color Picker" in Populate Anything. | |
* Author: Gravity Wiz | |
* Version: 1.0 | |
* Text Domain: gp-populate-anything | |
* Domain Path: /languages | |
*/ |
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.
@saifsultanc I made a naming update suggestion, but other than it looks ready to go 💯
…plate for GPPA to work with Jet Sloth Color Picker plugin.
Context
⛑️ Ticket(s): https://secure.helpscout.net/conversation/2908760149/82217
Summary
Jetsloth Gravity Forms Color Picker doesn't work on a dynamically populated field. Add support for using Jetsloth Gravity Forms Color Picker on a GPPA populated field
Loom (Samuel):
https://www.loom.com/share/072f38457d3347bbac3c4771bb3b883e
We have added support it. How it looks after snippet added:
https://www.loom.com/share/c062a781a86242de9f1ebb92492a408c