function get_post_default_color() { global $post; $categories = wp_get_post_categories($post->ID); $color = ''; if (!empty($categories)) { $first_category_id = $categories[0]; $color = et_get_childmost_taxonomy_meta($first_category_id, 'color', true, et_get_option('accent_color', '#00A8FF')); } return $color; }
function get_post_default_color() { global $post; if (isset($post->ID)) { $categories = wp_get_post_categories($post->ID); } $color = ''; if (!empty($categories)) { $first_category_id = $categories[0]; if (function_exists('et_get_childmost_taxonomy_meta')) { $color = et_get_childmost_taxonomy_meta($first_category_id, 'color', true, et_builder_accent_color()); } else { $color = et_builder_accent_color(); } } else { $color = et_builder_accent_color(); } return $color; }
function extra_get_post_category_color($post_id = 0) { $post_id = empty($post_id) ? get_the_ID() : $post_id; $categories = wp_get_post_categories($post_id); $color = ''; if (!empty($categories)) { $first_category_id = $categories[0]; if (function_exists('et_get_childmost_taxonomy_meta')) { $color = et_get_childmost_taxonomy_meta($first_category_id, 'color', true, extra_global_accent_color()); } else { $color = extra_global_accent_color(); } } return $color; }
function extra_add_category_edit_form_color_picker($term, $taxonomy, $wrapper_tag = 'tr') { $term_id = isset($term->term_id) ? $term->term_id : 0; $color = et_get_childmost_taxonomy_meta($term_id, 'color', true, et_get_default_category_color()); $default_attr = ' data-default-color="' . esc_attr($color) . '"'; $value_attr = ' value="' . esc_attr($color) . '"'; ?> <?php printf('<%1$s class="form-field">', tag_escape($wrapper_tag)); ?> <th scope="row"><label for="description"><?php esc_html_e('Color', 'extra'); ?> </label></th> <td><input class="color-picker-hex" name="extra_category_color" type="text" maxlength="7" placeholder="<?php esc_attr_e('Hex Value', 'extra'); ?> "<?php echo $default_attr; echo $value_attr; ?> /><br> <span class="description"><?php esc_html_e('The color used for this category throughout the site.', 'extra'); ?> </span></td> <?php printf('</%1$s>', tag_escape($wrapper_tag)); ?> <?php }
function et_get_childmost_taxonomy_meta($term_id, $meta_key, $single = false, $default = '', $taxonomy = 'category') { global $et_taxonomy_meta; if (!($term = get_term($term_id, $taxonomy))) { return $default; } $result = et_get_taxonomy_meta($term_id, $meta_key, $single); if (empty($result) && isset($term->parent) && $term->parent !== 0) { return et_get_childmost_taxonomy_meta($term->parent, $meta_key, $single, $default, $taxonomy); } if (!empty($result)) { return $result; } return $default; }