Be careful before upgrading to PHP 7.3
if you are using Crayon Syntax Highligher WordPress plugin. Your site will crash with fatal Uncaught Error
.
On Crunchify we are using Crayon Syntax Highlighter since last 4 years without any issue.
Recently we upgraded PHP version to 7.3.1 and noticed fatal error on our staging site.
Fatal Error:
Fatal error: Uncaught Error: Call to a member function id() on array in /www/folder_path/public/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php:36 Stack trace: #0 /www/folder_path/public/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 /www/folder_path/public/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php(516): preg_replace_callback('#()#msi', 'CrayonFormatter...', '{\r\n "founder...') #3 /www/folder_path/public/wp-content/plugins/crayon-syntax-highlighter/crayon_highlighter.class.php(166): CrayonFormatter::format_mixed_code('{\r\n "founder...', Object(CrayonLang), Object(CrayonHighlighter)) #4 /www/folder_path/public/wp-content/plugins/crayon-syntax-highlighter/crayon_highlighter.class.php(186): CrayonHighlighter->process() #5 /www/folder_path/public/wp-content/plugins/crayon-syntax-highlighte in /www/folder_path/public/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 36
Warning:
Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /www/folder_path/public/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340
As you see in above error log it’s complaining about id()
method. This plugin hasn’t been upgraded since last 3 years
🙁
How to fix this Fatal error?
Change-1) file crayon_langs.class.php
In order to fix this you need to make changes to crayon_langs.class.php
Open line 340
and replace return preg_replace('/[^\w-+#]/msi', '', $id);
with return preg_replace('/[^\w\-+#]/msi', '', $id);
Change-2) file crayon_formatter.class.php
PHP Warning: preg_replace()
: Compilation failed: invalid range in character class at offset 4 in /www/folder_path/public/wp-content/plugins/crayon-syntax-highlighter in /www/folder_path/public/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php
Delete line 118 and 119 with below 3 lines
Old lines:
$toolbar_height = $font_size * 1.5 . 'px !important;'; $info_height = $font_size * 1.4 . 'px !important;';
New lines:
$crunchify_height = 1.5; $toolbar_height = $_font_size * $crunchify_height . 'px !important;'; $info_height = $_font_size * $crunchify_height . 'px !important;';
Changes-3) crayon_settings.class.php
Fix for Uncaught Error: Undefined class constant ‘SHOW_MIXED’.
Fatal error: Uncaught Error: Undefined class constant 'SHOW_MIXED' in D:\xampp-7.3.1\htdocs\wordpress1\wp-content\plugins\crayon-syntax-highlighter\crayon_settings_wp.class.php:1077 Stack trace: #0 D:\xampp-7.3.1\htdocs\wordpress1\wp-admin\includes\template.php(1530): CrayonSettingsWP::code(Array) #1 D:\xampp-7.3.1\htdocs\wordpress1\wp-admin\includes\template.php(1489): do_settings_fields('crayon_fields', 'crayon_general') #2 D:\xampp-7.3.1\htdocs\wordpress1\wp-content\plugins\crayon-syntax-highlighter\crayon_settings_wp.class.php(220): do_settings_sections('crayon_fields') #3 D:\xampp-7.3.1\htdocs\wordpress1\wp-includes\class-wp-hook.php(286): CrayonSettingsWP::settings('') #4 D:\xampp-7.3.1\htdocs\wordpress1\wp-includes\class-wp-hook.php(310): WP_Hook->apply_filters('', Array) #5 D:\xampp-7.3.1\htdocs\wordpress1\wp-includes\plugin.php(453): WP_Hook->do_action(Array) #6 D:\xampp-7.3.1\htdocs\wordpress1\wp-admin\admin.php(224): do_action('settings_page_c...') #7 D:\xampp-7.3.1\htdocs\wordpress1\wp-admin\options-general.ph in D:\xampp-7.3.1\htdocs\wordpress1\wp-content\plugins\crayon-syntax-highlighter\crayon_settings_wp.class.php on line 1077
How to Download latest version of Crayon Syntax Highlighter?
Here is a link to download latest Crayon Syntax Highlighter plugin: https://github.com/Crunchify/crayon-syntax-highlighter/releases
We are using above version 2.8.6 on Crunchify and it’s running perfectly fine without any issue. Let me know if you see any issue running above plugin and we will fix an issue ASAP.
How to see these error?
Well, you need to enable DEBUG
log to see above errors, else you will see just blank screen.
Open wp-config.php
file and add below 2 lines after $table_prefix
line.
define( 'WP_DEBUG', true ); define( 'WP_DEBUG_LOG', true );