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.
Related
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.
I'm completely new to the whole WordPress scene so I kind of don't know the "WordPress way" of doing the desired task:
Create a form where a user would fill in some details (such as name, surname, upload a video or post a youtube iframe link)
Submit it, once it's done - an admin must verify that everything has been filled out correctly and after that the video can be seen on the website.
Should I write a plugin of some sort that would do that or how does it happen?
Thank you.
The Gravity Forms plugin allows you to do exactly what you're looking to do. With it, you can set up a form that creates a post and sets it to be 'Pending Review' in WordPress. This tutorial contains everything you need to know about what you'll need to do.
If you want to create a Custom Post Type (ie. 'User Page') to better separate user submissions, you'll need to employ this special add-on (as mentioned in the tutorial above).
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.
I have a website based on Wordpress, built with pages. I need to have:
public content
pages that are only accessible to logged in users
pages that are only accessible to a certain subset of logged in users
I have accomplished this with Role Scoper. However, there is an important capability that this doesn't provide. I would like to be able to publish (say via email) a link to one of the "restricted" pages, and then when someone went to it, have the login screen presented and after successful login have the appropriate page displayed. With role scoper, if you direct a user to a restricted page they just get the "page not found" error.
Anyone found a good solution for this?
Use could use a couple of built in wordpress functions. The ones I'd choose are:
<?--php is_user_logged_in() ?>
<?--php current_user_can(...) ?>
is_user_logged_in() is a simple check that does exactly as it says, checks if the user is logged in. If they are, it returns true. If not, it returns false. Current_user_can() performs the same way; if you look at the capabilities on http://codex.wordpress.org/Roles_and_Capabilities you can simply use those to simulate user levels (there's another function that does this in a more direct way but I can't remember it off the top of my head.
Really, what I'm trying to get at, is that you can set up specific pages that have your content and perform a role check before the header loads. If you want to have them login before hand, you could generate a login url w/ redirect using <?--php echo wp_login_url( $redirect ); ?>, which would take them to $redirect after they login.
Personally I've found it easier to use plugins to achieve this. s2member (http://www.s2member.com/) is a good one to use, although for the best features there is a paid version.
How can I create a form that requires anonymous viewers to register in order to view it?
Right now, I've created a content-type (Submit Plan) which is a primary link available to everyone (anonymous + authenticated). I've restricted 'view' user permissions to anonymous users but they can still see the 'Title' input (I don't want that).
I'd like it so that when an anonymous user clicks on 'Adding a Plan' primary link (the Submit Plan content-type), it goes to the page and says:
"You must register for an account" OR
Redirects them to the registration page asking them to register to submit a plan.
I've been searching for a module or maybe some code to use but have come up short on this topic. Any help would be appreciated. Thanks!
If you're going to be redirecting users to the registration page, I'd strongly consider using something like logintoboggan to make the registration > node-creation process smooth. Otherwise, registration is a multi-step process and I'd imagine it being easy for users to lose their way back to the Add a Plan form in the process.
For the "show links or show the form" direction, there are at least two ways of approaching that: 1) create a custom page where you "import" the add_plan form (or show the links). 2) modify the node/add/plan page itself, either through themeing or the fapi (the forms api).
Here's a promising looking post for the first method: http://drupal.org/node/357895.
Here's a place to start with FAPI http://api.drupal.org/api/drupal/developer--topics--forms_api.html/6
Here's a post about theming the node form: http://11heavens.com/theming-the-node-form-in-Drupal-6
Without having tried this, I'd probably lean toward method one.
Update: just had another thought: you could also add the plan form to the registration form so they'd fill them out in one shot. I'm not sure of how to do that in general, but the node profile would work if they're only ever going to make one plan, and if not, you can look at how that's put together.
This can be done a few ways.
One, in your menu output, you can change the link to Submit Plan like this:
<?php
global $user;
if ($user->uid == 0) {
print 'Add a Plan';
} else {
print 'Add a Plan'l;
}
?>
The above code looks to see if the user object has a UID. 0 is anonymous, so that will print the link that sends them to register. Otherwise it will take them to the node add form for Submit Plan content type. This also assumes you control your own menu output. You can also override it in a similar manner by using a theme function.
There are a few ways you can do this, so start there and let me know what you think.