Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've got custom developed sales system (in PHP, let's say it's and I would like to add informational section to it. Instead of developing it from the ground up I thought that it would be better to publish information by Wordpress (for example published on subdomain

The problem is I would like to make it accessible only for users logged in to system. So when somebody enters he sees some text like "Please login to". When somebody is logged in to he should be able to read all the pages in Commenting them is not necessary (read-only is enough).

As I know Wordpress rather from administrator's perspective I tried to find some plugin to solve that, but I failed. Maybe you can advice some ready-made (evan paid) solution? If it does not exist please, advise how it could be solved.

Login to is based on POST form and cookies, passwords in database are hashed with salt. system can be extended to provide some API.

share|improve this question

1 Answer 1

Quick and dirty: add something that runs during the WordPress init action that checks your the login status, and dies if the person isn't logged in. At a very basic level (if you don't need a pretty "access denied" page or anything), you can do something as simple as this in a plugin:

function wpsx_26176_check_login() {

    // some logic to validate your cookies. here I'm just checking if a cookie exists
    // but obviously your validation would be more extensive
    if(!isset($_COOKIE['yourcookie'])) {
        wp_die('get out of here'); // If cookie is missing, just die

add_action('init', 'wpsx_26176_check_login');

What you'll need to keep in mind if rolling out WordPress on a subdomain is that cookies are by default only applicable to the domain they're set on. You'll have to set the cookies written by your custom application to specifically be available across all your subdomains.

share|improve this answer
Which Wordpress' .php file is the best to add such a code? – user7982 Aug 18 '11 at 15:10
You can put it in your theme's functions.php file. – MathSmath Aug 18 '11 at 17:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.