-
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
Merged
saifsultanc
merged 2 commits into
master
from
saif/add/82217-colorpicker-choice-template
May 1, 2025
Merged
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?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 | ||
*/ | ||
class GPPA_Compatibility_JetSloth_Color_Picker_Template { | ||
|
||
public function __construct() { | ||
add_filter( 'gppa_input_choice', array( $this, 'add_colorpicker_to_choice' ), 10, 4 ); | ||
add_action( 'gform_editor_js', array( $this, 'add_colorpicker_choice_template' ), 1 ); | ||
} | ||
|
||
public function add_colorpicker_to_choice( $choice, $field, $object, $objects ) { | ||
$templates = rgar( $field, 'gppa-choices-templates', array() ); | ||
|
||
if ( rgar( $templates, 'colorPicker_color' ) ) { | ||
$choice['colorPicker_color'] = gp_populate_anything()->process_template( $field, 'colorPicker_color', $object, 'choices', $objects ); | ||
} | ||
|
||
return $choice; | ||
} | ||
|
||
public function add_colorpicker_choice_template() { | ||
?> | ||
<script type="text/javascript"> | ||
window.gform.addFilter( 'gppa_template_rows', function ( templateRows, field, populate ) { | ||
if ( populate !== 'choices' ) { | ||
return templateRows; | ||
} | ||
|
||
templateRows.push( { | ||
id: 'colorPicker_color', | ||
label: '<?php echo esc_js( __( 'Color Picker', 'gp-populate-anything' ) ); ?>', | ||
required: false, | ||
} ); | ||
|
||
return templateRows; | ||
} ); | ||
</script> | ||
<?php | ||
} | ||
} | ||
|
||
new GPPA_Compatibility_JetSloth_Color_Picker_Template(); |
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.
🛠️ 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 aText Domain
(and optionallyDomain Path
) in the plugin header so translations work correctly.Example diff:
📝 Committable suggestion