Thanks for the response. I'm capable of adding a pre-made php snippet and using a custom shortcode... but that's my technical ability limit unfortunately.
I'm attempting to do all of this within a view. The idea is that IF the current user is the module leader then they will see a delete link.
I just can't get the conditional logic to work. I can get the name of the module leader easily, and I can get the name of the current user easily. But the problem is that the name of the module leader is being driven by entry ID where as current user is driven by user ID. So although the two values look the page, they are in fact differnet things that I cannot compare in a conditional statement.
What you want to use is a variation on https://formidableforms.com/knowledgebase/php-examples/#kb-show-content-based-on-current-users-role
The remaining question is what is the logic in the PHP program that figures out if the user attached to the entry id is the module leader. When you say "current user", do you mean that the view is only displaying one entry at a time, i.e., the user logs in and sees his/her own data vs. a user logs in and sees a table of entries for all sorts of users?
So I'm actually already using that snippet to make a delete link appear if the user has a 'Lead Subscriber' role. I have a view with many modules (training course titles) appearing in a list, powered by the module form. And then I have a view which displays which resources are linked to that module (powered by a module links form).
To be clear, module leader is not a user role. The Module form has a field for who the module leader is. This is a dynamic field pulling from the registration form. So all I need to do is check if that field contains the same user as the current_user. But my issue is that the dynamic field pulls entry ID whereas Current_user pulls user_id. Therefore even though both results display the same name, I cannot check that the two are equal.
Thanks for your help so far.
While this is tough for me to code this solution in absentia, the following seems like it might work, though it's completely untested and not even checked for syntax errors:
// $entry_id needs to be passed in via the frm-condition shortcode
$current_user_id = get_current_user_id();
global $wpdb;
$items_table = $wpdb->prefix . 'frm_items';
$sql = "SELECT user_id FROM $items_table WHERE id = $entry_id";
$userIdFromDynamicField = wpdb->get_col($sql);
return $userIdFromDynamicField == $current_user_id;
Please login or Register to submit your answer