Last active
December 8, 2015 23:01
-
-
Save JulioPotier/ff7e6ca779c4b51e843a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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