WordPress.org

Support

Support » Plugins and Hacks » underConstruction » Suggestion: Add possibility to enter site with a certain parameter

Suggestion: Add possibility to enter site with a certain parameter

  • I would like to have the possibility to enter a site with a configured parameter, e.g. http://example.com?uc_pass=open_sesame. With such a feature it would be possible to allow people to enter the site without giving them access to the admin area. Additionally the site could be bookmarked in the construction phase.

    I added this feature in my own code. Here is the patch:

    diff --git a/wp-content/plugins/underconstruction/ucOptions.php b/wp-content/plugins/underconstruction/ucOptions.php
    index 26da6c5..30f1464 100755
    --- a/wp-content/plugins/underconstruction/ucOptions.php
    +++ b/wp-content/plugins/underconstruction/ucOptions.php
    @@ -140,6 +140,17 @@ if(isset($_POST['remove_selected_ip_btn'])){
     if(isset($_POST['required_role'])){
     	update_option('underConstructionRequiredRole', $_POST['required_role']);
     }
    +
    +// ======================================
    +// 		process parameter key and value
    +// ======================================
    +if(isset($_POST['parameter_key'])){
    +	update_option('underConstructionParameterKey', $_POST['parameter_key']);
    +}
    +if(isset($_POST['parameter_value'])){
    +	update_option('underConstructionParameterValue', $_POST['parameter_value']);
    +}
    +
     ?>
     <noscript>
     	<div class='updated' id='javascriptWarn'>
    @@ -256,6 +267,27 @@ if(isset($_POST['required_role'])){
     			</tr>
     			<tr>
     				<td>
    +					<h3><?php _e('Enter with parameter', 'underconstruction');?></h3>
    +					<p><?php _e("You can allow people to enter the site by appending a parameter (e.g. http://example.com?uc_pass=open_sesame). Leave the parameter value field blank if you don't want to enable this feature.", 'underconstruction');?></p>
    +				</td>
    +			</tr>
    +			<tr>
    +				<td>
    +					<fieldset>
    +						<legend class="screen-reader-text">
    +							<span><?php _e('Enter with parameter', 'underconstruction');?> </span>
    +						</legend>
    +						<label title="Parameter key">
    +						  <input type="text" name="parameter_key" id="parameter_key" value="<?php echo get_option('underConstructionParameterKey')?>">&nbsp;<?php _e('Parameter key (default: uc_pass)', 'underconstruction');?>
    +						</label> <br />
    +						<label title="Parameter key">
    +						  <input type="text" name="parameter_value" id="parameter_value" value="<?php echo get_option('underConstructionParameterValue')?>">&nbsp;<?php _e('Parameter value', 'underconstruction');?>
    +						</label> <br />
    +					</fieldset>
    +				</td>
    +			</tr>
    +			<tr>
    +				<td>
     					<h3><?php _e('Display Options', 'underconstruction');?></h3>
     				</td>
     			</tr>
    diff --git a/wp-content/plugins/underconstruction/underConstruction.php b/wp-content/plugins/underconstruction/underConstruction.php
    index ba10ec4..fe177c3 100644
    --- a/wp-content/plugins/underconstruction/underConstruction.php
    +++ b/wp-content/plugins/underconstruction/underConstruction.php
    @@ -78,48 +78,56 @@ class underConstruction
     	{
     		if ($this->pluginIsActive())
     		{
    -			if (!is_user_logged_in())
    +			if (is_user_logged_in())
     			{
    -				$array = get_option('underConstructionIPWhitelist');
    -
    -				if(!is_array($array)){
    -					$array = array();
    +				return;
    +			}
    +			session_start();
    +			if ($this->parameterIsPresent()) {
    +				return;
    +			}
    +			if ($this->hasBeenPassedInSession()) {
    +				return;
    +			}
    +			$array = get_option('underConstructionIPWhitelist');
    +
    +			if(!is_array($array)){
    +				$array = array();
    +			}
    +
    +			if(!in_array($_SERVER['REMOTE_ADDR'], $array)){
    +
    +				//send a 503 if the setting requires it
    +				if (get_option('underConstructionHTTPStatus') == 503)
    +				{
    +					header('HTTP/1.1 503 Service Unavailable');
     				}
    -
    -				if(!in_array($_SERVER['REMOTE_ADDR'], $array)){
    -
    -					//send a 503 if the setting requires it
    -					if (get_option('underConstructionHTTPStatus') == 503)
    -					{
    -						header('HTTP/1.1 503 Service Unavailable');
    -					}
    -
    -					//send a 503 if the setting requires it
    -					if (get_option('underConstructionHTTPStatus') == 301)
    -					{
    -						header( "HTTP/1.1 301 Moved Permanently" );
    -						header( "Location: " . get_option('underConstructionRedirectURL') );
    -					}
    -
    -					if ($this->displayStatusCodeIs(0)) //they want the default!
    -					{
    -						require_once ('defaultMessage.php');
    -						displayDefaultComingSoonPage();
    -						die();
    -					}
    -
    -					if ($this->displayStatusCodeIs(1)) //they want the default with custom text!
    -					{
    -						require_once ('defaultMessage.php');
    -						displayComingSoonPage($this->getCustomPageTitle(), $this->getCustomHeaderText(), $this->getCustomBodyText());
    -						die();
    -					}
    -
    -					if ($this->displayStatusCodeIs(2)) //they want custom HTML!
    -					{
    -						echo html_entity_decode($this->getCustomHTML(), ENT_QUOTES);
    -						die();
    -					}
    +
    +				//send a 503 if the setting requires it
    +				if (get_option('underConstructionHTTPStatus') == 301)
    +				{
    +					header( "HTTP/1.1 301 Moved Permanently" );
    +					header( "Location: " . get_option('underConstructionRedirectURL') );
    +				}
    +
    +				if ($this->displayStatusCodeIs(0)) //they want the default!
    +				{
    +					require_once ('defaultMessage.php');
    +					displayDefaultComingSoonPage();
    +					die();
    +				}
    +
    +				if ($this->displayStatusCodeIs(1)) //they want the default with custom text!
    +				{
    +					require_once ('defaultMessage.php');
    +					displayComingSoonPage($this->getCustomPageTitle(), $this->getCustomHeaderText(), $this->getCustomBodyText());
    +					die();
    +				}
    +
    +				if ($this->displayStatusCodeIs(2)) //they want custom HTML!
    +				{
    +					echo html_entity_decode($this->getCustomHTML(), ENT_QUOTES);
    +					die();
     				}
     			}
     		}
    @@ -219,6 +227,39 @@ class underConstruction
     		}
     	}
    
    +	function parameterIsPresent()
    +	{
    +		$key = get_option('underConstructionParameterKey');
    +		if ($key == null)
    +		{
    +			$key = 'uc_pass';
    +		}
    +
    +		if (!array_key_exists($key, $_GET))
    +		{
    +			return false;
    +		}
    +		if (!get_option('underConstructionParameterValue'))
    +		{
    +			return false;
    +		}
    +		if ($_GET[$key] == get_option('underConstructionParameterValue'))
    +		{
    +			$_SESSION['uc_pass_accepted'] = 'true';
    +			return true;
    +		}
    +		else
    +		{
    +			$_SESSION['uc_pass_accepted'] = 'false';
    +			return false;
    +		}
    +	}
    +
    +	function hasBeenPassedInSession()
    +	{
    +		return $_SESSION['uc_pass_accepted'] == 'true';
    +	}
    +
     	function httpStatusCodeIs($status)
     	{
     		if (!get_option('underConstructionHTTPStatus')) //if it's not set yet

    http://wordpress.org/plugins/underconstruction/

Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Suggestion: Add possibility to enter site with a certain parameter’ is closed to new replies.
Skip to toolbar