我已经为wordpress插件设置了na选项页面。在表格I中使用带有wp颜色选择器的字段。一切工作正常,选择器确实以这种形式显示但是在提交时Picker的值没有被保存:
以下是插件文件中的代码:
add_action( 'admin_enqueue_scripts', 'findMeSpot_enqueue_color_picker' );
function findMeSpot_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('inc/my-script.js', __FILE__ ), array( 'wp-color-picker' ), false, true );
}
add_action('admin_menu', 'findmespot_add_options_page');
function findmespot_add_options_page(){
add_options_page('FindMeSpot Settings', 'FindMeSpot', 'manage_options', 'findmespot', 'findMeSpot_options_page');
add_action( 'admin_init', 'register_findMeSpot_settings' );
}
function findMeSpot_options_page(){
require 'inc/options_page.php';
}
function register_findMeSpot_settings(){
register_setting('findMeSpot_display_settings_group', 'findMeSpot_display_settings');
}
在这里表格:
<?php echo var_dump(get_option('findMeSpot_display_settings'))?>
<br class="clear" />
<p><strong>Settings to display the map in the frontend</strong></p>
<table class="widefat">
<thead>
<form method="post" action="options.php">
<?php settings_fields( 'findMeSpot_display_settings_group' ); ?>
<?php do_settings_sections( 'findMeSpot_display_settings_group' ); ?>
<tr>
<th class="row-title"><?php esc_attr_e( 'Setting:', 'wp_admin_style' ); ?></th>
<th><?php esc_attr_e( 'Options:', 'wp_admin_style' ); ?></th>
</tr>
</thead>
<tbody>
<tr>
<td class="row-title"><label for="tablecell"><?php esc_attr_e(
'Feed ID:', 'wp_admin_style'
); ?></label></td>
<td><input type="text" value="<?php echo get_option('findMeSpot_display_settings')['ID'] ?>" size="60" name="findMeSpot_display_settings[ID]"/><p class="description">Enter the ID of your public feed from findmespot.com. You find this ID, when you open your feed in the URL:
http://share.findmespot.com/shared/faces/viewspots.jsp?glId=<code>0XapxKiqW4RCHYhVkaCBpaHT3cNMUcEef</code></p></td>
</tr>
<tr class="alternate">
<td class="row-title"><label for="tablecell"><?php esc_attr_e(
'Map width:', 'wp_admin_style'
); ?> </label></td>
<td><input type="text" value="<?php echo get_option('findMeSpot_display_settings')['mapWidth'] ?>" name="findMeSpot_display_settings[mapWidth]" id="map_width" /><p class="description"> Enter the width of the map. 500px by default.</td>
</tr>
<tr>
<td class="row-title"><?php esc_attr_e( 'Map height:', 'wp_admin_style' ); ?></td>
<td><input type="text" value="<?php echo get_option('findMeSpot_display_settings')['mapHeight'] ?>" name="findMeSpot_display_settings[mapHeight]" id="map_width" /><p class="description"> Enter the height of the map. 500px by default.</td>
</tr>
<tr class="alternate">
<td class="row-title"><?php esc_attr_e(
'Map type:', 'wp_admin_style'
); ?></td>
<td><select name="findMeSpot_display_settings[mapType]">
<option value="ROADMAP">ROADMAP</option>
<option value="TERRAIN">TERRAIN</option>
<option value="SATELITE">SATELITE</option>
<option value="HYBRIDE">HYBRIDE</option>
</select></td>
</tr>
<tr>
<td class="row-title"><?php esc_attr_e(
'Show legend:', 'wp_admin_style'
); ?></td>
<td><input type="checkbox" value="true" name="findMeSpot_display_settings[showLegend]" checked="true"></td>
</tr>
<tr class="alternate">
<td class="row-title"><?php esc_attr_e(
'Legend height:', 'wp_admin_style'
); ?></td>
<td><input type="text" value="<?php echo get_option('findMeSpot_display_settings')['legendHeight'] ?>" name="findMeSpot_display_settings[legendHeight]" width="3"></td>
</tr>
<tr>
<td class="row-title"><?php esc_attr_e(
'Auto refresh:', 'wp_admin_style'
); ?></td>
<td><input type="text" value="<?php echo get_option('findMeSpot_display_settings')['autoRefresh'] ?>" name="findMeSpot_display_settings[autoRefresh]" width="3"><p class="description">The auto refresh interval for the track data. By default 5 minutes. You should not use less than 3 minutes because it is possible that requests can be blocked if you hit the server in an higher frequence.</p></td>
</tr>
<tr class="alternate">
<td class="row-title"><?php esc_attr_e(
'Polyline:', 'wp_admin_style'
); ?></td>
<td></td>
</tr>
<tr>
<td class="row-title"><?php esc_attr_e(
'Stroke color:', 'wp_admin_style'
); ?></td>
<td><input type="text" name="findMeSpot_display_settings[strokeColor]" value="<?php echo get_option('findMeSpot_display_settings')['strokeColor'] ?>"
class="my-color-field" data-default-color="#effeff" />
<p class="description">The color of the line on the map that connects your waypoints.</p></td>
</tr>
<tr class="alternate">
<td class="row-title"><?php esc_attr_e(
'Stroke weight:', 'wp_admin_style'
); ?></td>
<td><input type="text" name="findMeSpot_display_settings[strokeWeight]" value="3" /><p class="descritpion">The weight of the line that connects your waypoints on the map. 3px by default.</p></td>
</tr>
<tr class="alternate">
<td class="row-title"><input class="button-primary" type="submit" name="Example" value="<?php esc_attr_e( 'save changes' ); ?>" /></td>
<td></td>
</tr>
</tbody>
<tfoot>
<tr>
<th class="row-title"><?php esc_attr_e( 'findMeSpot-Plugin', 'wp_admin_style' ); ?></th>
<th><?php echo( '© ' . date(Y) . ' By <a href="http://www.poppgerhard.at">Popp Gerhard</a> if you need help, <a href="mailto:office@sewemo.eu"> mail me here.</a>'); ?></th>
</tr>
</tfoot>
</form>
</table>
和排队的剧本:
jQuery(document).ready(function($){
$('.my-color-field').wpColorPicker();
});
正如你所看到我只使用wp标准颜色选择器和一系列设置。我不知道为什么选择器的值不会附加到posts数组。
有人建议如何调试吗?
感谢维也纳的好意见。 关于霍华德