usermeta, userextra

Y’know, it really has been a long while since I’ve started to program anything from scratch, i.e. a new open source project. However, I’m pleased to say I’ve written a couple of WordPress plug-ins, albeit in PHP which makes me want to throw up.

You can check them out over at wp-plugins.org: Usermeta which adds an API so that arbitrary meta data can be associated to users (a feature they’ve added to 1.6 and I’ve effectively back-ported), and Userextra which extends user profiles to include admin-defined attributes, and provides for category access controls with user-level granularity.

I’m particularly pleased with this as it will allow me to construct a community site for my local development based on WordPress (which is fantastic) and allow each set of residents to be given a private category in which to talk. This all started when I went to the 4th Annual Garden Party at the end of August and met the members of our resident’s association. You could see their eyes light up when they heard I was in web-based IT… 🙂 So anyway, they invite me out for a chinese and one thing leads to another and I’m writing plug-ins…

60 thoughts on “usermeta, userextra

  1. Hi! First of all, Thanks for the great plugin!
    and, I have a question.
    I got error message in Manage page
    Extra User Data.

    WordPress database error: [Table ‘studiomo_pxsm.wp_usermeta’ doesn’t exist]
    SELECT meta_value FROM wp_usermeta WHERE user_id=’1′ AND meta_key=’categories_allow’

    WordPress database error: [Table ‘studiomo_pxsm.wp_usermeta’ doesn’t exist]
    SELECT meta_value FROM wp_usermeta WHERE user_id=’1′ AND meta_key=’categories_deny’

    How and where should I creat tables in MySQL?

    Thanks!

  2. re category access control, how do you define restricted categories… with the id, category slug, category name?

    in the screenshot at dev.wp-plugins.org you have “locked,allowed” in the options page, under ‘List of locked categories.’ this would indicate that the definitions are not not ids, but slugs or something else… a tip would be appreciated… i’d love to get this working:>)

  3. ah i see…
    1) the answer to my question seems to be category name

    2) w/ this plugin, authors cannot view restricted category posts (when logged in), though anonymous users can view these categories. authors not allowed access to restrict categories cannot manage posts in these categories but can write a post with these categories checked (and subsequently not be able to see or edit them).

    what i’d like is the ability just to restrict post access on a per-user basis, as described in this wordpress.org thread. any ideas?
    http://wordpress.org/support/topic/32118

  4. If you lock a category with Userextra it will not be visible to anyone at all, anonymous or otherwise, unless you unlock the category on a per-user basis. This actually means an anonymous user can never view the category. So I don’t understand what you mean when you said “though anonymous users can view these categories” – this shouldn’t be so, if there is a condition where this happens, let me know and I’ll investigate.

    I hadn’t thought of restricting posts – so I understand the requirement is this right: you want to allow everyone to VIEW all categories, but only allow certain people to post to a category? (presumably you want this to be flexible so you can choose which categories are restricted, and then which users can post to the category?)

  5. yes my bad i think… some sort of wordpress cookie bug using firefox– i logged out of wordpress and can see the excluded category posts on blog’s homepage, but indiv. posts and category archive are not viewable. tried in IE and everything works as you describe.

    yes i would love to restrict category posting by user instead of level (available with another plugin). and yes flexible, so some way to indicate exactly which categories are visible and allowed per user. ideally this would be accompanied by some way to optionally moderate posts (specified by admin per user), but this may already be possible in wordpress.

    the idea is to facilitate a multiblog. some categories will have multiple authors, and some authors will post to multiple categories but for the most part a given author will post to 1 cat and that’s it.

    anyhow thanks for your time and great work on this stuff:>) if you have any ideas of how to achieve this scenario, i’d welcome them, though my php is weak.

  6. I’ve tried to add some functionality to Userextra to do this.

    The three things I’ve added are:

    • There’s now an additional option: “List of category names users can’t post to by default” (as before, the per-user category allow/deny rules apply)
    • The Write Post window now only has the categories you can post to listed.
    • Attempts to post with a restricted category will throw up an error (just incase someone crafts a request by hand)

    Let me know if this is any good for you.

  7. Wow, fantastic Squish!

    A good many people will be grateful for this:>) I tested it and it works great. Two things for user of this function to remember:
    * allow permissions must also be set for admin
    * if default checked category is locked for an author and post is submitted without checking an allowed and visible category, error message is displayed. (i think it posts to the default category anyway despite the msg but i didn’t test thoroughly).

    thx again:>)

  8. Is anyone else having problems with posts from protected categories being displayed in the sidebar? (Even to anonymous users)

    I get a 404 on access, but the titles are still visible.

  9. Where in your sidebar are you getting this problem? i.e. what function in wordpress?

    Titles? Do you have some kind of recent news display in your sidebar or something? I don’t use a theme which does anything like that. What funciton does it use?

  10. hey– great plugin.. as to comment 9.. i see the restricted cats in the sidebar as an anonymous user.. im using Patricia Miller’s connections template.

  11. Firstly, thanks for Usermeta and Userextra, it is exactly what I have been looking for and is superb!

    However, I have discovered a problem with the RunPHP plugin using eval(), when the Usermeta plugin is activated. When I edit a page with embedded php code using the WP editor, I get the following errors when I try to save the page:

    Warning: Invalid argument supplied for foreach() in …../plugins/userextra2.php on line 669

    Warning: Cannot modify header information – headers already sent by (output started at …../plugins/userextra2.php:669) in ……post.php on line 397

    Any ideas why this might cause a problem?

  12. Hi John. I’ll look in to this. Editing pages doesn’t seem to go wrong on my install… but I don’t run RunPHP. I’ll need to get it and install it.

    Does the error stop WP from working? or does it actually do the desired action?

  13. Thanks. I think RunPHP may be a red herring, and I have done some more investigation to narrow down the problem (sorry, I should have paid more attention to my ITIL incident management book!):

    The error
    When I save a page (not a post, see below), I get the following error:

    Warning: Invalid argument supplied for foreach() in /home/xxx/public_html/xxx/wp/wp-content/plugins/userextra2.php on line 669

    Warning: Cannot modify header information – headers already sent by (output started at /home/xxx/public_html/xxx/wp/wp-content/plugins/userextra2.php:669) in /home/xxx/public_html/xxx/wp/wp-admin/post.php on line 397

    This is the only text that appears on the screen. However, the content of the edited page is saved, and can be viewed if I go back to the site or re-open the page in the WP editor.

    The error therefore doesn’t stop WP from working, it seems to affect what happens on postback.

    What causes the error
    1. With plugins Usermeta (0.1 beta), Userextra (0.2 – userextra2.php) activated. RunPHP deactivated. I get no errors on writing a post, but I do get the error (listed in comment 12) on writing a page.

    2. With plugins Usermeta activated and Userextra (0.2) deactivated. I do not get the error on writing a page or a post, but I obviously lose the extended user profile. As the Usermeta tables are still present, I can continue to display data from the extended user profile using the Usermeta object.

    3. With plugins Usermeta and Userextra (0.1 – userextra.php) activated. I get no errors, both pages and posts save correctly.

    Analysis
    The differences between userextra.php and userextra2.php includes an additional method: filter_content_save_pre() that is called on line 774:

    add_filter(‘content_save_pre’, array(&$userextra, ‘filter_content_save_pre’));

    Line 669 (the error line) states:

    foreach ($_REQUEST[‘post_category’] as $catid)

    Obviously this is invalid for a page.

    Conclusion
    My workaround for now is to use the original 0.1 version of Userextra (userextra.php). I don’t know enough about the workings of WP to suggest potential mods for userextra2.php.

    Why did you add the post restrictions to version 0.2? I’d be interested to find out.

    Once again, thanks for your help. I hope the ramble above helps.

  14. Hi squish – great plugin, i use it for restriction of categories. is there a possibility of hiding the locked category names in the sidebar as long as a user is not logged in? i couldn’t figure out… again, thanks a lot.

  15. I also expected that the categories would be hidden in the sidebar for users that weren’t logged in, or had restrictions. Apparently they just can’t read the posts or post to those categories. But what point is there letting people see that there are things they are not able to read?

    Any easy fix for that. What I need is that those who are not logged in, or have restrictions will not even know those categories/posts exist. Much neater in my opinion. Certainly appreciate any help in this.

  16. I’ll have to look in to hiding the categories in the sidebar when I have some time. I think it may be tricky due to themes etc., although perhaps could you the same technique that’s used to restrict the tick boxes available for posting.

  17. hi, i was looking for something like described in reaction 7 and 8 (restricted categories to post in).
    I just don’t seem to get it to work… It shows all the categories including the ones i filled in under “List of category names users can’t post to by default:”
    I am working with mac (safari, firefox). Any ideas?

  18. Hi – me again.

    I got some Invalid argument supplied for foreach() warnings and realized this was because there wasn’t any post yet in the category. A little bug in the script perhaps?

    One thing that frustrates me is that I keep seeing all categories! Restrictions doesn’t seem to work at all. (It looks as if I am the only one…)
    I truely don’t understand it!
    I deleted cookies – logged out and even tried IE via GuestPC (an emulator)….
    Help? 🙁
    Please…??

  19. wubbonius – can you confirm you are talking about the post section of the admin pages? if so, can you send me the html file for that page? Thanks.

  20. I’d love to use this but after I add the missing ?> at the end and enable the plugin I get this error: Fatal error: Cannot redeclare get_usermeta() in /home/user/public_html/wp/wp-content/plugins/usermeta.php on line 120

    I can’t even get the tables installed.. I’m using 1.6 beta..

  21. hi,
    yr plugin is of great help for my project, thx for offerinf it to us.
    But I have two pb that freeze my progression:
    1. There is a bug in the following conf > I have a categorie called “hiphop” with 3 child-categorie inside.I Want my users just to access child-cats.So I add “HipHop” to the “not visable by default” field. Something weird happen : the first child cat in alphabetical order do not show on ??? and the two others show on ??
    Couls you tell me please what can I do to fix this out ?
    Thx a lot for your work.

  22. After installing Userextra.2.php I got the following error when posting a new or edited page:

    Warning: Invalid argument supplied for foreach() in …../plugins/userextra2.php on line 669

    Warning: Cannot modify header information - headers already sent by (output started at …../plugins/userextra2.php:669) in ……post.php on line 397

    The problem is that the argument to the foreach loop equals null, putting it in an if statement evades this problem.
    The following modification to the userextra.2.php took care of it:


    function filter_content_save_pre($in) {
    /* for some reason, WP doesn't call category_save_pre on edits */
    global $user_ID;
    $locked = get_settings('userextra_lockedcategories_post');
    $locked_a = $this->options_split($locked);
    $allow = $this->usermeta->get($user_ID, "categories_allow", true);
    $allow_a = $this->options_split($allow);
    $deny = $this->usermeta->get($user_ID, "categories_deny", true);
    $deny_a = $this->options_split($deny);
    if ($_REQUEST['post_category'] != null)
    {
    foreach ($_REQUEST['post_category'] as $catid) {
    $name = get_catname($catid);
    if (!in_array($name, $allow_a) &&
    (in_array($name, $locked_a) || in_array($name, $deny_a))) {
    die($this->T('You cannot post to that category as this user.'));
    }
    }
    }
    return $in;
    }

  23. In response to Chris – these plug-ins are for WordPress 1.5. I haven’t attempted them in any 1.6 beta which you may be using. Sorry. If someone wants to get userextra working in 1.6 that’d be great, but I have no plans to migrate myself.

  24. I get the feeling that a lot of people are having problems getting the category restrictions to work. If you are one of these people, you will need to send me a copy of the web page which is displaying something you think it shouldn’t, a description of what the problem is, plus the output of the following MYSQL query:

    select option_name,option_value from wp_options where option_name like ‘user%’;

    Thanks.

  25. Thanks for spending time on these plug ins. My userextra options page doesn’t show up. I installed usermeta and created the tables. I go to the userextra options page and it is identical to the usermeta options page. yikes. Help?

  26. Hi, how do i get the extra information that a user has input to be available to all members of the site?

  27. I am using this plugin for my family website, and would like it so me registered family members can view the “Extended Userdata” which I have created.

    Example: I created fields for address, email, phone, B-Day, etc. now I would like it if all my family members can view this information.

    Is this possible?

    Thank you,

    Patrick

  28. Have installed the plugins with no problem. Is there a way for the user to populate this information automatically when filling out the registration form? That would really be ideal.

  29. I’ve tried using Usermeta (and Userextra), but I get errors when activating them.

    WordPress 1.5.2, Apache 2.x, Usermeta from:
    http://dev.wp-plugins.org/attachment/wiki/Usermeta/usermeta.php?format=txt

    After clicking on Activate, I get:

    Parse error: parse error, unexpected $ in …/wp-content/plugins/usermeta.php on line 367

    I noticed that there is no closing ?> in the plugin file. After adding one, I get the same error message except the line number is one higher.

    I would appreciate any tips on how to resolve this.

  30. I’ve been trying to use your plugin for my website, and I’ve been having a couple of problems.

    1- is there a way for the admin to edit the content of the user profile fields added via userextra?

    2- if i’ve created a text field called ‘longbio,’ what code do I insert into the code to tell it to quote the contents of that field?

    Thank you muchly for your help and for your plugins 🙂

  31. Hi there! I love this plug-in but I do have a question.

    Is there a way to post an entry (assuming its a private entry with certain users set to read it) that’s titled “private – click here to log in” then give the wp-admin login link… is that possbile???

    some users don’t log when t hey read the site so they wont see the private post listed and they won’t know one actually exists…

    does that make sense?

    thanks for the great-plug in!

    Andre’

  32. Addendum to my previous post:

    Say an entry has a set level. So users who are registered can see that. The one’s who are not see this:

    Private Entry. Please log in to view private entries. For an account, please read this entry. With corresponding links in the statement.

    It gives a person more reason to regsiter to read my site when they know a private entry exists…

    cheers,
    Andre’

  33. Hi – I’m having the same problems as Russ:

    “My userextra options page doesn’t show up. I installed usermeta and created the tables. I go to the userextra options page and it is identical to the usermeta options page.”

    Only the table installation part is showing (and I’ve installed the tables) any ideas? Thanks

  34. Is there a way to make so that I (as admin) can edit my users’ extended profiles, just as I edit their regular profiles?

    Also, is there a way for me to show usermetadata outside of the loop (which would come in handy when making author pages)?

    Either way, thanks a lot for the plugin.

  35. Great plugin…Have things working nicely, with mdm’s fix. Is there any way for authors to be able to view the site normally (as an anonymous user would), after logging in? I’m only trying to limit categories where authors can post, not which categories they can read.

    Cheers!

  36. Thanks for these plugins, they’re exactly what i was looking for!

    I have one problem tho – the locked categories still show up in the sidebar of my site, even when I add them to the “List of category names not visable by default” field.

    They appear when the wp_list_cats() funtion is called.

    Is there a way to hide them in the sidebar? I really want them to be invisible to visitors.

  37. If you add this extra code to userextra then it will remove the locked categories from your sidebar, unless users have permission to view them:


    // Returns a hash from IDs to associated category objects
    function get_category_lookup() {
    global $wpdb;

    $categories =
    $wpdb->get_results("SELECT * FROM $wpdb->categories ORDER BY cat_name");

    $category_lookup = array();

    foreach ($categories as $category)
    $category_lookup[$category->cat_ID] = $category;

    return $category_lookup;
    }

    function filter_category_list($exclusions) {
    global $user_level;
    global $user_ID;

    $category_lookup = $this->get_category_lookup();

    // find out which categories this user is allowed to view
    $locked = get_settings('userextra_lockedcategories_view');
    $locked_a = $this->options_split($locked);
    $allow = $this->usermeta->get($user_ID, "categories_allow", true);
    $allow_a = $this->options_split($allow);
    $deny = $this->usermeta->get($user_ID, "categories_deny", true);
    $deny_a = $this->options_split($deny);

    // add locked and denied categories to the exclusion string
    foreach ($category_lookup as $id => $category) {
    $name = $category->cat_name;
    if (in_array($name, $allow_a) ||
    (!(in_array($name, $locked_a)) && !(in_array($name, $deny_a)))) {
    // allow category
    } else {
    // exclude category
    $exclusions .= " AND cat_ID $id ";
    }
    }

    return $exclusions;
    }

    add_filter('list_cats_exclusions', array(&$userextra, 'filter_category_list'));

    In the code above, the get_category_lookup function is taken from the Category Levels plugin by David Coppit.

    I think there is also a bug in the filter_posts() function in userextra. I have ammended it as follows:


    function filter_posts($posts) {
    global $user_level;
    if ($user_level == 10)
    return $posts;
    $ok = array();
    if($posts != null) {
    foreach ($posts as $post) {
    if ($this->is_current_user_allowed($post))
    $ok[] = $post;
    }
    }
    return $ok;
    }

  38. A few weeks ago, i finally found your marvelous plugin. Unfortunately, it lacks a little bit of compatibility with WordPress 2.0. This, of course, since user level are replaced by user rights. Since some of my sites depend on your work (possibility to grant or block access to serveral categories), here is my question:

    is there a chance, that you might furnish a new version, or amendements to your fantastic plugin, so that it might be used with Wordpess 2.0?

  39. I’m sorry but I’ve not even downloaded WP2 yet. I use the debian package, and they haven’t moved away from 1.5 yet. Hopefully they will do soon. In any event, I’ll try and give it a go soon.

  40. Hi,

    Great Plugin!!! Exactly what I was looking for since I need to have more info for authors.

    The only problem is when I activate the plugin usermeta I get the following error:

    Warning: Cannot modify header information – headers already sent by (output started at E:DotsnDashes ClientsBAAwebsitewp-contentpluginsusermeta.php:2) in E:DotsnDashes ClientsBAAwebsitewp-adminadmin.php on line 10 (same error for lines 11,12, 13)

    I am using WP version 1.5

    Any help is appreciated as I would love to take advantage of the userextra plugin but that gives the same error.

    Thanx!
    Erum

  41. Hey there, you’ve got a wonderful plugin.

    I’m excited to upgrade to WP2.0, any chance that we can expect a compatible version upgrade sometime in the near future?

    Thanks so much for all your hard work!!!

  42. I agree with the others: You’ve done a great job developping this excellent plugin. It doesn’t it run on WP 2.0, does it ? Are you planning to release an updated version for WP 2.0 ?

  43. Plugin is working well, but I don’t know how to call the data in the template or list author ordered by new fields.
    I’m sorry, but I’m only a nosey graphic designer.
    Someone can help me? Thank you.

  44. I’m sorry, I found how to put the information in the template Address:
    get(get_the_author_ID(), “address”, true);
    ?>
    Now I don’t know how to order the author by new fields. Thanks.

  45. I’ve updated usermeta/userextra for WP 2.0.

    **NOTE** You must read the documentation for how to upgrade to WP 2.0 if you have installed Usermeta. Otherwise, it goes horribly wrong for your WP installation and you may have to restore from a backup!

    Please go to this new page userextra-goes-wp-20

Comments are closed.