Skip to content

Instantly share code, notes, and snippets.

@JulioPotier
Last active December 8, 2015 23:01
Show Gist options
  • Save JulioPotier/ff7e6ca779c4b51e843a to your computer and use it in GitHub Desktop.
Save JulioPotier/ff7e6ca779c4b51e843a to your computer and use it in GitHub Desktop.
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