16 Dec

Private notes plugin

More than a year ago, Fred of vituperation wrote a plugin to use private notes under wordpress. After installing this plugin on ochblog, pretty soon some users complained about errors they where getting. The funny thing was that not all users had this problem, most of them where fine.

Now, usually on ochblog, someone else installs the the plugins, and if there are any problems with it, he tries to solve these by himself. If he can't get a grab on it, he calls me, after wich I dig into it. This usually results into some very onorthodox hacking of source codes.

In this case, I was totally in the dark. For some reason there was one user who couldn't use the notes, for other users it was fine. We tried to contact Fred, but he was busy renovating his house, so no help from there. So I dug into the code of this plugin.

First of, the error produced told me that there where some functions defined twice. I solved this by pulling all of the functions out of the main plugin file, and put these in a separate functions.php. This file then gets called via a include_once command, in an attempt to get rid of the error. This worked partially, the user involved didn't see the errors anymore. Actually, he didn't see anything concerning this plugin anymore. So there was something else.

Pretty soon, I discovered some code to see if users could use this plugin or not, it goes like this;

  get_currentuserinfo();

  if ($userdata->user_level >= get_option('pn_user_level')) {

I figured there was something going wrong here, so I dugg in the Wordpress database. There I discovered the user mentioned didn't have a user_level setting attached to his account. This seemed pretty weird to me, since I had been using this setting to show or hide some template items reserved for the blog admins in the past. But, some searching revealed that the Wordpress user levels system was abandoned in Wordpress 2, and replaced by the roles system. Since we had updated from Wordpress 1.5 recently, most of the users had a user level assigned to their account, except for this one user who recently registered.

Finding the problem, a solution was easily found. Just change the code to test for capabilities instead of user level, and you're fine. So I did this, and it worked.

But that wasn't the only thing which bothered me ofcourse. I'm not a big fan of users going through the admin panels, I want them to see the blog the way I choose. Since this plugin used the admin panels to show the notes, I decided some more hacking into the plugin code was due. Adding some functions, changing some others, and adding a page template file to the theme directory did the trick. I sent the changes to Fred, but I guess he's still busy rebuilding his house, so now I've decided make the files available for downloading here. Upload it to your plugin dir, then activate the plugin from the admin panels. The page template included is useable for the K2 theme, if you have a different theme, create a new page template and paste this code into it:

<?php
global $userdata;

if (current_user_can(get_option('pn_user_allow')))

pn_user_page();

?>

Create a new page based on this template, and that should be it.

 

12 Responses to “Private notes plugin”

  1. Filip

    thanx... :D

  2. Taylor

    Hello-

    Thanks for the upgrades you made to this plugin. I was wondering if you could help me out with an issue. I can only get the private notes to appear for anybody set as a "contributor" or higher. In the "For sending/receiving notes user must be able to" field, I have "read", but of my 200+ registered users, I can only send a private note to the two other people, who are set to contributors.

    Thanks for any assistance you can provide!

  3. Zoute snor

    Hello Taylor,

    Sorry about that, it seems like the files in the zip weren't the correct ones. Please download the zip again, it should work now.

  4. Taylor

    Thanks for looking into this. I think we're almost there. I'm still only able to see people in the "To:" field who are set to "Contributor" or higher. I can now see the "private notes" at a "subscriber" level, but a "subscriber" can only send to a "contributor" or higher level.

    Thanks for your help.

  5. Zoute snor

    Wow, that's what you get for not properly testing plugins I guess... Error is in the pn_compose.php file, the zip is updated once again, and should really work now (again).

  6. Taylor

    Fantastic! Works great - thanks for your help.

  7. Zoute snor

    No problem, I always like some feedback, even if it means I have to go to work on something I should have done right the first time.

  8. Rita

    Hi, great plugin and I am happy that someone tries to get it work.

    I activated the plugin, wrote the page and get the following error messagen wen visiting the page. There is also nothing shown in the administration after activating the plugin.

    Do you know any solution for this problems?

    Many greetings,
    Rita

    PN
    
    WordPress Datenbank-Fehler: [Table 'db212906309.pn_folders' doesn't exist]
    SELECT id FROM pn_folders WHERE owner_user_id = 1 AND name = 'Inbox'
    
    WordPress Datenbank-Fehler: [Table 'db212906309.pn_folders' doesn't exist]
    INSERT INTO pn_folders (owner_user_id,name) VALUES (1,'Inbox')
    
    WordPress Datenbank-Fehler: [Table 'db212906309.pn_folders' doesn't exist]
    SELECT id FROM pn_folders WHERE owner_user_id = 1 AND name = 'Inbox'
    Uh oh.
    
    Something's broken in the notes plugin. Please let the site administrator know. Unfortunately, you can't do this by sending him/her a note right now.
    
  9. Simon

    Rita,

    It seems like the tables for the plugin are not created. Normally these are created if you go to the plugin admin page after activating it (under manage->private notes). If this page isn't available, you could try de- and reactivating the plugin.

    It is also possible to create the tables manually, but I have no experience with that sort of thing.

  10. Rita

    Simon, thank qou for your answer. I deactivated and reactivated the plugin, got it in the admin panel now and can open the new created page. But when I choose "send a note" I get a 404 page not found message.

    Also I don't understand, for what reason I should create folders. When I try to create one, I get the following message:

    Fatal error: Cannot redeclare pn_script() (previously declared in /homepages/42/d212713488/htdocs/cijou/wp-content/plugins/private_notes/pn_functions.php:5) in /homepages/42/d212713488/htdocs/cijou/wp-content/plugins/private_notes/pn_functions.php on line 3
    

    I'm using wordpress 2.2.3.

    I would really apprexiate if you could help me. If you like, I could do a german translation for you.

    Rita

  11. Rita

    Oh! Sorry for disturbing the layout!

  12. Simon

    Well, concerning the fatal error part when trying to create a folder: I got that too on a different site, it didn't use to happen on previous WordPress versions though. I just took the possibility to create folders out of the plugin, by opening the file pn_user.php, and removing the lines:

    <?php
      if (pn_folder_count($userdata->ID)
      <p> </p>
       <form name="CreateFolder" action="<?php echo pn_folder_list_url2(); ?>" method="POST">
          <label for="name"> Create new folder: </label>
          <input type="hidden" name="create" value="1">
          <input type="text" name="name" value="" size="30">
          <input type="submit" name="Submit" value="Create »">
    
      </form>
    <?php
      }
    ?>

    These lines are found near the end of the document.

    Now for the 404 error when trying to send a note, I really have no clue on how to fix that. I'll try to look into it later, but unfortunately I have little time to do this, and it's kind of difficult to fix these issues since I didn't (and probably couldn't) originally write the plugin.

Trackbacks

Leave a Reply