Skip Navigation

[Resolved] Member Personal Profiles

This support ticket is created 3 years, 11 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.

Our next available supporter will start replying to tickets in about 2.33 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 8 replies, has 2 voices.

Last updated by Beda 3 years, 11 months ago.

Assisted by: Beda.

Author
Posts
#1603183
userprofile workflow.jpg

Tell us what you are trying to do?
I'm trying to create individual user profiles. I'd like them to be automatically created when a new user registers with all related registration fields already filled out.
Is there any documentation that you are following?
N/A
Is there a similar example that we can see?
N/A
What is the link to your site?
hidden link

I also have a workflow with some notes I made to help clarify what I'm trying to accomplish. My debate here is if I should build my own custom profiles or just use something like buddypress/buddyboss for user profiles instead.

#1603855

With Toolset, you could have a form that creates a user on the website, as you probably already have used (see https://toolset.com/documentation/getting-started-with-toolset/publish-content-from-the-front-end/forms-for-registering-users/)

This won't create a Post Type for the user.
It would require custom code to do so on the fly, and hence, it is indeed questionable if it's not better fall back to an existing solution like BuddyPress.

It depends a lot what you want the user and the data to be, act and look like.

We do actually have an extensive DOC that elaborates on one possible approach, which is generally intended to be used when you want to create searches through your users, which is not possible if those are WordPress native Users.
See https://toolset.com/documentation/post-relationships/how-to-create-custom-searches-and-relationships-for-users/
It uses a Custom Post Type as a replacement for the user

This could be a solution to your project. If not, you'd need to fall back to some Custom Code hooked to cred_save_data() for example, in order to grab the user data on user profile creation and programmatically add the Custom Post.

#1604607

Hey Beda,
Thanks again for your help on this.

I did see that documentation and took note of it. It does seem to be something that I'd like to do. The only difference is I would like the custom post to be created when the user creates their account. I'm kind of stuck on this part.

What I've done thus far is created a custom post type called "Members" and a couple of users to see if it works properly. They do work as intended:

hidden link
hidden link

I had to manually create these "Members" custom post types. So, it does work as far as I can tell - but I just need to add a function so that it automatically creates the custom post type and gives the post authorship to the person who made an account. I'm not sure where to start on this part.

Thanks again for your help.

#1604621

Hunting around I found this code I think could work but I'm not 100% sure. I believe this code is to create a "post" on cred_save action. I think I'll have to modify it to make a new "member" custom post type on save vs a "post".

Ideally, I will only need to pass :
1.) post_title - would be the member name or nickname field
2.) post_status -
3.) post_author - Would not need to be 1 but the actual user ID who creates the account

The rest of the fields can be filled in later by the member as they see fit.

add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
    // change this 12 to the actual id of your form
    if ($form_data['id']==77)
    {
// You may need to modify the post author and post categories for your needs
$my_post = array(
  'post_title'    => $_POST['post_title'],
  'post_content'  => $_POST['post_content'],
  'post_status'   => 'publish',
  'post_author'   => 1,
  'post_category' => array( 8,39 )
);
  
// Insert the post into the database
wp_insert_post( $my_post );
    }
}

PS. - Thanks for taking the time with me on this. I'm not a php expert at all so I'm actually learning some of this php as I go. I appreciate your patience with me.

#1604799

So far I've modfied the code and it works. However; I still can't seem to get the custom toolset fields to be automatically populated with the values.

I'm trying to get the registration form data to populate the custom post type field.

//**New User Profile Creation When User Registers **// 
add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
    // change this 12 to the actual id of your form
    if ($form_data['id']==77) 
    {
// You may need to modify the post author and post categories for your needs
$my_post = array(
  'post_type'     => 'member',
  'post_title'    => $_POST['nickname'],
  'post_status'   => 'publish',
  'meta-key'      => 'wpcf-nickname',
  'meta-value'    => $_POST['nickname'],
  'post_author'   => $post_id
);
  
// Insert the post into the database
wp_insert_post( $my_post );
    }
}
#1604899

So, I managed to dig around and put together this code. It does work when a new user creates an account using my Toolset User Form - the custom post type "member" is created with the correct information - including custom toolset fields.

My next question is - how can I add to the function(or create another one) that says - "If a user updates his/her toolset fields then update wordpress account fields also" ?

Thanks again for the help here.

 
//**New User Profile Creation When User Registers **// 
add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
    // change this 12 to the actual id of your form
    if ($form_data['id']==77) 
    {
// You may need to modify the post author and post categories for your needs
$my_post = array(
  'post_type'     => 'member',
  'post_title'    => $_POST['nickname'],
  'post_status'   => 'publish',
  'post_author'   => $post_id,
  'meta_input'   => array(
                    'wpcf-nickname'      => $_POST['nickname'],
					'wpcf-first-name'      => $_POST['first_name'],
					'wpcf-last-name'      => $_POST['last_name']
                ),
);
  
// Insert the post into the database
wp_insert_post( $my_post );
    }
}
#1605183

I'm sorry the delay.

While it's correct that if you want the User Form to create a Post for the user and edit it - you will need Custom Code.
Your approach above is correct in that perspective.

However - if I may - you could do this without code.
The user (your visitor) will not recognize the difference.

