How to hack fluent comment experience
-
Hello wordpress.
Until today, i throught good about wordpress. Code is Poetry, yes… It’s PHP, okay. There is PHP5 for some days out now, so for WP v4 there should those features also be used!! (Not function get_some() { global $some; return $some->get(); } !!)
Code is poetry…
What i really don’t like: I write a big comment, then i’m going to send it, and the script tells me: you forgot something, go back and write again!
This usually happens, because the dev of that script doesn’t postback the data – or even sends the form to another page. The current WP version is working exactly this bad way, and dies (wp_dies) the php on errors.
How to workaround? I needed to rewrite three functions, namely comment_form, wp_new_comment and wp_allow_comment. I added one function ValidateAndSave_Comment and a global variable $validationErrors.
It’s bad, there’s no other way but touching core files.Basically, the ValidateAndSave_Comment will be added as action to wp_loaded. It simply fills the $validationErrors array, so if (empty($validationErrors)) it’s valid – will be saved and redirected to the GET url.
If it’s invalid, on rendering the comment_form, i can simply repopulate the filled-in values and display additional validation error messages. Much easier and user-friendly as posting to a dead error message, where a user has to go back, maybe losing any data (what’s typical for bad coded php sites).Code: https://pastebin.com/1P3x2yPc
Simply copy the poetry to your theme’s functions.php and call somewhere after your wp_list_comments the new twentyeleven_comment_form function.This was my first day in wordpress. Don’t use my code, if you can’t read it line by line. 03:26… thought about a bed, but i believe there will be a coffee in between ??
- The topic ‘How to hack fluent comment experience’ is closed to new replies.