I understand that when the consultant publishes the company CPT they want to run the code after the form is submitted to add the matching user as a second author of the company post, but the question is, how does the consultant specify which user that should be?
I guess you could add a generic select field where the value is the user id and the display value the username, so the consultant can select that user in the form, and then when the form is submitted the user ID (required for the custom code to assign the second author) would be available.
To do that, create a View which lists users. For the output section you will need to output the results in a JSON format that can supply the options to a form generic select field, like so:
<wpv-loop>
[wpv-item index=1]
{"value":"[wpv-user field='ID']","label":"[wpv-user field='display_name']"}
[wpv-item index=other]
,{"value":"[wpv-user field='ID']","label":"[wpv-user field='display_name']"}
</wpv-loop>
You will need to check the option "Disable the wrapping DIV around the View" to get clean output without wrapping divs.
The edit your form which publishes the company CPTs and insert a generic select field, specifying the shortcode to insert this View as the source of the options. That will produce something like this:
[cred_generic_field type='select' field='users']
{
"required":0,
"options":[ [wpv-view name='Users'] ]
}
[/cred_generic_field]
Then you will need the custom code to assign the selected user as an additional author.
I don't have the plugin and so this is untested, and is just an illustration of how you might adapt their code to work with the Forms API, if it doesn't work you'll need to study the code and do some debugging to identify why.
/**
* Custom form action
*/
add_action('cred_save_data', 'tssupp_form_submit', 10, 3);
function tssupp_form_submit($post_id, $form_data) {
use PublishPress\Addon\Multiple_authors\Classes\Objects\Author;
use PublishPress\Addon\Multiple_authors\Classes\Utils;
if (in_array($form_data['id'], array(53))) { // Edit form ID
$user1_id = get_current_user_id();
if ( isset($_POST['users'] ) ){
$user2_id = $_POST['users'];
$authors_list = [];
$users_list = [$user1_id, $user2_id];
foreach ($users_list as $user_id) {
$author = Author::get_by_user_id($user_id);
if (is_object($author)) {
$authors_list[] = $author;
}
}
if ( ! empty($authors_list)) {
Utils::set_post_authors($post_id, $authors_list);
}
}
}
}
Let me know if it works in case others are looking for a similar solution.