0

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

1 Answer 1

2

The 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' );
}
1
  • Just a note to let you know that I have made the changes that you have suggested, Jacob, and this has resolved the problem entirely. Many thanks for your helpful and swift response.
    – Martyn
    Commented Apr 9, 2020 at 8:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.