Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** Add New Field To Category **/
- function extra_category_fields( $tag ) {
- $t_id = $tag->term_id;
- $cat_meta = get_option( "category_$t_id");
- ?>
- <tr class="form-field">
- <th scope="row" valign="top"><label for="cat_Image_url"><?php _e('Category Image Url'); ?></label></th>
- <td>
- <input type="text" name="Cat_meta[bgc]" id="colorinput" size="3" style="width:20%;" value="<?php echo $cat_meta['bgc'] ? $cat_meta['bgc'] : '#fff'; ?>" class="my-color-field" />
- <div id="colorpicker"></div><br />
- <span class="description"><?php _e('Can't Think of A Desc Yet, Suggestions?'); ?></span>
- <br />
- </td>
- </tr>
- <?php
- }
- add_action ( 'category_add_form_fields', 'extra_category_fields');
- /** Save Category Meta **/
- function save_extra_category_fileds( $term_id ) {
- if ( isset( $_POST['Cat_meta'] ) ) {
- $t_id = $term_id;
- $cat_meta = get_option( "category_$t_id");
- $cat_keys = array_keys($_POST['Cat_meta']);
- foreach ($cat_keys as $key){
- if (isset($_POST['Cat_meta'][$key])){
- $cat_meta[$key] = $_POST['Cat_meta'][$key];
- }
- }
- //save the option array
- update_option( "category_$t_id", $cat_meta );
- }
- }
- add_action ( 'edited_category', 'save_extra_category_fileds');
- /** Enqueue Color Picker **/
- function farbtastic_scripts() {
- wp_enqueue_script( 'jQuery' );
- wp_enqueue_style( 'farbtastic' );
- wp_enqueue_script( 'farbtastic' );
- ?>
- <script type="text/javascript">
- jQuery(document).ready(function() {
- jQuery('#colorpicker').hide();
- jQuery('#colorpicker').farbtastic("#colorinput");
- jQuery("#colorinput").click(function(){jQuery('#colorpicker').slideToggle()});
- });
- </script>
- <?php
- }
- add_action( 'admin_enqueue_scripts', 'farbtastic_scripts' );
- /** Add Colorpicker Field to "Add New Category" Form **/
- function category_form_custom_field_add( $taxonomy ) {
- ?>
- <div class="form-field">
- <label for="category_custom_color">Color</label>
- <input name="cat_meta[catBG]" class="colorpicker" type="text" value="" />
- <p class="description">Pick a Category Color</p>
- </div>
- <?php
- }
- add_action('category_add_form_fields', 'category_form_custom_field_add', 10 );
- /** Add New Field To Category **/
- function extra_category_fields( $tag ) {
- $t_id = $tag->term_id;
- $cat_meta = get_option( "category_$t_id" );
- ?>
- <tr class="form-field">
- <th scope="row" valign="top"><label for="meta-color"><?php _e('Category Name Background Color'); ?></label></th>
- <td>
- <div id="colorpicker">
- <input type="text" name="cat_meta[catBG]" class="colorpicker" size="3" style="width:20%;" value="<?php echo (isset($cat_meta['catBG'])) ? $cat_meta['catBG'] : '#fff'; ?>" />
- </div>
- <br />
- <span class="description"><?php _e(''); ?></span>
- <br />
- </td>
- </tr>
- <?php
- }
- add_action('category_edit_form_fields','extra_category_fields');
- /** Save Category Meta **/
- function save_extra_category_fileds( $term_id ) {
- if ( isset( $_POST['cat_meta'] ) ) {
- $t_id = $term_id;
- $cat_meta = get_option( "category_$t_id");
- $cat_keys = array_keys($_POST['cat_meta']);
- foreach ($cat_keys as $key){
- if (isset($_POST['cat_meta'][$key])){
- $cat_meta[$key] = $_POST['cat_meta'][$key];
- }
- }
- //save the option array
- update_option( "category_$t_id", $cat_meta );
- }
- }
- add_action ('edited_category', 'save_extra_category_fileds');
- add_action('created_category', 'save_extra_category_fileds', 11, 1);
- /** Enqueue Color Picker **/
- function colorpicker_enqueue() {
- wp_enqueue_style( 'wp-color-picker' );
- wp_enqueue_script( 'colorpicker-js', get_stylesheet_directory_uri() . '/scripts/colorpicker.js', array( 'wp-color-picker' ) );
- }
- add_action('admin_enqueue_scripts', 'colorpicker_enqueue' );
- jQuery(document).ready(function($){
- $('.colorpicker').wpColorPicker();
- });
- <?php
- $cat_id = get_cat_ID('Default');
- $cat_data = get_option("category_$cat_id");
- echo $cat_data['catBG'];
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement