Problems and fixes for Jigoshop 1.9.5 in this article: https://drafie-design.nl/another-fix-for-jigoshop/ If you upgrade Jigoshop to the latest version on servers which still use PHP under 5.3., your shop will stop to
Continue reading...This is probably the last post about Jigoshop updates, our host updated PHP on server to 5.3. version. And I’m getting tired about these updates – the guys from Jigoshop seems to take these things as a joke… But is not… some of us use their plugin for shops with thousands of products, is not a joke to take down such a shop for their amusement… Because for me start to looking as an amusement how they code this plugin.
Let’s see about what I’m talking. In the morning I received a comment which said that my solution for Jigoshop 1.9.+ don’t works for 1.9.5. I was wondering why… in the changelog for this update was nothing “dangerous”… Looking in the code… the same “line 32” which can be commented…
So, what happens? I reverted php to 5.2.17 on the server (probably our host already think that I am nuts), I commented the line – in frontend all things goes fine, BUT one big WSOD in backend… Turning on WP_DEBUG revealed nothing… error.log on server? – CLEAN.
Finally, switching back and forth PHP version on server, after half of day of work, with all plugins disabled, INCLUDING Jigoshop, I found the problem – trying to re-enable Jigoshop I got this:
Parse error: syntax error, unexpected T_FUNCTION in /home/(username)/(domain name)/wp-content/plugins/jigoshop/admin/jigoshop-admin.php on line 31
And now come the reason for what I am upset… Looking into this file we can see this function:
1 2 3 4 5 6 7 8 9 |
add_action('admin_notices', function(){ if(isset($_GET['jigoshop_message'])){ switch($_GET['jigoshop_message']){ case 'invalid_variation_price': echo ' '.__('Error! One of variations has invalid price!', 'jigoshop').' break; } } }); |
REALLY??? Why to use an anonymous function here??? What if they write a function compatible with all versions of PHP??? It cost only an ENTER and a word written twice…
1 2 3 4 5 6 7 8 9 10 |
add_action('admin_notices', 'upset_jigoshop'); function upset_jigoshop() { if(isset($_GET['jigoshop_message'])){ switch($_GET['jigoshop_message']){ case 'invalid_variation_price': echo ' '.__('Error! One of variations has invalid price!', 'jigoshop').' break; } } }; |
But, stay, this wasn’t all – another error on activation:
Parse error: syntax error, unexpected T_FUNCTION in /home/(username)/(domain name)/wp-content/plugins/jigoshop/admin/write-panels/product-types/variable.php on line 204
Going to that file – another anonymous function!!!!
1 2 3 4 5 6 |
if(!is_numeric($meta['regular_price'])){ add_filter('redirect_post_location', function($location){ return add_query_arg('jigoshop_message', 'invalid_variation_price', $location); }); $meta['regular_price'] = 0.0; } |
For what to use such constructions??? For clarity or readability? Don’t look better than classical functions… Below is the filter used normally, much more readable:
1 2 3 4 5 6 7 |
if(!is_numeric($meta['regular_price'])){ add_filter('redirect_post_location', 'upset_jigoshop_loc'); function upset_jigoshop_loc($location){ return add_query_arg('jigoshop_message', 'invalid_variation_price', $location); }; $meta['regular_price'] = 0.0; } |
In this way are written all actions and filters in plugins and themes – the function is defined separately than call… Only Jigoshop try to force all Internet to upgrade to PHP 5.3.+… I have news for Jigoshop – some of us simply cannot upgrade – some users paid money for customized plugins/themes which cannot be upgraded… Jigo-guy’s know that I paid for a Carousel plugin which aren’t anymore on CodeCanyon?… I paid for Jigoshop Prices by User and now Chris moved his site and closed his shop…
It is so hard to take care about your users??? I know that the things evolve everywhere, but at least keep a minimum necessary for a functional shop even on older servers… Even if they cannot benefit of the new features, keep the old shops as they was…. THE USERS FROM THESE SERVERS WAS WITH YOU FROM THE BEGINNING!
Even the problem with “line 32” can be solved by Jigoshop in a more elegant way than blocking the shops… So in the file jigoshop-web-optimization.php from /wp-content/plugins/jigoshop/plugins/jigoshop-web-optimization-system replace the line 32 (new \Jigoshop\Web\Optimization();) with:
1 2 3 4 5 6 7 |
if (!defined('PHP_VERSION_ID')) { $version = explode('.', PHP_VERSION); define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2])); } if (PHP_VERSION_ID > 50300) { new \Jigoshop\Web\Optimization(); } |
In this way the plugin will check itself the php version of the server and will activate the new web optimization system only on servers which support this. The shops builded on lower version will works as in previous versions, without optimization….
Even this is not a problem of PHP version… Since when the best coding practices was deprecated? After few updates even for original programmer will be hard to find his own functions when hundreds of them will be named just function()…. You can make a plugin for your own purpose on your own server and code it in this way…. but not when thousands of users expect better versions, not worst… And this changes don’t cost nothing, are easy to implement, just one or few lines of code….
In conclusion… if you still are on PHP 5.2. and you cannot upgrade to PHP 5.3. – replace the above function in their respective files, including the last function (or comment the line as in my previous post: https://drafie-design.nl/quick-fix-for-jigoshop-1-9-on-servers-with-php-below-5-3/)… or start thinking to move your shop to Woocommerce (I never thought that will be a day when I say that)…………
Don’t think that on PHP 5.3 all things works perfectly – after installing Jigoshop 1.9.5 from repository, without any change in it’s files, on a server with php 5.3.28, their duck-egg color is spreaded on all admin pages. With php 5.3.16 I don’t see the same problem… I don’t know from where is coming this problem, I am just too tired to dig for every inconsistence in codes…