I am using a child theme of TwentyTwelve (the customer is always right).
I recently started getting the following warning bot at the top of the Dashboard and on the Jetpack panel of the Dashboard:
"Warning: Use of undefined constant register_setting - assumed 'register_setting' (this will throw an Error in a future version of PHP) in /home/leytongr/public_html/wp-content/plugins/theme-logo-plugin/themelogo.php on line 81."
This is the code starting at line 80, so you will see why I have raised the query here:
function tl_init(){
if(function_exists(register_setting))
{ register_setting("tl-options", "tl_logo_src"); }
}
I would be grateful if you can suggest a means of recoding this section so that the warning message disappears (the website continues to work fine but I'm slightly concerned that a PHP update may change this).
Thanks in anticipation
I am using a child theme of TwentyTwelve (the customer is always right).
I recently started getting the following warning bot at the top of the Dashboard and on the Jetpack panel of the Dashboard:
"Warning: Use of undefined constant register_setting - assumed 'register_setting' (this will throw an Error in a future version of PHP) in /home/leytongr/public_html/wp-content/plugins/theme-logo-plugin/themelogo.php on line 81."
This is the code starting at line 80, so you will see why I have raised the query here:
function tl_init(){
if(function_exists(register_setting))
{ register_setting("tl-options", "tl_logo_src"); }
}
I would be grateful if you can suggest a means of recoding this section so that the warning message disappears (the website continues to work fine but I'm slightly concerned that a PHP update may change this).
Thanks in anticipation
Share Improve this question edited Apr 15, 2020 at 13:12 Chetan Vaghela 2,4084 gold badges10 silver badges16 bronze badges asked Apr 8, 2020 at 10:56 MartynMartyn 11 Answer
Reset to default 2The issue is this line:
if(function_exists(register_setting))
register_setting
is not in quotes. Values without quotes are how you refer to constants in PHP, but there's no constant with that name, because it's supposed to be 'register_setting'
, with quotes.
PHP recognises this mistake, and is interpreting this as if you had included the quotes, but it's warning you that it won't do this in the future, so you should fix it now. So just add quotes to fix the issue. You might as well clean up the formatting while you're at it.
function tl_init(){
if ( function_exists( 'register_setting' ) ) {
register_setting( 'tl-options', 'tl_logo_src' );
}
}
That being said, you can probably remove that condition. That is a backwards compatibility measure to ensure compatibility with older versions of WordPress that do not have this function, but that function has now been in WordPress for 12 years. You don't need to check it anymore:
function tl_init(){
register_setting( 'tl-options', 'tl_logo_src' );
}