Wordpress get_option 到变量而不使用未定义的常量 [英] Wordpress get_option to variable without use of undefined constant
问题描述
我的插件有很多选择.我使用 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
我不明白为什么我应该先定义 woomps_sub01 或者我应该如何定义它.但我的问题是:为什么这不是获得 WP 选项的正确方法,什么是更好的方法?
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 只是告诉您正在向函数传递一个未定义的常量,但您可能将 'woomps_sub01'
作为字符串传递给函数.
PHP is simply telling that you're passing to the function a undefined constant but probably you meant 'woomps_sub01'
as a string.
只要加上这样的引号get_option('woomps_sub01')
,通知就会消失.
Just put quotes like this get_option('woomps_sub01')
and the notice will go away.
这篇关于Wordpress get_option 到变量而不使用未定义的常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!