Undefined variable in compat.php of WordPress: error displaying page titles in dashboard
This post was originally published at LionVineyard.com on 2009/02/27
I recently updated to WordPress 2.7.1. On one of the blogs I am administering I am using the qTranslate plugin for multilingual support. Everything is working right but yesterday I went to edit one of the pages only to figure out that the Titles were not displayed and a warning was displayed above the page list. The problem did not appear on other blogs that did not use qTranslate plugin.
The problem:
Page titles not displayed in dashboard and an error appears above page list when having metalanguage support with qTranslate. The warning looked like this:
Warning: htmlspecialchars_decode() expects parameter 1 to be string, NULL given in your_directory_path/wp-includes/compat.php on line 105
The code in compat.php looks like this:
102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
function htmlspecialchars_decode( $str, $quote_style = ENT_COMPAT ) { if ( !is_scalar( $string ) ) { trigger_error( 'htmlspecialchars_decode() expects parameter 1 to be string, ' . gettype( $string ) . ' given', E_USER_WARNING ); return; } if ( !is_int( $quote_style ) && $quote_style !== null ) { trigger_error( 'htmlspecialchars_decode() expects parameter 2 to be integer, ' . gettype( $quote_style ) . ' given', E_USER_WARNING ); return; } return wp_specialchars_decode( $str, $quote_style ); } |
The problem is variable $string on lines 104 and 105 which is not defined. It is passed to the function as $str.
The solution:
Just change $string to $str on lines 104 and 105. The code should look like this:
102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
function htmlspecialchars_decode( $str, $quote_style = ENT_COMPAT ) { if ( !is_scalar( $str ) ) { trigger_error( 'htmlspecialchars_decode() expects parameter 1 to be string, ' . gettype( $str ) . ' given', E_USER_WARNING ); return; } if ( !is_int( $quote_style ) && $quote_style !== null ) { trigger_error( 'htmlspecialchars_decode() expects parameter 2 to be integer, ' . gettype( $quote_style ) . ' given', E_USER_WARNING ); return; } return wp_specialchars_decode( $str, $quote_style ); } |
I did some search and found that the problem is encountered in other cases as well. It is not only due to the multilingual support.


, or by using our 


