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)
Viewing 1 replies (of 1 total)
The topic ‘is_page within a plugin’ is closed to new replies.