• Resolved InterTrade

    (@intertrade)


    Hello Everyone!

    I am just sending this out there to see if by chance anyone knows how to prevent a wordpress webpage from showing up when the page is typed in the URL bar. Of course, when the URL is typed directly into the bar, I would want to display some other page that says something like “Access Denied” or something similar. And I would want this to be separate from the login abilities of WordPress. The thing is, I would like to design some pages specifically for use in some popup windows by creating a special template just for the popups, but I would not want the user to be able to access them just by typing in the URL.

    Now, before you guys send me over to look at the plugins available for popups, let me just say that I have already looked at them and would prefer not to use them for various reasons.

    Thanks for your help. I really appreciate it.

Viewing 3 replies - 1 through 3 (of 3 total)
  • In 2.7.1, go to ‘Pages’ in the Admin Menu and click edit. Then click on the page you wish to edit.

    The second block on the right side is called “Publish”. Look for the link which says, “visibility”. Click ‘edit’ next to it to change from ‘public’ to ‘private’ or ‘password protected’.

    Thread Starter InterTrade

    (@intertrade)

    Cool, BigDaddy00! You helped me see a solution I didn’t see before.

    As a matter of fact, I was just about to register my solution by utilizing the $_SESSION superglobal to pass popup status to the template and thereby blocking a direct access. But I like your solution very much!

    Thanks again for your help!

    Thread Starter InterTrade

    (@intertrade)

    Wow, you know, after I posted my last post, I began to see some serious problems with my approach with the $_SESSION superglobal. It seems that the superglobal just didn’t act the way I expected. It took me some time to find the right approach that would resolve all the issues and consistently give me the popups and the “Access Denied” pages as I originally intended, so I will post my solution here for all the world to see just in case there is anyone else out there looking for a similar solution.

    My final solution involved using a form, a link and some javascript. I had to use a fake submit button in order to invoke the onsubmit event handler. The solution is as follows:

    In the popup template:

    <?php
    /**
     * @package WordPress
     * @subpackage Your_Theme
     */
    /*
    Template Name: Popup
    */
    if ($_POST['popup'] != "true") {
    	header( 'Location: https://your.url/?page_id=yourpageid');
    // Place your "Access Denied" page in the your.url info above.
    } else {
    ?>
    	<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    	<html xmlns="https://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
    <!-- The rest of your popup template goes here.  Don't forget to close out the PHP if statement.

    In the javascript file (don’t forget to include your reference to this file in the header.php file):

    function get_popup(popup_window, form_name, height, width) {
    	window.open(popup_window, 'popup_window', 'width=' + width + ', height=' + height + ', resizable=yes, scrollbars=yes, toolbar=no, menubar=no, left=0, top=0').focus();
    	eval('document.' + form_name + '.target = "popup_window"');
    	return true;
    }
    
    function submitform(form_name) {
    	eval('document.' + form_name + '.fakeSubmitButton.click()');
    }

    And finally at the link:

    <form name="yourformname" action="yourtemplateurl" method="post" onSubmit="return get_popup('yourtemplateurl', 'yourformname', yourwindowheight, yourwindowwidth)"><input type="hidden" name ="popup" value="true">
            <div class="yourlink"><a href="javascript:submitform('yourformname');">Your Link</a></div><input type="submit" name="fakeSubmitButton" style="display: none"/>
    </form>

    This code works like a charm for me. I hope it helps someone else.

    Have a great day!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How To Prevent A Page From Being Displayed’ is closed to new replies.