1. Create a user form that lets new users create a real user account on your system. This is a classic "add new user" form, but it has only the very few required fields that WordPress core wants to create a user. Don't include any specific "post" information yet (data that you will require on the "members" post later).
2. Make sure to redirect this user to a Page with another form - this form, in turn, creates Member Posts.
The easiest here is to redirect to a page. On this page, your "create new member post" form is already inserted, and holds all the fields to fill for members.
3. Given at this point the user has an account, the user will be author of that Member post (with this you have the connection to the user). The user can now add all member data and creates the member post.

Similarly, you can edit users and posts by chaining the forms.

For the user, if you submit buttons of the forms are using smart labels, like on the first form you could use "Proceed" instead of submitting (and indeed this would already create the user), and on the second form, you could use "Finalize", which indeed would create the post.

This is one way to do it without custom code.

Now, if you want to do this with code, there is nothing wrong with it.
I see you already managed to create the post on form submit with all fields (you could use update_post_meta() for the fields, as a different approach, but I see everything works fine).

Now I see that you would like the same with Edit forms (https://toolset.com/forums/topic/member-personal-profiles/#post-1604899)
When you update (the USER profile thru a USER Form), you'd just use the wp_update_post() in the function like you used wp_insert_post.
https://developer.wordpress.org/reference/functions/wp_update_post/

But, you could also do the opposite, edit the post with the form and update the user with code.
In this case you will need to use methods like update_user_meta() and wp_update_user()
https://developer.wordpress.org/reference/functions/wp_update_user/
https://developer.wordpress.org/reference/functions/update_user_meta/

I have actually a quite large code snippet for something similar, inclusive very complex checkboxes fields, here:
https://pastebin.com/wz6dQVBE
Maybe this helps as a reference?

Please let me know if with this information you can proceed!

#1606013

Hi Beda,
No worries on the response time. I'm sure you guys stay busy with all the customers. I appreciate that.

On the suggestion that I don't use custom code (obviously that is the better scenario) - When a user creates their account using the toolset user form - how do they then create a new member custom profile post? I assume they need to be logged into the site in order to do this? (I am trying to understand the flow while maintaining spam protections) So a "first log on redirect" ?

I'm basically trying to build a fan anime site where members have their own custom profiles. On these profiles I want to have some anime related information as well as anything on the site the user does - ex. upload a video, submit a post, show forum topics etc.

Last night I was playing around with the Toolset Blocks and made a Content Template for single member profiles. It works great for visually editing but it's not ideal for more in depth custom html. For example, I'm not able to include custom field data into a gutenberg column for inline styles. I did this using the old Content Template editor that was strictly HTML/CSS. I was able to use a custom profile field "Cover Image" to make the background header of the profile the image a user uploaded using inline styling.

Thanks again for all your help, I really appreciate it.

#1606711

1. On the suggestion that I don't use custom code (obviously that is the better scenario) - When a user creates their account using the toolset user form - how do they then create a new member custom profile post?

My apologies if I was not clear on this point.
This is explained in my #2 above:
Make sure to redirect the (User) Form to a Page.
In that page, you want to insert the Form that creates Posts.

This is how you can make the users create a new member custom profile post.
You're right that they need to be logged in for this to work smoothly (they could be logged out, but it would make the auto-population and especially the authorship more tricky).
What you can do here (my apologies for not thinking on that earlier) a code snippet to automatically log in the user or well, make him/her login after the user is created (although this might interrupt the nice workflow.
A code snippet of this kind can be found here https://toolset.com/forums/topic/automatic-login-upon-cred-user-form-submission/#post-902725

Related to the old way in content Templates, where you could use ShortCodes to even populate a class attribute of HTML... to be honest, these are things that WordPress does not like and never liked. Toolset makes it possible thru a quite advanced "do_shortcode" replacement (wpv_do_shortcode) which mainly is allowing the recursive (and safe) usage of ShortCodes, so you can nest them and even use as HTML attributes or HTML in the ShortCode attributes.
Strictly speaking however it is not suggested to use ShortCodes like that, and I would (if possible) try to avoid it as much as possible.
I know that it is a powerful "feature", but those things will now all come (where there are none already) into Blocks.

You can already set a lot of dynamic sources in the different blocks, like using a dynamic link or button text, just as a small example, up to very complex (and dynamic) settings for Image Blocks or Grid Blocks etc.

It's right however as well that Blocks, Gutenberg itself is not intended towards "advanced HTML editing", but the exact opposed of that, "simple visual editing", is the Goal.
Honestly, I have a hard time using it as well, it's nice, but as you say not as in-depth as "raw" stuff. However one might argue the same looking at the difference of PHP to (old) Views. You could say, it's just less powerful than real PHP. On the other hand, you gain lots of time Using Views, instead of coding a query.

Similarly, I use Blocks now. I use to create CT's (Content Templates) and use them like "custom-designed lego bricks" allover my templates.
This allows me to design single aspects with a visual builder and produce nice HTML and CSS in no time.
Then (and this is unconventional) I put this together in Toolset Layouts using Content Template Cells - but you do not need Layouts to achieve the same result.
You can simply insert several different Templates as Blocks directly in another Template applied to your posts.
With time you have a library of Content Templates that you can even re-use, as said: like lego bricks

Before, those bricks where shortcodes, now it can be entire visual templates.
It takes a bit of time to get used to the new idea, but I think (with a few missing features) it is really great to design things.

Please let me know if I can help any further!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.