Or, embed this snippet using GenerateWP WordPress Plugin.

Download

Clone

ColorTAG

class Color_Term_Meta {

	public function __construct() {

		if ( is_admin() ) {

			add_action( 'active-tag_add_form_fields',  array( $this, 'create_screen_fields'), 10, 1 );
			add_action( 'active-tag_edit_form_fields', array( $this, 'edit_screen_fields' ),  10, 2 );

			add_action( 'created_active-tag', array( $this, 'save_data' ), 10, 1 );
			add_action( 'edited_active-tag',  array( $this, 'save_data' ), 10, 1 );

			add_action( 'admin_enqueue_scripts', array( $this, 'load_scripts_styles' ) );
			add_action( 'admin_footer',          array( $this, 'add_admin_js' )        );

		}

	}

	public function create_screen_fields( $taxonomy ) {

		// Set default values.
		$color_colortag = '';

		// Form fields.
		echo '<div class="form-field term-color_colortag-wrap">';
		echo '	<label for="color_colortag">' . __( 'Color TAG', 'activeage' ) . '</label>';
		echo '	<input type="text" id="color_colortag" name="color_colortag" class="color_color_picker" value="' . esc_attr( $color_colortag ) . '"><br>';
		echo '</div>';

	}

	public function edit_screen_fields( $term, $taxonomy ) {

		// Retrieve an existing value from the database.
		$color_colortag = get_term_meta( $term->term_id, 'color_colortag', true );

		// Set default values.
		if( empty( $color_colortag ) ) $color_colortag = '';

		// Form fields.
		echo '<tr class="form-field term-color_colortag-wrap">';
		echo '<th scope="row">';
		echo '	<label for="color_colortag">' . __( 'Color TAG', 'activeage' ) . '</label>';
		echo '</th>';
		echo '<td>';
		echo '	<input type="text" id="color_colortag" name="color_colortag" class="color_color_picker" value="' . esc_attr( $color_colortag ) . '"><br>';
		echo '</td>';
		echo '</tr>';

	}

	public function save_data( $term_id ) {

		// Sanitize user input.
		$color_new_colortag = isset( $_POST[ 'color_colortag' ] ) ? sanitize_hex_color( $_POST[ 'color_colortag' ] ) : '';

		// Update the meta field in the database.
		update_term_meta( $term_id, 'color_colortag', $color_new_colortag );

	}

	public function load_scripts_styles() {

		// Color picker
		wp_enqueue_script( 'wp-color-picker' );
		wp_enqueue_style( 'wp-color-picker' );

	}

	public function add_admin_js() {

		// Print js only once per page
		if ( did_action( 'Color_Term_Meta_js' ) >= 1 ) {
			return;
		}

		?>
		<script type="text/javascript">
			jQuery(document).ready(function($){
				$('.color_color_picker').wpColorPicker();
			});
		</script>
		<?php

		do_action( 'Color_Term_Meta_js', $this );

	}

}

new Color_Term_Meta;