sanitize_hex( $color );
return $hash && $color ? "#{$color}" : $color;
}
/**
* Geting category text color.
*
* @param type $term_id taxonomy term.
* @param type $hash before hex color.
* @return type
*/
public function get_term_text_color( $term_id, $hash = false ) {
$color = get_term_meta( $term_id, 'text_color', true );
$color = $this->sanitize_hex( $color );
return $hash && $color ? "#{$color}" : $color;
}
/**
* Geting category image.
*
* @param type $term_id taxonomy term.
* @return type
*/
public function get_term_image( $term_id ) {
$imageid = get_term_meta( $term_id, 'image', true );
return $imageid;
}
/**
* New term screen background color field.
*/
public function new_term_bg_color_field() {
wp_nonce_field( basename( __FILE__ ), 'mfc_term_bg_color_nonce' ); ?>
get_term_bg_color( $term->term_id, true );
if ( ! $color ) {
$color = $default; }
?>
|
|
get_term_text_color( $term->term_id, true );
if ( ! $color ) {
$color = $default; }
?>
|
|
get_term_image( $term->term_id, true );
$image = wp_get_attachment_image_src( $imageid );
if ( ! $image ) {
$image = $default; }
if ( ! $imageid ) {
$imageid = $default; }
?>
|
|
get_term_bg_color( $term_id );
$new_color = isset( $_POST['mfc_term_bg_color'] ) ? $this->sanitize_hex( $_POST['mfc_term_bg_color'] ) : '';
if ( $old_color && '' === $new_color ) {
delete_term_meta( $term_id, 'bg_color' ); } else if ( $old_color !== $new_color ) {
update_term_meta( $term_id, 'bg_color', $new_color ); }
}
/**
* Saving meta data - text color.
*
* @param type $term_id taxonomy term ID.
* @return type
*/
public function save_term_text_color( $term_id ) {
if ( ! isset( $_POST['mfc_term_text_color_nonce'] ) || ! wp_verify_nonce( $_POST['mfc_term_text_color_nonce'], basename( __FILE__ ) ) ) {
return; }
$old_color = $this->get_term_text_color( $term_id );
$new_color = isset( $_POST['mfc_term_text_color'] ) ? $this->sanitize_hex( $_POST['mfc_term_text_color'] ) : '';
if ( $old_color && '' === $new_color ) {
delete_term_meta( $term_id, 'text_color' ); } else if ( $old_color !== $new_color ) {
update_term_meta( $term_id, 'text_color', $new_color ); }
}
/**
* Saving meta data - image.
*
* @param type $term_id taxonomy term ID.
* @return type
*/
public function save_term_image( $term_id ) {
if ( ! isset( $_POST['mfc_term_image_nonce'] ) || ! wp_verify_nonce( $_POST['mfc_term_image_nonce'], basename( __FILE__ ) ) ) {
return; }
$old_image = $this->get_term_image( $term_id );
$new_image = isset( $_POST['mfc_term_image'] ) ? absint( $_POST['mfc_term_image'] ) : '';
if ( $old_image && '' === $new_image ) {
delete_term_meta( $term_id, 'image' ); } else if ( $old_image !== $new_image ) {
update_term_meta( $term_id, 'image', $new_image ); }
}
/**
* Enqueue admin scripts
*
* @param type $hook_suffix hook suffix.
* @return type
*/
public function admin_enqueue_scripts( $hook_suffix ) {
if ( ( 'edit-tags.php' !== $hook_suffix || 'category' !== get_current_screen()->taxonomy ) && ( 'term.php' !== $hook_suffix || 'category' !== get_current_screen()->taxonomy ) ) {
return; }
wp_enqueue_media();
wp_enqueue_script(
'category-image-js',
get_template_directory_uri() . '/inc/js/categoryimage.js',
array( 'jquery', 'wp-color-picker' ),
'1.0.0',
true
);
$data = array(
// 'wp_version' => WP_VERSION,
'label' => array(
'title' => esc_html__( 'Choose Category Image', 'blover' ),
'button' => esc_html__( 'Choose Image', 'blover' ),
),
);
wp_localize_script(
'category-image-js',
'CategoryImage',
$data
);
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script( 'wp-color-picker' );
}
}
new Blover_Meta_For_Categories();
}// End if().