Created
June 20, 2019 02:07
-
-
Save gene158/4877a21a0812ad888f1e733d25dcbce2 to your computer and use it in GitHub Desktop.
Custom shortcode to display forms of all submitted entries for current user - WPForms
This file contains 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
/** | |
* Custom shortcode to display forms of all submitted entries for current user. | |
* | |
* Usage [wpforms_display_user_entries] | |
* | |
*/ | |
function ws_display_user_entries() { | |
global $current_user; | |
get_currentuserinfo(); | |
$email = (string) $current_user->user_email; | |
// Fetch all entries. | |
$entries = wpforms()->entry->get_entries( | |
array( | |
'number' => -1, | |
'order' => 'ASC', | |
) | |
); | |
ob_start(); | |
foreach($entries as $entry) { | |
$fields = wpforms_decode($entry->fields); | |
foreach( $fields as $field ) { | |
if ($field['type'] == 'email') { | |
$formEmail = $field['value']; | |
} | |
} | |
if ($formEmail == $email) { | |
$formID = $entry->form_id; | |
$forms = wpforms()->form->get(); | |
foreach ($forms as $form) { | |
if ($form->ID == $formID) { | |
echo $form->post_title . "<br />"; | |
} | |
} | |
} | |
} | |
$output = ob_get_clean(); | |
return $output; | |
} | |
add_shortcode('wpforms_display_user_entries', 'ws_display_user_entries'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment