Code for private (invisible) pages

  • Unknown's avatar

    Hiya,

    I altered my theme so that some pages are only visible when users are logged in. I’m not sure if my code is the best way to do this.

    I added this function to my theme’s functions.php:


    function exclude_secrets() {
    global $wpdb;
    $myquery = $wpdb->get_col("select post_id from $wpdb->postmeta where meta_key='secret';",0);
    if( $myquery )
    $mystring = "&exclude=" . implode(",",$myquery);
    else $mystring = "";
    return $mystring;
    }

    …and then I changed my theme’s header.php page code to:

    ... if ( ! is_user_logged_in() )
    wp_list_pages('title_li=' . exclude_secrets() );
    else
    wp_list_pages('title_li=');

    Then if I write a page, I add ‘secret’ as a custom field. It will only be visible when I am logged in. Is this an ok way to solve this, or does anyone forsee a horrible flaw?

  • Unknown's avatar

    Are you on WordPress.com, or WordPress.org? Because we are running on a shared blogging platform over here, and without the Custom CSS upgrade nobody can edit their template.

  • Unknown's avatar

    I apologize: this is a hack for a wordpress blog off-site.

    Also, this hack does not genuinely restrict access to a private page! It only prevents it from appearing as a clickable link in the menu.

  • Unknown's avatar

    Closing thread since it’s for the other site.

  • The topic ‘Code for private (invisible) pages’ is closed to new replies.