Vous êtes sur le point de lancer un nouveau produit et vous avez développé un site développeur/développeuses pour celui-ci en utilisant la plateforme de publication web préférée du monde entier, WordPress. Vous souhaitez le tester en direct sur son propre domaine et son propre hébergeur, mais vous n’êtes pas encore prêt à le rendre public. Dans un autre article, nous avons expliqué comment protéger WordPress par un mot passe sans inscription des utilisateurs/utilisatrices. Que diriez-vous de limiter l’accès à un site aux seuls internautes connectés ou autorisés par leur adresse IP ? Dans cet article, nous allons vous afficher comment restreindre l’accès à un site WordPress par IP ou par utilisateurs/utilisatrices connectés.
Tutoriel vidéo
Si vous n’aimez pas la vidéo ou si vous avez besoin de plus d’instructions, alors continuez à lire.
La première chose à faire est d’installer et d’activer l’extension Restricted Site Access. Après avoir activé l’extension, allez dans Réglages » Lecture. Défilez vers le bas et vous verrez des options pour configurer l’accès restreint.
En utilisant le plugin Restricted Site Access, vous pouvez restreindre l’accès à un site WordPress pour les utilisateurs/utilisatrices connectés uniquement ou pour les personnes ayant des adresses IP spécifiques. Vous pouvez également choisir de rediriger les utilisateurs/utilisatrices n’ayant pas accès au site en les envoyant vers la page de connexion, en les redirigeant vers une autre adresse web, en leur affichant un message personnalisé ou même en les redirigeant vers une page spécifique (page coming soon) que vous avez créée sur le même site. La fonctionnalité de restriction par IP est très utile si vous souhaitez que plusieurs employés du bureau aient accès au projet de développement sans qu’il soit nécessaire qu’ils s’inscrivent en tant qu’utilisateurs/utilisatrices.
Cette extension peut être extrêmement utile pour tester votre site avant le lancement d’un produit. Il est également bon pour créer des blogs privés pour les amis et la famille uniquement. Nous espérons que cet article vous aidera à mener vos projets en toute discrétion. Avez-vous d’autres moyens que vous avez utilisés pour restreindre l’accès à un site WordPress ? Partagez-les avec nous dans les commentaires ci-dessous.
Jeff
Can you restrict by IP by role? We want to limit by IP user logins that have full admin rights. Subscribers, Authors, and Editors will not be limited by IP address.
WPBeginner Support
We do not have a specific recommendation for role-specific limitations at the moment but we will be sure to share if we find a method we would recommend.
Administrateur
Prince Lee
I was wondering if there was a way to restrict my signup page to only visitors from a given location
WPBeginner Support
You would normally need a security plugin to achieve something like that.
Administrateur
Terry
I think this plugin is great for my wholesale accounts. but the end user (retail) for me is a customer that has to approve designs. I do not understand how to make the private page with password open for them while keeping the wholesale side ip protected. Is there a plugin that allows access by page while restricting by ip address. The password feature for the wholesale side is too vulnerable to being shared.
chris
According to the FAQ’s here is a way to make exceptions for specific pages:
add_filter(‘restricted_site_access_is_restricted’,’impressum_override’,10,2);
function impressum_override( $is_restricted, $wp ) {
// check query variables to see if this is the feed
if ( ! empty( $wp->query_vars[‘pagename’] != ‘name-of-page’ ) ) {
$is_restricted = false;
}
return $is_restricted;
}
Eran
The only problem is that this plugin restricts the access to lost password page as well.. this is a problem..
Jim Gore
I also liked this simple and effective plugin, until I discovered that the lost password page couldn’t be reached. I also tried another nice plugin (restrict site access), also simple to set up & effective, but it suffered the same problem. The author of that plugin suggested that the problem could be resolved by hooking code in to handle that page.
JR
Thanks a lot !!! This plugin rocks…I was exactly looking for this ..God Bless You
Shoeb
Hi,
How to handle the scenario with the Dynamic IP addresses. If we unrestrict certain IP addresses then every time the IP address will get change. Then what to do in this situation ?
Joe Njenga
Can this plugin work with a single page restriction ?
Mariska Van de Langenberg
If you would have a subscription sign up for a product as well as a registration as affiliate on your site….would there be an option to avoid people to sign up as affiliate first and then subscribe to the product in order to get commissioned on them? Like a check on IP amongst the affiliate IP’s?
kate
I have a problem when my members sign up they are taken to payment page but if they click off this page they can log in without paying. How do i restrict their access until they have paid the fee
in a nutshell How can i restrict access to my members until they pay
WPBeginner Support
There are separate plugins for that for example, Retrrict Content.
Administrateur
John
You can use the safe private plugin:
http://wordpress.org/plugins/safe-private/
Mona
Can you please clarify the following:
By restricting site access to those who are « logged in » – does that mean users have to set up a Wordpress account? I’m trying to make it as easy as possible for the non-savvy computer user for accessing a family website.
Also, do restricted access plugins only work on self hosted sites? What about free sites like Wordpress.com?
Thanks!
Editorial Staff
Most techniques mentioned on this site including this one are for self-hosted WordPress and will not work on free WordPress.com
Administrateur
Ruchi
Is there a way to restrict users to only a certain section on the site, where they can access product data etc. based on an email login? I’m an amateur webmaster and have been struggling with this.
Editorial Staff
Yes. You would have to use one of the many membership plugins such as S2 members or Easy Digital Downloads etc.
Administrateur
Ruchi
Thanks. I ended up using word press access control since it allowed more customization, been workin like a charm..
Used a lot of tips from your website though. You guys are doing a great job! Thanks much!
Simon
So basically install a plugin… what a very informative article.
If anyone else is interested you can add code in your functions file to prevent anyone who is not logged in from viewing your site:
function password_protected() {
if ( !is_user_logged_in() ) {
auth_redirect();
}
}
add_action(‘template_redirect’, ‘password_protected’);
add_action(‘do_feed’, ‘password_protected’);
Editorial Staff
Thank you for sharing an alternative code solution, but why reinvent the wheel? There is absolutely nothing wrong with installing a plugin to do a simple task. That’s what plugins are made for. Also the author of that plugin is fairly well-reputed in the community. When we need to restrict site access by IP or logged in users, we use this plugin.
Administrateur
Barry
Hi simon,
Your code seems so simple yet it doesn’t work for me. I even check by putting a simple echo before the if statement to check if the function is being called at all and it doesn’t.
So which add_action should i use?
Malc
Simon, this plugin allows access to a whitelist of IP addresses. Not a common request – but very useful from time to time. Do you have code that could handle that function?