A client of ours is currently using Rolescoper as a WP plugin to manage users' access to various "private" pages and posts. However, Rolescoper hides posts/pages from view unless the user is logged in. We're looking for a plugin that shows all the posts/pages but shows a "access denied" message with a prompt to log-in afterwards.
Here's a list of the requests verbatim:
Create User Account: username/password
Assign user to a page that is private
I want the private page to still appear in the navigation, even though a user may not be logged in.
Once a private page is clicked, they are prompted to enter their username/password. Once they do, they are then redirected to that page.
This would also need to be applied to document uploads
Any ideas? I did some Googling/WP plugin searching without much luck.
Thanks!
Maybe rather than using a plugin, try reworking your template to use is_user_logged_in?
I know this is a very old question, but for anyone else who finds it, I'll take a swing.
You could add to the beginning of your while statement in your single.php file a "Private" category check and "User Logged In" check, like so (NOTE: redirects to login page if user not logged in and category on post is set to "private"):
while ( have_posts() ) : the_post();
if(in_category("private")){
if(is_user_logged_in()){
get_template_part( 'content', get_post_format() );
} else {
auth_redirect();
}
} else {
get_template_part( 'content', get_post_format() );
}
Is User Logged In?
In Category X?
See also: auth_redirect()
Hope this helps!
Related
I have an upper navigation menu with a logout link, when I click it first a message pops up asking me if I'm sure I want to log out. How do I bypass this message, remove it completely have logout automatically to the homepage? What link can I put in the logout menu link?
Currently it is this: http://website.com/my-account/customer-logout/
This maybe happens because you are forgetting the neccessary nonce in the URL, which is being checked in wp-login.php:
case 'logout' :
check_admin_referer('log-out');
...
You should use wp_logout_url in order to retreive the URL including the nonce. If you want to redirect to a custom URL, simply pass it as an argument:
Log out
Another thing, you may also use wp_loginout which generates the link for you including translation:
echo wp_loginout('/redirect/url/goes/here');
That´s it.
Best regards.
Since duplicates are permitted from one site to another, I'm posting this answer based on the original work here: https://wordpress.stackexchange.com/a/156261/11704
Based on your question, it sounds like you want a Log Out link to appear in your nav menu.
In order to do that, and for that link to contain the proper NONCE (which is missing in your case, and is why the "Are you sure you want to log out?" message appears), you'll need to create a plugin or modify your theme.
Add the below code to your custom plugin file, or your theme's functions.php file:
// hook into WP filter for nav items
add_filter( 'wp_nav_menu_items', 'my_loginout_menu_link', 10, 2 );
// modify links in nav menu
function my_log_in_out_menu_link( $items, $args ) {
// only do this if it's the "main" navigation
if ( $args->theme_location == 'primary' ) {
// if the user is logged in, add a log out link
if ( is_user_logged_in() ) {
// use the official WP code to get the logout URL.
// passed-in argument will cause it redirect to home page
$items .= '<li class="log-out">'. __("Log Out", "your_themes_i18n_slug" ) .'</li>';
} else {
// if the user is NOT logged in, add a log in link
$items .= '<li class="log-in">'. __( "Log In", "your_themes_i18n_slug" ) .'</li>';
}
}
return $items;
}
I had a developer write a plugin for registered users to upload videos to their private profile page that would appear in the public video gallery. The developer has gone MIA so I can't get him to modify the code. He gave me a [shortcode] that I placed in the private profile page that gives the users the ability to upload, delete videos, etc.
Now that I need those user videos to display also on their public profile page, they won't because of some code in his plugin that checks if the user is logged in. If any user is logged in, they can see their videos on their public page, but no one else can that's not logged in. Users not logged in see a message saying they must be logged in to have the video functionality. I think I've identified the code below in the plugin that's causing this:
public function videoAdd() {
global $wpdb;
$current_user = wp_get_current_user();
if ($current_user->ID == 0) {
$view = new View(dirname(__FILE__) . '/views/not-logged-in.phtml');
return $view->render(true);
}
My question is (because I can't write php code), can else if statements take care of this by specifying a page name? For instance, if page X, require user to be logged in to upload, but if page Y, only display the user's videos. Here's some example code I found that looks like it can be modified to work, but I'm not savvy enough to do it:
<?php if ( is_page(123) ) {
?>
<div class="option one">my content</div>
<?php } elseif( is_page(124) ) {
?>
<div class="option one">abc content</div>
<?php }
else {
echo '<div class="option one">any content</div>';
}
?>
Can anyone please help me with a code example to make this work?
Yes, you should be able to do this. is_page() accepts both the page ID as well as the page name.
So you could do something like this:
is_page(123)
Where 123 is the ID in the page's URL. For example, in the Admin area: https://your-site.com/wp-admin/post.php?post=123&action=edit, you'd use the string of numbers after post=.
You can also identify a page by URL name. For example, the page https://your-site.com/about-us/ could be identified like this:
is_page('about-us')
Hope that helps!
I have set up our bakeries web store in a way that any woo commerce page is only accessible for logged in users. Now I am looking for a way to change the title of h1 on the My Account page in order to display something different for not logged in users. Has anyone an idea how to achieve that? Thanks for your input! Saludos!
Wordpress has a built in function to check if a user is logged in.
<?php
//Built in Wordpress function that checks if the user is signed in
if ( is_user_logged_in() ) {
//If the user is logged in
echo '<h1>Logged in title</h1>';
} else {
//If user is not logged in
echo '<h1>Not logged in title</h1>';
}
?>
You will need to modify the Woocommerce template by overriding it.
Example: To override the admin order notification, copy: woocommerce/templates/emails/admin-new-order.php to yourtheme/woocommerce/emails/admin-new-order.php
----(Update)----
I was wrong… Woocommerce My account is a page. The <h1>page title</h1> is the title of your page, so you will need to change it, in the wordpress template for pages in your theme (Each theme is different) and not in woocommerce templates.
Once you have found this template in your theme folder, you will use a conditional in an if statement around the <h1>page title</h1>:
// When user is on my account page and not logged in
if (is_account_page() && !is_user_logged_in()) {
echo '<h1 class="entry-title">'.__("My custom title", "the_theme_slug").'</h1>'; // My custom title
} else {
the_title( '<h1 class="entry-title">', '</h1>' ); // the normal template title
}
This code is just a closer example, you will need to customize it a bit…
this is how I'm going with wordpress forum
it is such that even if you do not log into the site you can see what you can create, etc.
Create forum / post to the site just being tucked away so it is only possible to view it if you are login on the page.
Comment content must also be away but just get some text that you can not write content until he has sustained itself on the page.
I purchased this forum
http://themeforest.net/item/forumengine-flat-responsive-wordpress-forum-theme/5999646
WordPress comes with all the functionality needed for this its as simple as wrapping the content you want within an if statement for example
<?php if ( is_user_logged_in() ) {
echo "Member Content";
}else{
echo "Sorry Guest";
?>
id suggest something like above if you are working with template files you could always wrap the while loop with the above
I'm trying to redirect users to a custom page I made when they log in, but I'm not sure I have it right. I don't know exactly which function or variables to use. I want to use the index.php as a way to redirect users. I'm working in wordpress latest, as well as buddypress latest.
So ok, this is what I have:
function my_redirect() {
global $bp;
if ( $bp->current_component == $bp->root_domain ) {
bp_core_redirect($bp->root_component == MY_CUSTOM_SLUG );
}
}
The slug I created is in the root, so it looks like this:
www.mysite.com/mypage
Any ideas?
This can be achieved using redirect_to in your login links. This will require editing of your template.
$redirect_url = "www.mysite.com/mypage"
// if $redirect_url exists, it will add it, otherwise print the regular login link
<a href="<?php bloginfo('url'); ?>/wp-login.php<?php
if($redirect_url) {echo "?redirect_to=".urlencode($redirect_url)."\"";}?> >
log in
</a>
This will probably make you want to cut your face off at some point, since you will have to edit the template every time you want to change your redirect page.
I am not sure exactly what you need this for so here are two ways to do it.
1) You can set any page in wordpress to be the default home page. In the dashboard go to Settings>Reading and under the setting "Front page displays" you can choose "A static page (select below)"
2) You can use the php header location function used:
header( 'Location: http://www.yoursite.com/new_page.html' ) ;
You would place it before your content and it works well with whatever conditions you like.
For more information - http://php.net/manual/en/function.header.php
You may try the Login Redirect plugin. You can choose where to redirect the user after login. It is role based.