Wordpress get_option to variable without use of un

2019-08-12 09:30发布

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?

标签: php wordpress
1条回答
走好不送
2楼-- · 2019-08-12 09:52

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.

查看更多
登录 后发表回答