Advertisement
Guest User

Untitled

a guest
Jul 14th, 2014
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.06 KB | None | 0 0
  1. /** Add New Field To Category **/
  2. function extra_category_fields( $tag ) {
  3. $t_id = $tag->term_id;
  4. $cat_meta = get_option( "category_$t_id");
  5. ?>
  6. <tr class="form-field">
  7. <th scope="row" valign="top"><label for="cat_Image_url"><?php _e('Category Image Url'); ?></label></th>
  8. <td>
  9. <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" />
  10. <div id="colorpicker"></div><br />
  11. <span class="description"><?php _e('Can't Think of A Desc Yet, Suggestions?'); ?></span>
  12. <br />
  13. </td>
  14. </tr>
  15. <?php
  16. }
  17. add_action ( 'category_add_form_fields', 'extra_category_fields');
  18.  
  19. /** Save Category Meta **/
  20. function save_extra_category_fileds( $term_id ) {
  21. if ( isset( $_POST['Cat_meta'] ) ) {
  22. $t_id = $term_id;
  23. $cat_meta = get_option( "category_$t_id");
  24. $cat_keys = array_keys($_POST['Cat_meta']);
  25. foreach ($cat_keys as $key){
  26. if (isset($_POST['Cat_meta'][$key])){
  27. $cat_meta[$key] = $_POST['Cat_meta'][$key];
  28. }
  29. }
  30. //save the option array
  31. update_option( "category_$t_id", $cat_meta );
  32. }
  33. }
  34. add_action ( 'edited_category', 'save_extra_category_fileds');
  35.  
  36. /** Enqueue Color Picker **/
  37. function farbtastic_scripts() {
  38. wp_enqueue_script( 'jQuery' );
  39. wp_enqueue_style( 'farbtastic' );
  40. wp_enqueue_script( 'farbtastic' );
  41.  
  42. ?>
  43. <script type="text/javascript">
  44.  
  45. jQuery(document).ready(function() {
  46. jQuery('#colorpicker').hide();
  47. jQuery('#colorpicker').farbtastic("#colorinput");
  48. jQuery("#colorinput").click(function(){jQuery('#colorpicker').slideToggle()});
  49. });
  50.  
  51. </script>
  52. <?php
  53. }
  54. add_action( 'admin_enqueue_scripts', 'farbtastic_scripts' );
  55.  
  56. /** Add Colorpicker Field to "Add New Category" Form **/
  57. function category_form_custom_field_add( $taxonomy ) {
  58. ?>
  59. <div class="form-field">
  60. <label for="category_custom_color">Color</label>
  61. <input name="cat_meta[catBG]" class="colorpicker" type="text" value="" />
  62. <p class="description">Pick a Category Color</p>
  63. </div>
  64. <?php
  65. }
  66. add_action('category_add_form_fields', 'category_form_custom_field_add', 10 );
  67.  
  68. /** Add New Field To Category **/
  69. function extra_category_fields( $tag ) {
  70. $t_id = $tag->term_id;
  71. $cat_meta = get_option( "category_$t_id" );
  72. ?>
  73. <tr class="form-field">
  74. <th scope="row" valign="top"><label for="meta-color"><?php _e('Category Name Background Color'); ?></label></th>
  75. <td>
  76. <div id="colorpicker">
  77. <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'; ?>" />
  78. </div>
  79. <br />
  80. <span class="description"><?php _e(''); ?></span>
  81. <br />
  82. </td>
  83. </tr>
  84. <?php
  85. }
  86. add_action('category_edit_form_fields','extra_category_fields');
  87.  
  88. /** Save Category Meta **/
  89. function save_extra_category_fileds( $term_id ) {
  90.  
  91. if ( isset( $_POST['cat_meta'] ) ) {
  92. $t_id = $term_id;
  93. $cat_meta = get_option( "category_$t_id");
  94. $cat_keys = array_keys($_POST['cat_meta']);
  95. foreach ($cat_keys as $key){
  96. if (isset($_POST['cat_meta'][$key])){
  97. $cat_meta[$key] = $_POST['cat_meta'][$key];
  98. }
  99. }
  100. //save the option array
  101. update_option( "category_$t_id", $cat_meta );
  102. }
  103. }
  104. add_action ('edited_category', 'save_extra_category_fileds');
  105. add_action('created_category', 'save_extra_category_fileds', 11, 1);
  106.  
  107.  
  108. /** Enqueue Color Picker **/
  109. function colorpicker_enqueue() {
  110. wp_enqueue_style( 'wp-color-picker' );
  111. wp_enqueue_script( 'colorpicker-js', get_stylesheet_directory_uri() . '/scripts/colorpicker.js', array( 'wp-color-picker' ) );
  112. }
  113. add_action('admin_enqueue_scripts', 'colorpicker_enqueue' );
  114.  
  115. jQuery(document).ready(function($){
  116. $('.colorpicker').wpColorPicker();
  117. });
  118.  
  119. <?php
  120. $cat_id = get_cat_ID('Default');
  121. $cat_data = get_option("category_$cat_id");
  122. echo $cat_data['catBG'];
  123. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement