Php 如何在WordPress中将逗号分隔列表(从选项页)作为数组传递

Php 如何在WordPress中将逗号分隔列表(从选项页)作为数组传递,php,wordpress,Php,Wordpress,我在WordPress的管理(仪表板)页面中创建了一个自定义选项菜单 其思想是允许管理员在仪表板中输入Post ID以限制为逗号分隔的值(例如“100102104”)。我想将逗号分隔的值作为数组传递,以限制对具有Post ID的Post的访问 为了限制访问,我尝试在主题文件中获取值: $restricted_ids = array(); $restricted_ids = get_option('_s_theme_options')['restricted_post_ids']; if(is_s

我在WordPress的管理(仪表板)页面中创建了一个自定义选项菜单

其思想是允许管理员在仪表板中输入Post ID以限制为逗号分隔的值(例如“100102104”)。我想将逗号分隔的值作为数组传递,以限制对具有Post ID的Post的访问

为了限制访问,我尝试在主题文件中获取值:

$restricted_ids = array();
$restricted_ids = get_option('_s_theme_options')['restricted_post_ids'];
if(is_single ($restricted_ids)) && !is_user_logged_in()) {
// My code here
}
我对它进行了测试,发现变量“$restricted_ids”没有获得预期的Post ID。例如,如果我输入'123456',$restricted_id将其作为一个数组接收,该数组的值为'1,2,3…',而不是'123456'。 我如何更正“$restricted_id”的代码,以便将输入的Post ID作为数组正确接收


谢谢您的帮助。

尝试从字符串中删除空格,然后使用
explode()将其拆分为一个数组。

$restricted_ids = array();

$post_ids = str_replace(' ', '', get_option('_s_theme_options')['restricted_post_ids']);
$restricted_ids = explode(',', $post_ids);

if(is_single ($restricted_ids) && !is_user_logged_in()) {
  // Do the things
}

mybe base64对条目进行编码?@Jester。谢谢你的评论。然而,我不是那么专业。。。解决此问题的进一步线索?PHP
introde()
是否适合您?