我正在使用shortcake UI插件,并努力将一系列短代码注册到UI界面中。
我正在尝试获取所有分类术语(通过get\\u terms()),然后填充接口的数组。现在,我遇到了这样一个分析错误:
Parse error: syntax error, unexpected \';\', expecting \')\' in...
代码如下:
// Register the Featured Pages shortcode with \'Shortcake UI\' plugin
add_action( \'register_shortcode_ui\', \'shortcode_ui_feat_pages\' );
function shortcode_ui_feat_pages()
{
shortcode_ui_register_for_shortcode(
\'featured-pages\',
array(
\'label\' => \'Featured Pages Shortcode\',
\'listItemImage\' => \'dashicons-editor-table\',
\'attrs\' => array(
array(
\'label\' => \'Category\',
\'attr\' => \'category\',
\'type\' => \'select\',
\'options\' => array(
$feat_pages_terms = get_terms(array(\'taxonomy\' => \'featured_page_category\', \'hide_empty\' => false));
foreach($feat_pages_terms as $feat_page_term) :
echo \'array(\\\'value\\\' =>\\\'\' . $feat_page_term->name . \'\\\', \\\'label\\\' =>\\\'\' . $feat_page_term->name . \'\\\'), \';
endforeach;
),
\'description\' => \'Insert the category full name (i.e. Home page)\',
),
array(
\'label\' => \'Columns\',
\'attr\' => \'cols\',
\'type\' => \'select\',
\'options\' => array(
array(\'value\' => \'\', \'label\' => esc_html__(\'\')),
array(\'value\' => 2, \'label\' => esc_html__(\'Two\')),
array(\'value\' => 3, \'label\' => esc_html__(\'Three\')),
array(\'value\' => 4, \'label\' => esc_html__(\'Four\')),
),
\'description\' => \'The number of columns you want to display within a row\',
),
array(
\'label\' => \'Order By\',
\'attr\' => \'orderby\',
\'type\' => \'select\',
\'options\' => array(
array(\'value\' => \'\', \'label\' => esc_html__(\'None\')),
array(\'value\' => \'ID\', \'label\' => esc_html__(\'ID\')),
array(\'value\' => \'author\', \'label\' => esc_html__(\'Author\')),
array(\'value\' => \'title\', \'label\' => esc_html__(\'Title\')),
array(\'value\' => \'name\', \'label\' => esc_html__(\'Name\')),
array(\'value\' => \'date\', \'label\' => esc_html__(\'Date\')),
array(\'value\' => \'modified\', \'label\' => esc_html__(\'Modified\')),
array(\'value\' => \'rand\', \'label\' => esc_html__(\'Random\')),
array(\'value\' => \'menu_order\', \'label\' => esc_html__(\'Menu order\')),
),
\'description\' => \'Choose how you want to order the Featured Pages\',
),
array(
\'label\' => \'Order\',
\'attr\' => \'order\',
\'type\' => \'select\',
\'options\' => array(
array(\'value\' => \'\', \'label\' => esc_html__(\'\')),
array(\'value\' => \'ASC\', \'label\' => esc_html__(\'Ascending\')),
array(\'value\' => \'DESC\', \'label\' => esc_html__(\'Descending\')),
),
\'description\' => \'You can order the pages in ascending or descending order (A-Z or Z-A)\',
)
),
)
);
}
我在注册特色页面数组的代码外测试了foreach循环,它的输出很好。我只是有点难以从自定义帖子类型分类法“featured\\u page\\u category”中填充用于选择的选项。
在创建变量$feat\\u pages\\u terms时,我不喜欢声明获取\\u terms()。
我是否必须在shortcode ui注册之外运行此逻辑,然后将值分解为它?