Skip to content

Instantly share code, notes, and snippets.

@bacoords
Last active May 6, 2021 23:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bacoords/63dfbf0b5c3af7e967d954cd23c99074 to your computer and use it in GitHub Desktop.
Save bacoords/63dfbf0b5c3af7e967d954cd23c99074 to your computer and use it in GitHub Desktop.
<?php
/**
* Register an action with 'fl_page_data_add_properties' hook
*/
add_action( 'fl_page_data_add_properties', 'demo_add_properties' );
function demo_add_properties(){
/**
* Add a custom group
*/
FLPageData::add_group( 'demo_details_group', array(
'label' => 'My Custom Fields'
) );
/**
* Add a new property to our group
*/
FLPageData::add_post_property( 'demo_details', array(
'label' => 'Address',
'group' => 'demo_details_group',
'type' => array('string'),
'getter' => 'demo_connection_getter',
) );
/**
* A list of the meta fields
*/
$meta_fields = array(
'_demo_address_1' => 'Address Line 1',
'_demo_address_2' => 'Address Line 2',
'_demo_city' => 'City',
'_demo_state' => 'State',
'_demo_zip' => 'Zip Code',
'_demo_country' => 'Country'
);
/**
* Settings option to pop up when our group is added
*/
FLPageData::add_post_property_settings_fields(
'demo_details',
array(
'key' => array(
'type' => 'select',
'label' => 'Select a Field',
'options' => $meta_fields,
),
)
);
}
/**
* Helper function to retrieve settings fields values
*/
function demo_connection_getter( $settings, $property ){
global $post;
if( '' == $settings->key ) return '';
return get_post_meta($post->ID, $settings->key, true);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment