最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

child theme - Started getting warning message following host's PHP upgrade

programmeradmin4浏览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

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 1
Add a comment  | 

1 Answer 1

Reset to default 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' );
}
发布评论

评论列表(0)

  1. 暂无评论