Last active
July 9, 2024 06:55
-
-
Save jetsloth/49a0b8ad79955286b7048c236c09d571 to your computer and use it in GitHub Desktop.
Example code for integrating Enhanced Choices with GPPA (Populate Anything). Includes the basic config for each available component.
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
<?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); | |
$list_items = array(); | |
foreach ($categories as $cat) { | |
$list_items[] = $cat->name; | |
} | |
$featured_image = get_the_post_thumbnail_url($object->ID, 'full'); | |
if (empty($featured_image)) { | |
$featured_image = gf_enhanced_choices()->placeholder_image(); | |
} | |
$choice = gf_enhanced_choices()->choice_add_components($choice, array( | |
array( | |
'type' => 'image', | |
'src' => $featured_image, | |
'alt' => $object->post_title, | |
), | |
array( | |
'type' => 'pill', | |
'text' => (!empty($categories)) ? $categories[0]->name : $object->post_title, | |
), | |
array( | |
'type' => 'title', | |
'text' => $object->post_title, | |
), | |
array( | |
'type' => 'label', | |
), | |
array( | |
'type' => 'price', | |
), | |
array( | |
'type' => 'paragraph', | |
'text' => get_the_excerpt($object->ID), | |
), | |
array( | |
'type' => 'list', | |
'listBorders' => true, | |
'decoration' => 'none', | |
'items' => $list_items, | |
), | |
array( | |
'type' => 'button', | |
'text' => "Select", | |
), | |
array( | |
'type' => 'html', | |
'text' => '<iframe width="560" height="315" src="https://www.youtube.com/embed/NEKvDFs5J-A?si=SBlt91KubSzAafci" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>', | |
), | |
)); | |
return $choice; | |
}, 10, 4); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment