Bug fix for reading options
-
The grid view in my Media Library was not loading. This was driving me crazy, but I finally figured it out.
Issue: When the setting hide_cropped is unchecked and WP_DEBUG is true, the grid view of the Media library in the admin interface never loads.
Cause: Errors get printed to the admin-ajax response, which is expecting json, and as a result just shows nothing. Looking at the actual ajax response, the errors have to do with ACF-image-crop trying to access a non-existent array index.
Versions: WP 4.4 + ACF 4.4.4 + ACF-image-crop 1.4.7
Warning: Illegal string offset ‘hide_cropped’ in /var/www/arc/web/app/plugins/acf-image-crop-add-on/acf-image-crop-v4.php on line 895
Notice: Uninitialized string offset: 0 in /var/www/arc/web/app/plugins/acf-image-crop-add-on/acf-image-crop-v4.php on line 895Fix: check to see that the result from get_options() is an array and that the array index actually exists:
Change line 895 from
$hide = $options['hide_cropped'];
to
$hide = (is_array($options) && array_key_exists('hide_cropped', $options)) ? $options['hide_cropped'] : false;
Incidentally, a similar thing needs to be done for the actual checkboxes on the settings page:
Warning: Illegal string offset ‘hide_cropped’ in /var/www/arc/web/app/plugins/acf-image-crop-add-on/acf-image-crop-v4.php on line 943
Notice: Uninitialized string offset: 0 in /var/www/arc/web/app/plugins/acf-image-crop-add-on/acf-image-crop-v4.php on line 943
Warning: Illegal string offset ‘retina_mode’ in /var/www/arc/web/app/plugins/acf-image-crop-add-on/acf-image-crop-v4.php on line 955
Notice: Uninitialized string offset: 0 in /var/www/arc/web/app/plugins/acf-image-crop-add-on/acf-image-crop-v4.php on line 955Change line 943 from
$value = $options['hide_cropped'];
to
$value = (is_array($options) && array_key_exists('hide_cropped', $options)) ? $options['hide_cropped'] : false;
and change line 955 from
$value = $options['retina_mode'];
to
$value = (is_array($options) && array_key_exists('retina_mode', $options)) ? $options['retina_mode'] : false;
- The topic ‘Bug fix for reading options’ is closed to new replies.