Set up a WordPress site to require an invite code

code-coding-data-574071

I recently built a website for a wedding and a specific feature they wanted was for the website only to be available to their guests. We didn’t want to have to deal with any cumbersome user login system, but just something simple that only invited guests would be able to use.

Security wasn’t a major priority. If at the end of the day, a guest wanted to show a friend the site, that’s okay.

So the method that we implemented for the site was to set up the site with an invite code that would then be included in invites that were set out to guests. Again, it wasn’t set up to be highly secure nor did individual guests need their own unique invite code, so the same invite code was used for all guests — for simplicity’s sake — especially when it came to creating the invites.

How to set it up

1. Download the plugin called Password Protected.

You can find the download here:
https://wordpress.org/plugins/password-protected/

The author of this plugin is Ben Huson and plugin gives you the basic functionality that you’ll use for securing the site. For our use case, password protection (without user authentication) met our requirements for security and privacy.

2. Edit the plugin’s code.

The changes to the code are very, very minor, but if you don’t feel comfortable digging through any code, feel free to give me a shout and I’d be happy to give you a quote on your project. You can contact me here.

Open the plugin file named “password-protected-login.php” in a text editor. You’ll find the file inside the plugins “theme” folder.

Do a quick search in your editor for:

<label for="password_protected_pass"><?php _e( 'Password', 'password-protected' ) ?><br />

Or scroll down and locate the line with that code. It’s somewhere around 3/4 of the way down at the time of writing this article (line 106 to be exact).

Replace “Password” with “Invite Code”, or whatever you want to call it (Access Code, Secret Phrase, etc.)

Your code should like this after:

<label for="password_protected_pass"><?php _e( 'Invite Code', 'password-protected' ) ?><br />

Save the changes you made to the file.

3. Rename plugin and change URL.

This is done to ensure that future plugins updates that are rolled out to the Password Protected plugin do not overwrite the code you’ve changed.

Open the file named “password-protected.php“. And edit the following lines:

*/
Plugin Name: Password Protected  /* RENAME THIS LINE */
Plugin URI: https://wordpress.org/plugins/password-protected/ /* RENAME THIS LINE */
Description: A very simple way to quickly password protect your WordPress site with a single password. Please note: This plugin does not restrict access to uploaded files and images and does not work with some caching setups.
Version: 2.2.5
Author: Ben Huson
Text Domain: password-protected
Author URI: http://github.com/benhuson/password-protected/
License: GPLv2
*/

You can rename these to anything you’d like. For example:

/*
Plugin Name: Invite Code
Plugin URI: https://mywebsiteaddress.com
*/

4. Optional: Make some design improvements.  

The site we used this for was for a wedding, so naturally, we wanted the login screen to look a little nicer than the default styling that the plugin uses. The changes were very minimal so we just added the styling directly to the elements that we edited in the above file. If you wanted to do more you could always add the CSS to your theme’s (child theme’s) style.css file. I don’t believe the Password Protected plugin actually applies any styling of its own, but rather just uses the default WordPress styling. I could be wrong but I didn’t dig down the road.

5. Install the plugin and activate.

In order to do this you’ll need to compress the plugin folder. Locate the folder on your computer and then right click on it and choose the compress option. You’ll then see a .zip version of the folder with the same name.

Login to your WordPress site and Install the plugin and activate it just like you would with any other plugin that you’ve downloaded the .zip file for. If you’ve never done that before, navigate to Plugins, click “Add New”, then click “Upload Plugin”. Activate once it’s installed.

6. Enable the invite code.

Go to the plugin’s settings and add enable the plugin for password protection and enter the password (invite code) you want to use.

And that should be it! You’ll need to be signed out of your WordPress admin account in order to test the feature, so sign out and give it a try.

Here’s what our invite login looked like:

If you want to change the admin logo as we did, you can use this plugin here for an easy way to do that:
https://wordpress.org/plugins/login-logo/

If you’d like this done for your site but don’t want to deal with coding it out yourself, let me know, I’d be happy to help with your project!

Category:

Daniel Lemky

Leave a Comment