2015-11-07 19:32
浏览 58

Wordpress get_option变量而不使用未定义的常量

My plugin i have many options. I use get_option and store it as an array so its easier to use.

function woomps_get_options() {
    $options = array(
        'sub01' => get_option(woomps_sub01),
        'sub02' => get_option(woomps_sub02),
    return $options;

This produces this notice for each line:

[TIME] PHP Notice:  Use of undefined constant woomps_sub01 - assumed 'woomps_sub01' in "DOMAIN"\settings\options.php on line 9

I dont understand why i should define woomps_sub01 first or how i should define it. But my question is rather: Why is this not a correct way to get a WP option and what is the better way?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douxu3732 2015-11-07 20:16

    PHP is simply telling that you're passing to the function a undefined constant but probably you meant 'woomps_sub01' as a string.

    Just put quotes like this get_option('woomps_sub01') and the notice will go away.

    解决 无用
    打赏 举报

相关推荐 更多相似问题