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.
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'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.
I have a Wordpress site and what I would like to do is for users to send their email address through a form and then my email client would send automatically message them with a link to a certain page. That page should not be accessable without that link. Is that possible to do and are there any ready plugins for this? I use a members plugin, but I want users only to give their email and not to fill out a whole form. Hope you understand. Thanks. w
The better route is to just use the built-in sign-up system. Is there some reason that didn't work for you?
Short of that, here is a quick and dirty approach...
To send mail to a user, just put the following PHP code in a page:
mail($_GET['user_email_address'], 'Access to site', 'To access the site please use ' . get_bloginfo('url') . '/foo.php?access=1');
The first parameter assumes the page that calls this has an textbox with the name 'user_email_address'. The subject and content of the mail follow; you can change them to reflect what you reallyw ant.
Then on the page you want to restrict access to, put the following code at the top of the file:
if (!isset($_GET['access']))
wp_redirect(get_option('siteurl') . '/wp-login.php?action=register');
This redirects anyone who doesn't have the get parameter access. This system has two main shortcomings:
you can easily copy/paste and share this URL and anyone will be able to bypass the e-mail
if you try to return to the page later you won't be able to get to it without the get parameter
If you provide more details on why the built-in registration system didn't work, I might be able to help better.
-Kevin
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.
Can anyone recommend me a good members-only plugin? I want to hide pages (and their tabs) if users aren't signed in.
So far I have found:
'Member Access' which doesn't hide the tabs
'wp-members' which wouldn't work with 2.8.4
'user access manager' which was too complex clunky to be useful.
There should be something basic out there for what I need, but no luck so far.
Justin Tadlock is a WordPress heavy (wrote the popular Hybrid theme framework), recently released a comprehensive user management plugin called Members, which among other things can turn your blog into a login-only venue:
Private Blog: Allows you to create a
private blog that can only be accessed
by users that are logged in (redirects
them to the login page).
But I get the impression that you're looking to keep some part available to the public users and other parts only for registered users.
You can also use this plugin to restrict certain areas of your blog, screenshot example here: based on role
Hiding the tabs from the public user is the challenging part. Themes typically aren't designed with private portions in mind; you'd have to hack it yourself or get someone to do it for you.
If are familiar with php and WP structure, you can add a few lines of code to a few template files to redirect users to login page if they are not signed-in. Let me know if you want to go that way. I can try to provide sample code. Are you using one of the basic themes?
I have a plugin called "LJ Custom Menu Links" that can do what you are asking. However as the name suggests they are custom links, so you would have to hand add the pages you want. But it does/and can only show a link when a user is logged on if that is what you want. Combined with "pagemash" plugin which will hide pages from the menu generated by WP itself leaving only the pages linked to by the LJ Custom Menu Links plugin.
However I was under the impression if you made a Page private then it wouldn't show up unless someone was logged in, or am I wrong on that one?
A good option is to use three difference plugins:
Member Access
Register Plus
AJAX Login Widget++
You can find my post on all these here:
http://sbhosting.com/wordpress-member-area/
Try CMS Members
I know it hide some pages for non-members.
A paid option is this. It's VERY good. I use it on several websites. Called Wishlist Memeber
For me s2member does the job. You don't have to use the paypal option, you can stick with free membership.