WordPress.org

Ready to get started?Download WordPress

Forums

underConstruction
Suggestion: Add possibility to enter site with a certain parameter (6 posts)

  1. bjoerne
    Member
    Posted 11 months ago #

    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/

  2. albastru22
    Member
    Posted 8 months ago #

    I'm sorry, I am a beginner... What do I do with this code? The idea is excellent and I wish to send someone a link to see the website without having to log in...

  3. bjoerne
    Member
    Posted 8 months ago #

    Hi!
    You need a tool to apply a patch. Unix systems (Linux, OSX ...) have a 'patch' command line tool on board.
    But you can contact me via email (info bjoerne com) and I'll send you the patched plugin as a ZIP.
    Regards
    Björn

  4. demon11c
    Member
    Posted 6 months ago #

    Hi Björn

    Do you think your patch would work for my situation here?:

    http://wordpress.org/support/topic/exclude-password-recovery-page?replies=1

    if I click the password recovery link on the login page, it takes me to the under construction page. Is it possible exclude the password recovery page from the under construction plugin?

    Thank you

  5. bjoerne
    Member
    Posted 4 months ago #

  6. bquerry
    Member
    Posted 4 months ago #

    Bjoerne -
    Thank-you very much for the file!!!

Reply

You must log in to post.

About this Plugin

About this Topic

Tags