«

»

Howto Fix WordPress – There Has Been A Critical Error On Your Website

A few days back i was contacted by a blog reader who pointed out that some of my posts were not displayed correctly. Actually both good and bad news same time:)

It means people are actually reading my blog posts and in this case it was a 3.5 old post he was trying to access. On the other hand not so good since it usually requires some investigation and configuration changes to get rid of the errors.

I’m using wordpress which i think is quite nice with it’s built-in capabilities and admin interface.

The error message reported for the specific blog post and several others was:

There has been a critical error on your website.

Two options – download and investigate the log file (3.5 GB) to see what’s going on or take the quick route of enabling web site debug mode and have the platform display the root cause. Since i’m a bit lazy i enabled debugging and the rest of the blog article will describe that process and how i fixed the problem.

  • Step 1- enable debug mode by editing the file wp-config.php and change the section about debugging from “define(‘WP_DEBUG’, false);” – to “define(‘WP_DEBUG’, true);”
  • Step 2 – Reload web browser to get an extended error message which came back as:
    • Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/magander.se/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

      Notice: Undefined offset: 0 in /var/www/magander.se/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 532
      Fatal error: Uncaught Error: Call to a member function id() on array in /var/www/magander.se/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php:36 Stack trace: #0 /var/www/magander.se/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php(538): CrayonFormatter::format_code(”, Array, Object(CrayonHighlighter)) #1 [internal function]: CrayonFormatter::delim_to_internal(Array) #2 /var/www/magander.se/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php(516): preg_replace_callback(‘#()#msi’, ‘CrayonFormatter…’, ‘#!/bin/bash\r\n# …’) #3 /var/www/magander.se/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_highlighter.class.php(166): CrayonFormatter::format_mixed_code(‘#!/bin/bash\r\n# …’, Object(CrayonLang), Object(CrayonHighlighter)) #4 /var/www/magander.se/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_highlighter.class.php(186): CrayonHighlighter->process() #5 /var/www/magander.se/public_html/wp-content/plugins/crayon-synta in /var/www/magander.se/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 36
  • Step – 3 – Pretty helpful error messages received in Step 2 so next up was to deactivate the plugin, Crayon Syntax Highlighter, causing the issues
  • Step 4 – When done change the debugging config back to “false” and then reload the web browser

Voila – now it looks as it’s supposed to:)

————————————————————————————————————————————————————————-