【发布时间】:2019-03-23 12:27:14
【问题描述】:
我正在尝试使用以下代码将变量添加到调色板。前两种颜色有效,但没有添加我的第三种颜色,正如您在我的代码中看到的那样; echo 将显示来自 CMS 的正确颜色,但当它进入函数时,此变量不起作用。
// Get current user identification
$current_user = wp_get_current_user();
$current_role = $current_user->roles[0];
// Loop through ACF repeater in the options
if( have_rows('group_colour', 'options') ):
while ( have_rows('group_colour','options') ) : the_row();
// Set the selected user role and the colour
$colourrole = get_sub_field('user_role');
$colourvalue = get_sub_field('role_colour');
// If options user role matches the logged in user, get the colour and remove the #
if ($current_role == $colourrole){
$colour_no_hash = str_replace('#', '', $colourvalue);
echo $colour_no_hash;
// Customize the TinyMCE Color Palette. Attempting to add a colour for 'Custom Login'. Other 2 colours work.
function wptb_tinymce_options($options) {
$custom_colours = '"000000", "Black",
"00AC9F", "Custom Teal",
"' . $colour_no_hash . '", "Custom Login"';
$options['textcolor_map'] = '['.$custom_colours.']';
return $options;
}
add_filter('tiny_mce_before_init', 'wptb_tinymce_options');
}
endwhile;
else :
endif;
任何帮助表示赞赏。
【问题讨论】:
-
我很好奇为什么
$custom_colours不是 assoc 而是 CSV 字符串?作为一个副手会不会更容易? -
抱歉,我不知道你说的 assoc 是什么意思?
-
对不起,我本来应该澄清的,但我觉得很懒。我的意思是一个关联数组,例如
$custom_colours = [ '000000' => 'Black', [...] ] -
@Script47 我会看看这个,我在网上找到了这个改变所见即所得颜色的例子,并希望我能将我的代码集成到其中。这会很遥远吗?
-
将TinyMCE 与color picker plguin 一起使用会不会更容易?
标签: php wordpress function advanced-custom-fields