/** * Automatically assign category color when the theme is activated * @return void */ function et_assign_category_color_upon_activation() { if (et_get_option('has_auto_assign_category_color')) { return; } // Get category $categories = get_categories(array('hide_empty' => 0)); // Available colors $colors = et_default_category_colors(); // Loop categories data $color_index = 0; foreach ($categories as $category) { $category_id = $category->term_id; // Check for saved color $category_color = et_get_taxonomy_meta($category_id, 'color', true); // Skip if the category already has color if (!empty($category_color)) { continue; } $color = $colors[$color_index]; // Set category color et_update_taxonomy_meta($category_id, 'color', $color); // Setup $color_index for next loop iteration $color_index++; if ($color_index >= count($colors)) { $color_index = 0; } } et_update_option('has_auto_assign_category_color', true); }
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; }