Title: is_page within a plugin
Last modified: August 19, 2016

---

# is_page within a plugin

 *  Resolved [tomkinsg](https://wordpress.org/support/users/tomkinsg/)
 * (@tomkinsg)
 * [18 years, 3 months ago](https://wordpress.org/support/topic/is_page-within-a-plugin/)
 * Hi, diving into updating a plugin – Members only – so that it only requires login
   for a pages. The original code looks like this
 *     ```
       function members_only()
       {
       	global $userdata, $members_only_opt, $members_only_reqpage;
   
       	$home = get_bloginfo('url'); //Get base URL or WordPress install
       	$currenturl = sprintf('http%s://%s%s',(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == TRUE ? 's': ''), $_SERVER['HTTP_HOST'], $members_only_reqpage); //Get the current URL
   
       	//Check redirection settings
       	if ($members_only_opt['redirect_to'] == 'login' || $members_only_opt['redirect_to'] == 'specifypage' && $members_only_opt['redirect_url'] == '') //If redirecting to login page or specified page is blank
       	{
       		$redirect = "/wp-login.php";
       		if ($members_only_opt['redirect'] == TRUE) //If redirecting to original page after logging in
       		{
       			$redirect .= "?redirect_to=";
       			$redirect .= $members_only_reqpage;
       		}
       	}
       	elseif ($members_only_opt['redirect_to'] == 'specifypage' && $members_only_opt['redirect_url'] != '') //If redirecting to specific page
       	{
       		$redirect = '/'.$members_only_opt['redirect_url'];
       	}
   
       	//Create Redirection URL
       	$redirection = $home.$redirect;
   
       	if ($userdata->ID == '' && $members_only_opt['members_only'] == TRUE)//Check if user is logged in and blog is Members Only
       	{
       		//Check we aren't already at the page we're redirecting to (with and without the trailing slash) or wanting to go to the login page, registration page or somewhere in wp-admin
       		if ($currenturl == $redirection || $currenturl == $redirection.'/' || preg_match("/wp-login.php/i", $_SERVER["REQUEST_URI"]) || preg_match("/wp-register.php/i", $_SERVER["REQUEST_URI"]) || preg_match("/wp-admin/i", $_SERVER["REQUEST_URI"]))
       		{
       			//Do Nothing
       		}
       		else
       		{
       			//Redirect Page
       			ob_start();
       			header("Location:".$redirection);
       			ob_end_flush();
       		}
   
       	}
       	else
       	{
       		//Do Nothing
       	}
   
       }
       ```
   
 * All I am doing is putting in a test to see if it is a page…
 *     ```
       {
       	if (is_page())
       	{
       		//Redirect Page
       		ob_start();
       		header("Location:".$redirection);
       		ob_end_flush();
       	}
               else
               {
                       // Do nothing
               }
       }
       ```
   
 * The is_page() function just always appears to return false.
 * any pointers.
 * thanks

Viewing 1 replies (of 1 total)

 *  Thread Starter [tomkinsg](https://wordpress.org/support/users/tomkinsg/)
 * (@tomkinsg)
 * [18 years, 3 months ago](https://wordpress.org/support/topic/is_page-within-a-plugin/#post-695319)
 * I basically gave up with this. Don’t know why i could not get it to work.
 * Instead I borrowed another plugin (Angsuman’s authenticated wordpress plugin)
   and tweaked it to do what i needed. If i get time, I will clean it up an publish
   it as I think it may have a broader application and I don’t think any of the 
   other authentication plugins do authentication of a subset of a site without 
   the need for entitlements to be set up.
 * thanks
    G

Viewing 1 replies (of 1 total)

The topic ‘is_page within a plugin’ is closed to new replies.

## Tags

 * [authentication](https://wordpress.org/support/topic-tag/authentication/)
 * [is_page](https://wordpress.org/support/topic-tag/is_page/)

 * 1 reply
 * 1 participant
 * Last reply from: [tomkinsg](https://wordpress.org/support/users/tomkinsg/)
 * Last activity: [18 years, 3 months ago](https://wordpress.org/support/topic/is_page-within-a-plugin/#post-695319)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
