目前,我已经成功地在WordPress的TinyMCE编辑器中添加了一行快捷键。问题是,只有管理员才能看到该行,我也需要贡献者和编辑器来查看它。我已经检查了法典中的add\\u action和add\\u filter,我看不到任何指示用户角色或类似角色的特定参数。如何修改此代码,以便所有登录的用户都可以看到新行,而不仅仅是管理员?下面是我用来将行添加到编辑器窗口的代码:
// add shortcode buttons to the tinyMCE editor row 3
function add_button_3() {
if ( current_user_can(\'edit_posts\') && current_user_can(\'edit_pages\') )
{
add_filter(\'mce_external_plugins\', \'add_plugin_3\');
add_filter(\'mce_buttons_3\', \'register_button_3\');
}
}
//setup array of shortcode buttons to add
function register_button_3($buttons) {
array_push($buttons, "dropcap", "divider", "quote", "pullquoteleft", "pullquoteright", "boxdark", "boxlight", "togglesimple", "togglebox", "tabs", "signoff", "columns", "smallbuttons", "largebuttons", "lists");
return $buttons;
}
//setup array for tinyMCE editor interface
function add_plugin_3($plugin_array) {
$plugin_array[\'lists\'] = get_template_directory_uri().\'/js/customcodes.js\';
$plugin_array[\'signoff\'] = get_template_directory_uri().\'/js/customcodes.js\';
$plugin_array[\'dropcap\'] = get_template_directory_uri().\'/js/customcodes.js\';
$plugin_array[\'divider\'] = get_template_directory_uri().\'/js/customcodes.js\';
$plugin_array[\'quote\'] = get_template_directory_uri().\'/js/customcodes.js\';
$plugin_array[\'pullquoteleft\'] = get_template_directory_uri().\'/js/customcodes.js\';
$plugin_array[\'pullquoteright\'] = get_template_directory_uri().\'/js/customcodes.js\';
$plugin_array[\'boxdark\'] = get_template_directory_uri().\'/js/customcodes.js\';
$plugin_array[\'boxlight\'] = get_template_directory_uri().\'/js/customcodes.js\';
$plugin_array[\'togglesimple\'] = get_template_directory_uri().\'/js/customcodes.js\';
$plugin_array[\'togglebox\'] = get_template_directory_uri().\'/js/customcodes.js\';
$plugin_array[\'tabs\'] = get_template_directory_uri().\'/js/customcodes.js\';
$plugin_array[\'columns\'] = get_template_directory_uri().\'/js/customcodes.js\';
$plugin_array[\'smallbuttons\'] = get_template_directory_uri().\'/js/customcodes.js\';
$plugin_array[\'largebuttons\'] = get_template_directory_uri().\'/js/customcodes.js\';
return $plugin_array;
}
add_action(\'init\', \'add_button_3\'); // add the add_button function to the page init
最合适的回答,由SO网友:helenhousandi 整理而成
if语句希望用户能够发布文章和页面,这在默认情况下仅适用于管理员和编辑器。您确定编辑器看不到按钮吗?如果你想让任何可以编辑帖子的人看到按钮(例如作者和贡献者),请选中edit_pages
或者使用or语句(这在大多数安装中是不太可能的,但我认为可能会发生)。
因此,不是:
if ( current_user_can(\'edit_posts\') && current_user_can(\'edit_pages\') )
使用
if ( current_user_can(\'edit_posts\') )
或
if ( current_user_can(\'edit_posts\') || current_user_can(\'edit_pages\') )