[Resolved] How to pass ID of the person performing the edit
This thread is resolved. Here is a description of the problem and solution.
Problem: I would like to capture information about the User who submitted a CRED edit post form so I can moderate submissions efficiently from wp-admin.
Solution: Use a generic field in the form to capture the current User's ID, then use the CRED API to do something with that information.
This support ticket is created 6 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
I have a simple edit form that registered users can go about updating vehicle posts.
I want to be able to capture the person who made the edit, so I can credit them as a contributor. Im guessing I need to pass the user ID or something via a hidden form field???
At the moment, the edits come through pending approval, in which case I approve them as admin, but I have no idea who made the changes.
Thanks guys - this really is a brilliant piece of software!!
Hi, sure you can do this with a generic hidden field in CRED. You can supply any Views shortcode as the value of a generic field, then capture the value in a cred_save_data hook.
Here's a generic field that captures the current User's ID:
Here's a cred_save_data hook where you can access this information in PHP:
add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data) {
$forms = array( 12345 );
if ( in_array( $form_data['id'], $forms ) )
{
// do something with the editing User ID
$editor_user_id = $_POST['userid'];
// your code goes here
}
}
Replace 12345 with the numeric ID of this CRED form.
As far as what you do with this information, it depends on what you actually want to accomplish. You can set the editor to be the author of the post, or you can set some custom field value on the post to be the editor's ID, or you can add the editor's ID to a repeating custom field on the post that tracks all the editing Users.
As Christian is currently on vacation at the moment, I will be handling this ticket.
A quick question is this being updated on the frontend by a different author ? As if its done by a non-admin person then it should show a different user here under the revisions.
Also you want to store the ID of the last person who performed the edit correct?
A quick question is this being updated on the frontend by a different author ?
Yes. Multiple authors, all on the front end - much like contributors.
As if its done by a non-admin person then it should show a different user here under the revisions.
Correct.
Also you want to store the ID of the last person who performed the edit correct?
I guess so, although Im not quite sure if thats necessary? I just want to see who made the update in revisions as shown. Because Id like to list them as a "contributor" to the content.
Because the post is being submitted as "pending review" and not actually going live.
Then of course as the administrator, Im clicking on publish, which is why its probably showing me instead.