Post Levels

I searched for a plugin for WordPress that would allow me to restrict the posts from being readable by certain people. I wanted a system which would scale from «Allowable for registered users» to «Allowable only to my closest of close friends». So I found Post Levels made by Filipe Fortes and it did almost what I wanted. But it didn’t allow me to show private posts to users without posting capabillities at my site (and since this is a private blog, I don’t really want 20 people to be able to make contributions. No offence buddies :) ).

You can now download the edited plugin.

So I decided to hack the plugin so that I could do that. Hence I made this post to make a mini-howto. I’m writing in English because I hope anyone will find it useful. I’m just trying to contribute back a littlebit (although my hack is simple).

So, enough chat.

  1. Find your «post-levels.php» plugin, it should be located in wp-content/plugins.
  2. Open up the file and find this line:
    // Don’t bother unless someone is logged in
    if (!empty($user_level))

    and replace it with this:
    // Don’t bother unless someone is logged in
    if (!empty($user_level) or $user_ID)
  3. Find this line, it should be near the ending:
    function postlevel_posts_where($where)
    { global $user_level, $postlevel_key, $wpdb;

    and add the following beneath it:
    // XXX: Hack to make all registered users see posts of level 1!
    if (empty($user_level) && $user_ID)
    $level = ‘1’;
    $level = $user_level;
  4. Just a few lines down, replace this line:
    “AND {$wpdb->postmeta}.meta_value < = $user_level )))", $where);
    with this:
    “AND {$wpdb->postmeta}.meta_value < = $level )))", $where);
  5. Finished!

If you don’t want to do this – you can always just get the edited plugin. :)

6 thoughts on “Post Levels

  1. Salve

    Hvis du ser på resten av koden så ser du at dette egentlig e ein relativt elegant måde å løse det på, om ikkje heilt skalerbart.

  2. Odin

    ESH, denne er ikkje mynta på deg. Er ikkje du som skal lese dette ;) Du kan fint oversjå det :)

  3. Egil

    Hehe, vasje seriøst meint. :p Men Odin, eg vil lesa den hax skjulte artikkelen din teirik snakka om :/

  4. Teirik

    eg snakka aldri om någen hax artikkel ^o) Eg spurte om dåkkår hadde axx t siste artikkel, sa aldri någe om an!

Legg att eit svar

Epostadressa di blir ikkje synleg.