Envira Gallery Documentation

Documentation, Reference Materials and Tutorials for Envira Gallery

How to Control the Cookie for the Password Addon

Would you like to control the amount of time your cookie for your password is set for? With a custom plugin you can easily set the cookie time for the Password Protection Addon.

This tutorial is a bit more technical than our other docs, but we’ll walk you through the process step by step. In order to control the cookie time, we’ll need to create and upload a basic WordPress plugin.

To control the time set for the cookie on the password, just add the following code to a new file at wp-content/plugins/envira-set-password-cookie.php.

<?php
/*
 * Plugin Name: Envira Gallery - Control Password Cookie Time
 * Plugin URI:  http://enviragallery.com
 * Description: Plugin that will set the cookie time on your password protected galleries
 * Author:      Envira Gallery Team
 * Author URI:  http://enviragallery.com
 * Version:     1.0
 */

add_filter('envira_password_protection_time_limit', 'test_envira_password_protection_time_limit', 10, 3);
function test_envira_password_protection_time_limit( $time_limit, $post, $data ) {
	// note: you can use $post and $data to individually set time limit based on post ID, gallery data, etc.
	// time is in seconds, so if you wanted to set the time limit for something very short (like 10 seconds)
	$time_limit = time() + 10;
	return $time_limit;   
}

If you’re unsure how to create a plugin file, follow these steps below:

  1. Open a text file and make sure that it is a plain text document. You can use a plain text editor like Notepad or a code editor of your choice.
  2. Next, copy and paste the code shown above into the file and save the file as envira-keyboard-mousewheel-navigation.php.
  3. Once you’ve saved the file, you can easily upload this directly to your /plugins directory on your server using FTP, or you can right-click on the text document and zip (or compress).
  4. Finally, log in to your WordPress dashboard and go to Plugins » Add New » Upload Plugin and upload the .zip file you just created in the previous step.

Your next step is to activate the plugin you just uploaded. Simply navigate to the Plugins from within your WordPress dashboard and activate the Envira Gallery – Control Password Cookie Time plugin.

Activate the custom plugin to control the cookie time on the password

And that’s it! Would you like to have your gallery titles link when inside an Envira album? Take a look at our article on How to make the gallery titles in your Envira Albums link.

[i]
[i]