Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Save CF new form entries as user meta data and display a list of these entries linked to a modal form filled with entry
<?php
/*
* Plugin Name: CF entries as user meta data
* Description: Save entries as USER metadata, display list of entries for a user to see / edit them
* Author: New0
*/
/**
* On form submit, associate new entries to USER
*/
add_action( 'caldera_forms_submit_complete', function( $form, $form_link_array, $process_id, $entry_id ){
//change form ID to match your form
if( 'CF5cae2cff5d65c' === $form[ 'ID' ] && get_current_user_id() ){
$form_entry_ids_user_meta = get_user_meta( get_current_user_id(), 'form_entry_ids' );
if(!empty($form_entry_ids_user_meta)){
$entry_ids = $form_entry_ids_user_meta[0];
}
$entry_ids[] = $entry_id;
update_user_meta( get_current_user_id(), 'form_entry_ids', array_unique($entry_ids) );
}
}, 10, 4);
/**
* Adds the list of entries associated to the current user in the POST with ID 165 (edit with post ID needed)
*/
add_filter( 'the_content', function( $content ){
$post = get_post();
//EDIT POST ID
if( 165 === $post->ID ){
//EDIT FORM ID
$form = 'CF5cae2cff5d65c';
$entry_ids = get_user_meta( get_current_user_id(), 'form_entry_ids' );
if(!empty($entry_ids)){
$entry_ids = $entry_ids[0];
}
$view_entries = '<div class="my-custom-entries"><ul>';
foreach($entry_ids as $key => $entry_id){
$entry = Caldera_Forms::get_entry($entry_id, $form);
if( $entry['status'] === "active" ){
$view_entries .= '<li>' . do_shortcode('[caldera_form_modal id="'. $form . '" entry="' . $entry_id . '"]
View / Edit entry '. $entry_id . '
[/caldera_form_modal]') . '</li>';
}
}
$view_entries .= '</ul></div>';
$content .= $view_entries;
}
return $content;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.