Skip to content

Commit f520713

Browse files
authored
gppa-colorpicker-choice-template.php: Added Color Picker choice template for GPPA to work with Jet Sloth Color Picker plugin.
1 parent 00117a8 commit f520713

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* Gravity Perks // Populate Anything // Add Custom Template Row for Color Picker
4+
* https://gravitywiz.com/documentation/gravity-forms-populate-anything/
5+
*
6+
* Instructions Video: https://www.loom.com/share/c062a781a86242de9f1ebb92492a408c
7+
*
8+
* Adds "Color Picker" template row to the Populate Anything interface and processes its value (with Jet Sloth's Color Picker plugin).
9+
*
10+
* Plugin Name: GP Populate Anything — Color Picker Choice Template
11+
* Plugin URI: https://gravitywiz.com/documentation/gravity-forms-populate-anything/
12+
* Description: Adds a custom template row and value processing for "Color Picker" in Populate Anything.
13+
* Author: Gravity Wiz
14+
* Version: 1.0
15+
*/
16+
class GPPA_Compatibility_JetSloth_Color_Picker_Template {
17+
18+
public function __construct() {
19+
add_filter( 'gppa_input_choice', array( $this, 'add_colorpicker_to_choice' ), 10, 4 );
20+
add_action( 'gform_editor_js', array( $this, 'add_colorpicker_choice_template' ), 1 );
21+
}
22+
23+
public function add_colorpicker_to_choice( $choice, $field, $object, $objects ) {
24+
$templates = rgar( $field, 'gppa-choices-templates', array() );
25+
26+
if ( rgar( $templates, 'colorPicker_color' ) ) {
27+
$choice['colorPicker_color'] = gp_populate_anything()->process_template( $field, 'colorPicker_color', $object, 'choices', $objects );
28+
}
29+
30+
return $choice;
31+
}
32+
33+
public function add_colorpicker_choice_template() {
34+
?>
35+
<script type="text/javascript">
36+
window.gform.addFilter( 'gppa_template_rows', function ( templateRows, field, populate ) {
37+
if ( populate !== 'choices' ) {
38+
return templateRows;
39+
}
40+
41+
templateRows.push( {
42+
id: 'colorPicker_color',
43+
label: '<?php echo esc_js( __( 'Color Picker', 'gp-populate-anything' ) ); ?>',
44+
required: false,
45+
} );
46+
47+
return templateRows;
48+
} );
49+
</script>
50+
<?php
51+
}
52+
}
53+
54+
new GPPA_Compatibility_JetSloth_Color_Picker_Template();

0 commit comments

Comments
 (0)