Creating user profile pages in wordpress - wordpress

What I'm trying to achieve is to make each user on the website(the wp-users) have their own unique front-end profile pages like so site.com/user/userX. (EDIT: To clarify, it is not a settings page that only the user himself can see, it's a open profile page for logged users or anonymous/visitors to access and see its profile)
I thought about using the url GET (site.com/user?name=userX) in a post but wordpress doesn't seems to understand "?..=.." and says page doesn't exist. This solution does not look like a good practice in wordpress so I'm trying to look from another perspective.
Even tho there are a couple of plugins there that would do that for me and more, I'm stuck with doing manually since I'm building a multi-language website (using Polylang), so plugins will only work in the main language.
Briefly, Polylang keeps track of the language through url, ex.: site.com/langX/pageX, and the plugins I've tried are stuck to one page only.
I'm inclined to say what I'm looking for is a way in the functions.php to make Wordpress understand that a page .../user/ will expect a name right after .../user/userX like that I can use the same function for multiple languages : ...langX/user/userX, ...langY/user/userX ...
I'd be glad if someone could put me in the right direction of what should I be looking for.

for security you should create a new route in wordpress :
function custom_rewrite_basic() {
add_rewrite_rule('^user/([0-9]+)/?', 'index.php?user_profile=$matches[1]', 'top');
}
add_action('init', 'custom_rewrite_basic');
function custom_rewrite_tag() {
add_rewrite_tag('%user_profile%', '([^&]+)');
}
add_action('init', 'custom_rewrite_tag', 10, 0);
Now, you can access the same page as :
http://example.com/user/95
this code in your theme :
get_header();
global $wp_query;
if($wp_query->query_vars['user_profile']) {
//do stuff
}

From my understanding, what you can try is to create a page from dashboard, named user or something. Once users are logged in, you can get user info in session or you can use the query vars as you mentioned above. You can create custom page templates in Wordpress and assign that template to the page. In this page template write the frontend html-s with required logic. Routing in WordPress is normally handled by WordPress itself. So creating a page will make that route say yoursite.com/user available for you. Please read on page templates from the below link from WordPress documentation.
https://developer.wordpress.org/themes/template-files-section/page-template-files/
UPDATED ANSWER
As per the comments
Create a custom post type which holds the data(users)
When a user registers, create the entry for users post type, link user id to that post type entry with a post meta. You can set a unique url for the user by setting the slug as you need.
Provide users the ability to edit only their own data. You can check the post meta which connects user id with that particular custom post type item.
If a user gets removed, delete their custom post type entry as well, so that nothing remains in the DB related to the user.

Related

is there anyway to send notification of new Post is published in wordpress to another page of same website?

I'm creating a wordpress plugin in which i want that if new post is published the notification gone on another page of same wordpress website.
Thanks
There is a few ways todo this. But I would do it this way.
When you create a post, you add a post_meta to that post that tells that this page is new.
Then you have an cronjob or something that is running an wp_query that are searching for all posts that have that post_meta. And when it finds the new post/posts it either clear that post_meta or set it to false.
And then on the page that you wanted to display it somehow, use that cronwork to update that page or something like it.
Hard to describe more when I don't know what that other page should do with the information about the new post

Wordpress - Proper way to manage custom users

