Problem: I have a new User CRED form that allows guests to register. When they submit the form, I would like to automatically create a custom post that includes information from the form, and I would like to restrict access to that post to the created member only.
Solution:
1. Create a Custom Post Entry for "Band Name" on Member Registration.
This can be accomplished with a bit of custom code using the cred_save_data API.
add_action('cred_save_data', 'my_save_data_action',10,2); function my_save_data_action($post_id, $form_data) { if ($form_data['id']==1234) { $my_post = array( 'post_title' => $_POST['some_custom_input'], 'post_status' => 'publish', 'post_author' => $post_id, 'post_type' => 'band-post-type-slug' ); // Insert the post into the database wp_insert_post( $my_post ); } }
1234 should be changed to match the numeric ID of your User CRED form, and 'some_custom_input' should be changed to match the name of an input containing the data you would like to use in the Band post title. The data in the $my_post array can be modified according to the wp_insert_post documentation.
2. Only allow the registered Member edit his own Band Page.
In the code I provided above, I have configured the new post's author to be automatically set to the User that was just created during registration. Once this registration form is up and running, you should be able to use Access post and form restrictions based on the post Author (Member can edit own vs Member can edit any).
Relevant Documentation:
https://developer.wordpress.org/reference/functions/wp_insert_post/
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
https://toolset.com/documentation/user-guides/setting-access-control/
https://toolset.com/documentation/user-guides/access-control-texts-inside-page-content/
https://toolset.com/documentation/user-guides/access-control-for-cred-forms/
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.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 5 réponses, has 2 voix.
Last updated by Christian Cox Il y a 6 années et 4 mois.
Assisted by: Christian Cox.