• Per-Post User Level restrictions
    ???? 2004 Scott Merrill [email protected]
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.
    INTRODUCTION
    This modification allows blog authors to assign a minimum user level required to view each post. The default value is zero (retroactively applied to all existing posts), which means anyone can see the post. By choosing the post level on the admin post or edit screen, the author can limit who sees what.
    INSTALLATION
    PART ZERO
    Extract the contents of the file post_level.tgz into your WordPress directory. No files will be overwritten. The contents of the download file are thus:

    • post_level.txt
    • post_level.diff
    • post_level.mysql
    • wp-admin/post_level_install.php
    • modified/wp-blog-header.php
    • modified/wp-admin/post.php
    • modified/wp-admin/edit-form.php
    • modified/wp-admin/edit-form-advanced.php
    • modified/wp-includes/template-functions-general.php

    PART ONE
    This modification requires the addition of a new row to the wp_posts table, called “post_level”. There are sever al ways to accomplish this:
    1) Make sure the included post_level_install.php is in your wp-admin directory. Call this page from your browser:
    https://www.example.com/wordpress/wp-admin/post_level_install.php
    2) Edit the included post_level.mysql file to correctly identify the name of your wp_posts table (only necessary if you’re using a custom table prefix for your database tables), then execute the following:
    mysql -uusername -p wordpress < post_level.mysql
    Replace”username” with your database username, as defined in wp-config.php.
    Replace “wordpress” with the name of your WordPress database, as defined in wp-config.php
    3) Use a tool like phpMyAdmin to manually alter the table. The post_level row must be UNSIGNED INT(2), default zero, not null.
    PART TWO
    Next, you need to modify five files:
    wp-blog-header.php
    wp-admin/post.php
    wp-admin/edit-form.php
    wp-admin/edit-form-advanced.php
    wp-includes/template-functions-general.php
    Again, there are several ways to do this:
    1) From the command line, run the patch command in your WordPress directory to automatically modify all the files for you using the included post_level.diff file:
    patch -p0 < post_level.diff
    2) If you haven’t modified any of the listed files yourself (to apply other modifications, for example), you can simply copy the files from the modified/ directory to their respective locations:
    cd modified
    cp -r ./* ..
    3) You can look through either the post_level.diff file, or the files in the modified/ directory to see what changes I’ve made. I’ve prefaced all of my modifications with this line:
    // SDM 23-05-2004 post_level modification
    to help you identify what has been changed.
    USING THE MODIFICATION
    Once installed, you’ll note that the post and edit screens now have a drop-down select box labelled “Post level”. This is the minimum user level required to view the post.
    Enjoy!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hey there Skippy. I take back what I said prior. Your hack was a lot easier to implement than I originally thought. The installation was very quick and easy. The only tiny thing is, I think you may have forgotten to comment in the /wp-admin/edit-form-advanced.php, designating where you made the changes. I did a search for “// SDM 23-05-2004 post_level modification” and nothing came up. Otherwise, all the rest had the comments. I hadn’t made any changes in those files originally, so I just replaced them with your modified ones. Great job on this. You have no idea how long I have been looking for this kind of hack.
    Now, I just need to work in the redirection hack and change the permissions of the user levels and voila! I’ll have what I’m looking for!
    Keep up the good work, Skippy.

    Thread Starter skippy

    (@skippy)

    tontamoo,
    Thanks for the positive feedback! My apologies if I fouled up the download file. I have a typo in wp-admin/edit-form-advanced.php:
    <?php // SDM 23-04-2004 post_level modification ?>
    Wrong month. Silly me. Thankfully, it sounds like my oversight wasn’t an impediment to implementation.

    Skippy, just curious, does this filter the posts from the RSS feeds as well? What about the comments RSS feed? wyzewoman has done another hack, but she says that her comment RSS feed is not being filtered. I’m just wondering whether you took care of this already or not.
    And of course: GREAT WORK! It’s people like you that make WP even more polished than it is now. Hopefully some form of this will be commited to the code base so it’ll be a standard in the upcoming versions ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Per-Post User Level Restrictions’ is closed to new replies.