Thursday, September 29, 2011

Wordpress Comment Extra Fields Plugin

I made the first version of a plugin I will continue to develop for the next weeks. How to use it/features list:
  • install the plugin (copy it to wp-content/plugins);
  • activate it
  • go to Settings. The plugin adds a new option under that menu: Comment Extra Fields
  • in Comment Extra Fields page you can see the extra fields already defined (and edit / delete each of them) or define new extra fields to be added to your comment form
  • all fields are mandatory (even not all tested for that)
  • the types of fields one can define on admin are:
    • text field
    • textarea
    • checkboxes: field to define the values to display on front comment form
    • radio buttons: field for values
    • drop down: field for values
    • file: the upload on front is made using swfupload for jquery
    • (database) db select: fill in the name of a table (with or without the wordpress prefix) and 2 column names for id and values and on front the drop down will be populated with the database values
  • mouse over the labels and, if there are any, tooltips with hints will be shown
  • on front the plugin comes with a .css using twentyeleven form style
More features to come:
  • allow extra fields to be required
  • add date extra field type
  • allow extra fields to be shown on logged in user or not logged in user
  • add option to remove the default comment fields: author, url and email
  • on admin side allow user to define the HTML code for more flexible DOM display
The first version can be found at this link.

Edit
WordPress.org accepted my plugin, just added it to their SVN (heh:D). I will post link here asap it is available (where's the wittle happy monkey? where's the wittle happy monkey? a-gu-gu-gu to me!).

Edit
Best link

Saturday, September 17, 2011

Wordpress WPML Edits

In one of my recent projects I had to use WPML, a very well done plugin for Wordpress for Multi Languages sites. It is based on the idea of keeping translations of different posts in another posts linked to the first one. This way the problem of translated URLs is solved in a very elegant manner. Also all fields appear only one time per translation (which is really nice. If you have 10 fields and you need to translate it in almost 30 languages you won't end up with almost 300 fields on a post edit page).

My problem appeared when I had to define some custom languages and then I wanted to change their names. On a site there can be different content for users whith IP from Europe and have their browser set to English and users with IP from US and their browser language set to English...so I need the default en plus some user defined language, let's say en-euro. If instead of en-euro I wanted to use en-emea the only possible solution would have been to define the new language and use the new one. So, I ended up looking in all _icl tables and try to figure out where the language codes are used. Same thing for a language name. After updating information in those tables the changes were not visible unless I deleted the plugin's cache (kept in wp_options, option_name='_icl_cache').

There are some risks in using my new plugin:
  • I didn't test it for all types of WPML translations;
  • I don't know what happens if one had already made mane translations and then deletes the plugin's cache from wordpress' database (of course, I can figure out from WPML code, but I had been too busy for that. If I get any emails with problems related to this issue described I will try to go deeper into this issue);
  • There might be still hidden issues with this approach (maybe the creators of the WPML plugin had their reasons not to include this option. On edit languages form the fields for language name and code are disabled...)
I recommend using my plugin before starting to translate, if possible. The plugin can be downloaded from here.

After you copy the .zip's content into wp-content/plugins directory and you activate it, a new option will appear under Settings menu called WPML Edits. When you click on it a form will appear where you can set the Old code, New code, Old name and/or New name and when you click Apply changes the database updates run. You need to use an already existing code/language name for Old code and Old name values and a not already existing code/language name for New fields values.