I have a site in Wordpress.
The functionality I need is such that, I can create 'users' of the site. These users have no purpose editing the Wordpress site in any way, and don't need to know we're even using the wordpress platform.
These users need to be able to edit their contact info and upload/view/swap out their own resume, using a page that I will build for them (not the wp-admin dashboard in any way). This resume will be PDFs and WordDocs.
At first I thought I'd just use the built in Wordpress Users and Roles that Wordpress offers. However, I'm not sure how I would attach resumes to that user, and let that user edit their own resume. I know I can use the 'user_contactmethods' hook to attach basic fields. However, I'd be trying to attach a link to a file that Wordpress hosts, and would need to be able to replace that file on a whim, in php. Also, my goal is to prevent them from ever using the Wordpress dashboard or editing tools.
Next, I thought I could create a custom post type for a 'SiteUser'. That would make it easy to manage a PDF/WordDoc attached to that post type. Also, that user wouldn't have any way to access the Wordpress stuff. Before I do that though, I wanted to ask on here if this really is the right way to do this.
This solution feels hacky.
Can I get some proposed solutions to this problem that could be perceived as 'the proper way'?
Thanks
Here is a rough idea of what you are looking to do.
Step 1
Create the user role for these new users
Step 2
Set the permission for them and disable backend access and redirect all access of those roles to a custom page /account/
Step 3
Use Advance custom fields plugin to create some custom fields on the user meta. (text, file, image)
Step 4
Apply some login logic/form and Link to a /account/edit-info/ custom page with the acf frontend form. https://www.advancedcustomfields.com/resources/create-a-front-end-form/
Step 5
Use these info to display somewhere on the /account/ page
Optional
Using gravity forms instead to manage user data entry gives better control but requires more coding, and a better user experience.
Front-end Admin Steps
Repeat Step 1-2
Loop site user and list them and their custom field files Have a button that opens a Gravity form with the user ID text field pre-populated and hidden, and have a file uploader element.
Add backend hooks after validation directly replace the user meta
containing the file path or ID (however you choice to store it in
Advance custom fields)

Create master-detail page in wordpress

I'd like to create a master/detail page in my wordpress site. In other words, when someone clicks a username from a list of names,that link will take them to a page with the user's complete details, how do I create a link for each user displayed that will open a details page about JUST that user? I dont want any code or anything like that, just a pointer as to which wordpress functions i should be looking into. i would really love to do this without a plugin, but if theres no other way then im willing to go that route. ive searched on google but found nothing relevant.
First of all you should get all users using get_users.
Then you need to cycle trought this users using foreach or while ( it doent's matter which one you will choose )
In your cicle you should get create a link tag and add the author link using the_author_meta( $field, $userID ); where the $field will be replaced by user_url.

Modify custom field from front end

If I need to manage a custom field under wordpress, but not from the admin area. In other words, I need that users modify the content of post custom fields from front end. What is the way to do so?
As instances, please to imagine Stackoverflow.com as a wordpress site. Under this site, the number of upvotes/downvotes and the accept state are my 2 post custom fields. How can I make the front end user modify their values in WP database?
Please If you have another better approach to create votes system and accept system, using wordpress, it will be highly appreciated. But if my approach (using post custom field) is okey, please to guide me find documentation from web or codex to achieve my goal.
Thank you for your usual help.
I would suggest thinking about a couple things:
Each post should show the sum of up-votes and down-votes
Each user should only be able to up or down-vote once (i.e., one user can't vote the same post up a hundred times)
You think you would want to create a function for your theme that allowed users when logged in to alter the metadata of a post. However, this isn't really the case – what you need to do is to allow users to edit an element of their own metadata (see add_user_meta) that is basically just a hash. The metadata could be like array("post-666-vote" => -1, "post-777-vote" => 1) for a downvote of post 666 and upvote of post 777.
So, when loading each post, your vote-tally-renderer would look something like this:
vote = get_post_meta($user_id, "post-" . $post_id . "-vote", true);
if(vote == -1) {
// Render down-arrow voting
} elsif(vote == 1) {
// Render up-arrow voting
} else {
// Render normal arrows
}
Each arrow would probably have to make an AJAX request to update the post's metadata. This is a long tutorial (but it's not super complicated! I promise!) and about 3/4 of the way down it talks about how to use an AJAX request to modify some user's metadata. http://wp.tutsplus.com/tutorials/plugins/a-primer-on-ajax-in-the-wordpress-frontend-actually-doing-it/
The only real major change is that the PHP function that is called by the WP AJAX request would also need a callback function to update the post's metadata, and change the number of votes on the post itself. This way, when the page is reloaded, it will show the proper number of votes.

Adding custom user options to wordpress

I am trying to add a custom field to the wordpress user profile page. For instance if I wanted to add a field where the user could put in their Linkedin, or Twitter user name, then use that value whenever the user posts a comment, or if the user is an author, to add that value in their posts.
I have a forum (bbpress) integrated so I would also like to use this value to customize the users avatar in the forums.
I am looking at the way Wordpress uses Gravatar. I would like to do something similar. However, I'm not sure where to start. I've written a couple of shortcode plugins in the past, but nothing this complicated.
Anyone have any ideas on where I should begin on this?
look at this post and this

Resources