Last active
November 10, 2022 03:10
-
-
Save MoatazAbdAlmageed/036fb98b1c44f6a5f7954d711c92df38 to your computer and use it in GitHub Desktop.
fluentform shortcode
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
<?php | |
function getCurrentUserAllFormEntries() | |
{ | |
$query = wpFluent()->table('fluentform_submissions') | |
->select([ | |
'fluentform_submissions.id', | |
'fluentform_submissions.form_id', | |
'fluentform_submissions.user_id', | |
'fluentform_forms.title', | |
]) | |
->join('fluentform_forms', 'fluentform_forms.id', '=', 'fluentform_submissions.form_id') | |
->orderBy('fluentform_submissions.id', 'DESC'); | |
$query->where('fluentform_submissions.user_id', '=', get_current_user_id()); | |
$entries = $query->get(); | |
foreach ($entries as $entry) { | |
$entry->entry_url = admin_url('admin.php?page=fluent_forms&route=entries&form_id=' . $entry->form_id . '#/entries/' . $entry->id); | |
$entry->human_date = human_time_diff(strtotime($entry->created_at), strtotime(current_time('mysql'))); | |
} | |
return ($entries); | |
} | |
function getAllForms($exclude_ids = []) | |
{ | |
global $wpdb; | |
$ids = implode(",", $exclude_ids); | |
$query = wpFluent()->table('fluentform_forms') | |
->select(['id', 'title']); | |
if ($ids != "") { | |
$query->where(wpFluent()->raw($wpdb->prefix . "fluentform_forms.id NOT IN($ids)")); | |
} | |
return $query->get(); | |
} | |
function user_forms($atts = []) | |
{ | |
extract(shortcode_atts( | |
[ | |
'submitted' => false, | |
'exclude' => null, | |
], | |
$atts | |
)); | |
$exclude_ids_array = []; | |
if ($exclude) { | |
$exclude_ids = preg_replace('/\s*,\s*/', ',', filter_var($exclude, FILTER_SANITIZE_STRING)); | |
$exclude_ids_array = explode(',', $exclude_ids); | |
} | |
$user_submitted_forms = []; | |
$forms = getAllForms($exclude_ids_array); | |
$user_entries = getCurrentUserAllFormEntries(); | |
foreach ($user_entries as $entry) { | |
if ( | |
!in_array($entry->title, $user_submitted_forms) && | |
!in_array($entry->form_id, $exclude_ids_array) | |
) { | |
array_push($user_submitted_forms, $entry->title); | |
} | |
} | |
$list = "<ul style='direction: rtl; text-align: right;'>"; | |
if ($submitted == 'true') { | |
foreach ($user_submitted_forms as $title) { | |
$list .= "<li>$title</li>"; | |
} | |
} else { | |
foreach ($forms as $form) { | |
if (!in_array($form->title, $user_submitted_forms)) { | |
$list .= "<li>$form->title</li>"; | |
} | |
} | |
} | |
$list .= "</ul>"; | |
return $list; | |
} | |
add_shortcode('user-forms', 'user_forms'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment