我正在尝试在wordpress设置API中添加颜色选择器以进行插件开发。但我这样做面临着问题。我有这个用于颜色选择器的代码。
// Create this function for color picker.
add_action( 'admin_enqueue_scripts', 'mw_enqueue_color_picker' );
function mw_enqueue_color_picker( $hook_suffix ) {
// first check that $hook_suffix is appropriate for your admin page
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script( 'my-script-handle', plugins_url('my-script.js', __FILE__ ), array( 'wp-color-picker' ), false, true );
}
//Call it in my input field option
<tr valign="top">
<th scope="row"><label for="cursor_color">ScrollBar Color</label></th>
<td>
<input id= "cursor_color" type="text" name="ppmscrollbar_options[cursor_color]" value="<?php echo stripslashes($settings['cursor_color']);?>" class="my-color-field"/><p class="description">Select Icon holder color here. You can also add html HEX code.</p>
</td>
</tr>
//在my-script.js文件中,我写了这个波纹管代码。
jQuery(document).ready(function($){
$('.my-color-field').wpColorPicker();
});
我没有解决这个问题。谁能告诉我我能做些什么?
答案 0 :(得分:1)
我真的不确定为什么你的代码无效,也许问题不在你发布的代码中......以下几乎与你的代码相同,但是完整的演示:
add_action('admin_menu', 'color_pick_so_23696173');
function color_pick_so_23696173()
{
$my_page = add_dashboard_page(
'colorpick',
'colorpick',
'add_users',
'colorpick-page',
'color_pick_callback_so_23696173'
);
add_action( "admin_print_scripts-$my_page", 'enqueue_so_23696173' );
}
function enqueue_so_23696173()
{
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script(
'colorpick',
plugins_url( 'my-script.js', __FILE__ ),
array( 'wp-color-picker'),
false,
true
);
}
function color_pick_callback_so_23696173()
{
?>
<div class="wrap">
<h2>Test</h2>
<table>
<tr valign="top">
<th scope="row"><label for="cursor_color">ScrollBar Color</label></th>
<td>
<input id= "cursor_color" type="text" name="ppmscrollbar_options[cursor_color]" value="" class="my-color-field"/>
<p class="description">Select Icon holder color here. You can also add html HEX code.</p>
</td>
</tr>
</table>
</div>
<?php
}
my-script.js
与您的完全相同。