• I’ve been searching and searching on how to create custom pages for the frontend for a userprofile page in WordPress. I know there like a million plugins that allows this, however, I need alot of custom functionality on the profile pages, so I would prefer not to use a plugin.

    However, I cant seem to find any infomation on how to create custom user profile pages in WordPress?

    Anyone that can point me in the right direction on how to create this?
    ———

    My scenario is this:
    A user creates a profile and fills out all information about themselves… Now, in the frontend I list all users (list-companies.php), and from here it should be possible to link to a users profile to read more about the users… (company-profile.php)

    So basicly all users should have their own personal profile page in the frontend… Hope it makes sense ??

    So the list of users would be:
    https://mydomain.com/companies/

    userprofiles:
    https://mydomain.com/companies/companyname/

    Any ideas on how to accomplish this?

    • This topic was modified 8 years, 1 month ago by ncdk.
Viewing 6 replies - 1 through 6 (of 6 total)
  • this can be done with custom post companies and taxonomies
    it will be like this
    create taxonomy with name companies and custom post type company (singular)
    you should use a plugin to make it easy to create them one i recommend is Custom Post Type UI .

    Thread Starter ncdk

    (@ncdk)

    Hmm, not quite. The users is actually companies, and therefore should not be custom post types…

    As mentioned, i need to list all users (Already haves this) – And then each company needs to have a link to their own profile page (frontend, NOT backend), which should contain information about the “user/company”…

    I thought about using the “author.php”, however it’s not authors I need, but actual registered users(companies) in the system…

    I guess, from the listview i would have a link like: https://mydomain.com/companies?id=XXXX and then create a custom page that gets the id and make a query to the database after this user…. However, then I dont get the “pretty” URL structure like so: https://mydomain.com/companies/companyname

    Really hope someone can help…

    • This reply was modified 8 years, 1 month ago by ncdk.
    Moderator bcworkz

    (@bcworkz)

    Just create a custom page template that has the necessary code to collect and save profile information. Add a page based on this template so there is a permalink to use to access the page.

    As for displaying user/company data through a pretty permalink, again, create a custom page template. Use the Rewrite API to convert the pretty permalink into URL parameters that the page code can get through $_GET.

    Thread Starter ncdk

    (@ncdk)

    So, i’ll create ex: page-company.php and then create a page in the backend using this template – Lets cal this “company” ?

    I my list, then I would create a link like: Link to company profile page – However, this still leaves me with a rather “ugly” link ?

    When a visitor click the link, then they would be redrected to https://mydomain.com/companies/company?userid=XXX – And then you would use the RewriteAPI for getting a pretty URL like: https://mydomain.com?companies/company/companyname ?? But how will you replace ?userid=XXX with the companyname?

    So when linking to the profilepage from the list would I then create a link like so: Link to profilepage

    Then how would I fetch the ID of the company on the page template, as I cant get the id from the querystring? ARGH, im confused ?? ??

    Im pretty new to the WordPress API, and never touched rewrited rules before, so im completely lost on how my setup should/would be for achieving what I want…

    Could you provide a small example perhaps? That would make me a really happy camper ??

    • This reply was modified 8 years, 1 month ago by ncdk.
    • This reply was modified 8 years, 1 month ago by ncdk.

    what i think you should do :
    -allow user to login and limit the access to wp-admin
    -in theme you can use author.php and check for role
    what you will use :
    *user role editor to create a new role and create custom capabilities
    *add_filter on authentication to wp-admin
    *and redirect the logged in user to login page that you have to create

    all the above can be done using plugin for membership like members

    Moderator bcworkz

    (@bcworkz)

    Don’t get overwhelmed with everything involved. Don’t worry, it’ll all work out. Focus on an immediate, small, achievable task. For example, just go with the ugly ?user_id=### URL parameter for now, pretty permalinks and rewrites can be added later.

    Let’s get the user/company information first. You need a custom page template. The only requirements are that it resides in the theme folder and has a comment header that has a line that begins “Template Name: ” followed by a name.

    On the template build a standard HTML form. The form method should be POST and the action attribute an empty value so the form submits to this same page. You can get the current user’s WP_User object with wp_get_current_user(). This object will contain some basic information about the user. Some of it can be presented as read-only information, like the login name, since no one can change it. Other fields are editable. Use the properties from this object to pre-populate form field values. Include hidden fields for security measures like verifying the user ID and a nonce value.

    You can add in security measures later, but the form should not be presented to regular users until security is in place. For now, a line that verifies the current user is you is enough. Just call wp_die() if it’s anyone else.

    You will be storing other values in user meta, or they already exist there. Get these values as well to pre-populate fields when they are available. Most of the page is displayed the same way regardless of whether it’s an initial GET request or after a POST submit. The one important distinction is POST request code needs to save the form data. This save the data section is managed as an if ('POST' == $_SERVER['REQUEST_METHOD']) conditional. Within this block is all code to take data from the submitted form (in the array $_POST) and validate and sanitize it prior to saving it in the DB.

    You’ll eventually need code to verify the user ID in $_POST matches the current user and that the passed nonce value is correct. If some users should not be able to edit their profile, then there needs to be a capability/role check as well.

    To start with, maybe your form only has a few fields. If you can successfully present existing data in the few fields and save updated data upon submit, then it’s time to celebrate! Now it’s just a matter of adding in more fields and doing security checks.

    Presenting a selected company profile to visitors is not that different than the profile form, except there are no form fields or POST requests. But you still get the saved data from the DB and output it in an organized manner. After the profile form, this page should be easy.

    Which leaves us with the company listing page. It’s going to be much like a post archive template, except the query will be for users instead of posts.

    Once you get these three pages working in a very rudimentary way, it’s just a matter of improving upon the basics, one step at a time. Don’t sweat all the little details involved, solutions exist. Just focus on the immediate goal you are dealing with, forget about the rest. Eventually, everything will come together ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘create a profile page for users?’ is closed to new replies.