WordPress protection by default

Discussion in 'Setting-up protection' started by bennyuk1, Oct 9, 2012.

  1. bennyuk1

    bennyuk1 aMember Pro Customer

    Joined:
    Jan 12, 2012
    Messages:
    160
    I have some pages that are created in the background when a user uploads a file, using the
    wp_insert_post
    call in wordpress.

    However I need these pages to be protected to members only.

    1. Can I set a page parameter via wp_insert_post to setup protection?

    2. The pages are arranged so that they all have the same PARENT page. Is there a way I can set protection to be "for all pages with this parent page" (all child pages)

    3. Worse case scenario, is there a way page CONTENT can be added via wp_insert_post to set protection?

    Thanks for any advise.

    Ben
  2. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,274
    Ben,
    Plugin stores protection settings for each page in page meta.
    The simplest way to protect each page when you create it automatically, will be as follows:
    1. Create any page and set protection for it the same way as you will need for other pages which will be created automatically.
    2. In the code do this:
    $meta = get_post_meta(ID_OF_THE_PAGE_WHERE_PROTECTION_WAS_SET_MANUALLY, 'am4options',true);
    update_post_meta(NEW_PAGE_ID, 'am4options', $meta);
  3. bennyuk1

    bennyuk1 aMember Pro Customer

    Joined:
    Jan 12, 2012
    Messages:
    160
    Thanks Alex, I'll give that a go.

    Can I assume that approach can be used in other circumstances, for instance if I wanted to batch protect a whole group of pages that already exist, I could do this by copying the meta data as above using a script?
  4. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,274
    Yes correct

Share This Page