Quiero agregar un campo personalizado a mis categorías donde el usuario pueda codificarlas por colores. He agregado el campo pero quiero usar el selector de colores integrado (ya sea tinyMCE o el farbtastic) para dar al usuario una forma fácil de elegir colores. No puedo averiguar cómo agregar la funcionalidad, sin embargo, esto es lo que tengo hasta ahora:
Configuración de campo de categoría
/** Add New Field To Category **/
function extra_category_fields( $tag ) {
$t_id = $tag->term_id;
$cat_meta = get_option( "category_$t_id");
?>
<tr class="form-field">
<th scope="row" valign="top"><label for="cat_Image_url"><?php _e('Category Image Url'); ?></label></th>
<td>
<input type="text" name="Cat_meta[bgc]" id="colorinput" size="3" style="width:20%;" value="<?php echo $cat_meta['bgc'] ? $cat_meta['bgc'] : '#fff'; ?>" class="my-color-field" />
<div id="colorpicker"></div><br />
<span class="description"><?php _e('Can't Think of A Desc Yet, Suggestions?'); ?></span>
<br />
</td>
</tr>
<?php
}
add_action ( 'category_add_form_fields', 'extra_category_fields');
/** Save Category Meta **/
function save_extra_category_fileds( $term_id ) {
if ( isset( $_POST['Cat_meta'] ) ) {
$t_id = $term_id;
$cat_meta = get_option( "category_$t_id");
$cat_keys = array_keys($_POST['Cat_meta']);
foreach ($cat_keys as $key){
if (isset($_POST['Cat_meta'][$key])){
$cat_meta[$key] = $_POST['Cat_meta'][$key];
}
}
//save the option array
update_option( "category_$t_id", $cat_meta );
}
}
add_action ( 'edited_category', 'save_extra_category_fileds');
Script Colorpicker (Farbtastic) - No funciona
/** Enqueue Color Picker **/
function farbtastic_scripts() {
wp_enqueue_script( 'jQuery' );
wp_enqueue_style( 'farbtastic' );
wp_enqueue_script( 'farbtastic' );
?>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#colorpicker').hide();
jQuery('#colorpicker').farbtastic("#colorinput");
jQuery("#colorinput").click(function(){jQuery('#colorpicker').slideToggle()});
});
</script>
<?php
}
add_action( 'admin_enqueue_scripts', 'farbtastic_scripts' );
:: Editar :: Si lo hace más fácil, tengo el complemento "Campos personalizados avanzados" que tiene una opción de selección de colores. Estoy mirando para ver si sería más fácil usar eso.