Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
add_action( 'edit_category', 'baw_save_term_color' );
add_action( 'create_category', 'baw_save_term_color' );
function baw_save_term_color( $term_id ) {
if ( defined( 'DOING_AJAX' ) ) {
return;
}
if ( ! isset( $_POST['add_term_meta_color_nonce'] ) ||
! isset( $_POST['baw_term_color'] ) ||
! wp_verify_nonce( $_POST['add_term_meta_color_nonce'], 'add_term_meta_color' )
) {
wp_nonce_ays( '' );
}
$color = $_POST['baw_term_color'];
$color = preg_match('|^#([A-Fa-f0-9]{3}){1,2}$|', $color ) ? $color : false;
if ( $color ) {
update_term_meta( $term_id, 'color', $color );
} else {
delete_term_meta( $term_id, 'color' );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment