Skip to content

Instantly share code, notes, and snippets.

View jetsloth's full-sized avatar

JetSloth jetsloth

View GitHub Profile
@jetsloth
jetsloth / gppa_image_choices_from_term_acf_field.php
Last active August 5, 2024 03:45
An example for Image Choices with Gravity Perks Populate Anything, where the object is a taxonomy and the ACF field returns either an image ID or object
<?php
function gppa_image_choices_from_term_acf_field( $choice, $field, $object, $objects ) {
$object_type = rgobj($field, 'gppa-choices-object-type');
if ( !function_exists('gf_image_choices') || !gf_image_choices()->field_has_image_choices_enabled($field) ) {
return $choice;
}
$templates = rgobj($field, 'gppa-choices-templates');
$template = (!empty($templates)) ? rgar($templates, 'imageChoices_image') : "";
@jetsloth
jetsloth / gppa_image_choices_from_form_entry_example.php
Last active August 5, 2024 03:44
An example for using Gravity Perks Populate Anything with Image Choices where the image source is a form entry, and another Image Choices field
<?php
function gppa_image_choices_from_form_entry( $choice, $field, $object, $objects ) {
$object_type = rgobj($field, 'gppa-choices-object-type');
if ( $object_type != "gf_entry" || !function_exists('gf_image_choices') || !gf_image_choices()->field_has_image_choices_enabled($field) ) {
return $choice;
}
$templates = rgobj($field, 'gppa-choices-templates');
$template = (!empty($templates)) ? rgar($templates, 'imageChoices_image') : "";
@jetsloth
jetsloth / gppa_enhanced_choices_example.php
Last active July 9, 2024 06:55
Example code for integrating Enhanced Choices with GPPA (Populate Anything). Includes the basic config for each available component.
<?php
add_filter('gppa_input_choice_FORMID_FIELDID', function ($choice, $field, $object, $objects) {
if (!function_exists('gf_enhanced_choices')) {
return $choice;
}
// Assuming $object is a Post object
$categories = get_the_category($object->IO);
@jetsloth
jetsloth / populate_enhanced_choices_from_posts.php
Last active April 24, 2024 00:32
An example of dynamically populating Enhanced Choices from posts
<?php
add_filter( 'gform_pre_render', 'populate_enhanced_choices_from_posts' );
add_filter( 'gform_pre_validation', 'populate_enhanced_choices_from_posts' );
add_filter( 'gform_pre_submission_filter', 'populate_enhanced_choices_from_posts' );
add_filter( 'gform_admin_pre_render', 'populate_enhanced_choices_from_posts' );
function populate_enhanced_choices_from_posts( $form ) {
// update form and field ID to suit
$FORM_ID = 1;
@jetsloth
jetsloth / gform_pre_render_custom_color_picker_options.php
Created April 20, 2023 00:33
Example of dynamic population for color picker options
<?php
add_filter( 'gform_pre_render', 'populate_gf_color_choices' );
add_filter( 'gform_pre_validation', 'populate_gf_color_choices' );
add_filter( 'gform_pre_submission_filter', 'populate_gf_color_choices' );
add_filter( 'gform_admin_pre_render', 'populate_gf_color_choices' );
function populate_gf_color_choices( $form ) {
if ( $form['id'] != 9999 ) {// set to the form id you want to run this on
@jetsloth
jetsloth / custom_image_choices_size.php
Created October 23, 2022 23:11
Customise the image size used for Image Choices
<?php
add_filter( 'gform_pre_render', 'custom_image_choices_size' );
add_filter( 'gform_pre_validation', 'custom_image_choices_size' );
add_filter( 'gform_pre_submission_filter', 'custom_image_choices_size' );
add_filter( 'gform_admin_pre_render', 'custom_image_choices_size' );
function custom_image_choices_size( $form ) {
foreach ( $form["fields"] as &$field ) {
if ( property_exists($field, "imageChoices_enableImages") && !empty($field->imageChoices_enableImages) ) {
/*Import font*/
@import url('https://fonts.googleapis.com/css2?family=Merriweather:wght@900&display=swap');
.newsletter-signup_wrapper {
border: 1px solid #ebebe5;
border-radius: 20px;
background-color: #fafbf8;
background:url('https://images.unsplash.com/photo-1509624776920-0fac24a9dfda?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2369&q=80');
padding: 80px;
background-size:cover;
}
/*////////////////////////// Color Variables //////////////////////////*/
:root {
/*Purple*/
--theme1: #7245F1;
--theme1-light: #F0ECFD;
/*Orange*/
--theme2: #FFA630;
--theme2-light: #FFF7EC;
/*Blue*/
--theme3: #0076FF;
/*Add animated CSS gradient to your form background*/
.gradient_wrapper {
background: linear-gradient(45deg, #2455EB, #24DDEB, #59EB24);
background-size: 600% 600%;
animation: GradientBackground 9s ease-in infinite;
border:none!important;
}
@keyframes GradientBackground {
0% {
/*Add the class pulse to any field you want to pulse*/
.pulse input,
.pulse textarea {
animation: pulse-animation 3s infinite;
}
@keyframes pulse-animation {
0% {
box-shadow: 0 0 0 0px #2d6dec;
}