[-] Check if current logged in user is within the users stored in a Custom Field on a Post

This is useful when you, for example, want to add more than an author to a post (using Toolset forms, it is not a backend ready solution)

For it to work you need a field that stores User (emails, in this case), with slug user-can-do

That field needs to be populated in any post with a commaseparated list of user emails like so

email1@email.com,email2@email.com,email3@email.com

Then, you can use the below shortcode in an HTML condition, to check if the current logged in user is within those users stored for the user-can-do field of the post.

function user_can_author( $atts ){
 
    //We get the current logged in user email, see https://developer.wordpress.org/reference/functions/wp_get_current_user/
    $current_user_email = wp_get_current_user()->user_email;
 
    //we get the value of the single line field saved against the post, with all those emails of users that an co-author
    //https://developer.wordpress.org/reference/functions/get_post_meta/
    //We get the ID of the post with get_the_ID(), see https://developer.wordpress.org/reference/functions/get_the_id/
    $field_value = get_post_meta(get_the_ID(),'wpcf-user-can-do', true);
 
    //We explode tha commaseparated string to an array where the email will be value of each key
    //https://www.php.net/manual/function.explode.php
    $field_values_array = explode( ',', $field_value );
 
    //Use below to debug the code
    //error_log(print_r($field_value, true));
    // error_log(print_r($field_value, true));
    // error_log(print_r($field_values_array, true));
  
    //Here we check if the current user email is within the emails stored for $field_value
    //https://www.php.net/manual/de/function.in-array.php
    if (in_array($current_user_email, $field_values_array)) {
        return true;
    }
    else {
        return false;
    }
  
}
add_shortcode( 'user-can-author', 'user_can_author' );

use this like so in an HTML condition after registering the shortcode in Toolset > Settings:

[wpv-conditional if="( '[user-can-author]' eq '1' )"]
   The current user has access to this post, display a form or link to a form
[/wpv-conditional]

Note, there is also a version of this where the field is stored in a user, and it saves Post Ids the user has access to, as seen here
https://toolset.com/forums/topic/grant-revoke-access-to-image-visibility-based-on-user/page/2/#post-1489243

Create Custom Select field with all users as Label/Value using wpt_fields_options

Use at your own discretion

The code requires a Select Field with Title Select a User and one option set.
It then completes the options of the Select Field with User Login Names as labels and User IDs as values.

Cannot be used for Views Custom Searches.

add_filter( 'wpt_field_options', function ( $current_options, $title_of_field ) {
    if ( $title_of_field != 'Select a User' ) {
        // not our "Headline Color" field
        return $current_options;
    }

    $users_objects_array = get_users();
    $users = array();

    foreach ($users_objects_array as $user_object_array) {
    	$users[$user_object_array->data->user_login] = $user_object_array->ID;
    }
    //error_log(print_r($user_id_array, true));

    if ( ! $users_objects_array ) {
        // no theme colors are set yet
        return array(
            array(
                '#title' => 'No users available',
                '#value' => 0
            )
        );
    }

    $new_options = array();
    foreach ( $users as $user => $user_value ) {
        $new_options[] = array(
            '#title' => $user . '-' . $user_value,
            '#value' => $user_value
        );
    }
    

    return $new_options;
}, 30, 2 );