Guest User

Untitled

a guest
Mar 24th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.54 KB | None | 0 0
  1. <?php
  2. // Register Custom Taxonomy
  3. if ( ! function_exists( 'tqe_custom_taxonomy_edition' ) ) {
  4. function tqe_custom_taxonomy_edition() {
  5.  
  6. $labels = array(
  7. 'name' => _x( 'Editions', 'Taxonomy General Name', 'tqe' ),
  8. 'singular_name' => _x( 'Edition', 'Taxonomy Singular Name', 'tqe' ),
  9. 'menu_name' => __( 'Edition', 'tqe' ),
  10. 'all_items' => __( 'All Editions', 'tqe' ),
  11. 'parent_item' => __( 'Parent Edition', 'tqe' ),
  12. 'parent_item_colon' => __( 'Parent Edition:', 'tqe' ),
  13. 'new_item_name' => __( 'New Edition Name', 'tqe' ),
  14. 'add_new_item' => __( 'Add New Edition', 'tqe' ),
  15. 'edit_item' => __( 'Edit Edition', 'tqe' ),
  16. 'update_item' => __( 'Update Edition', 'tqe' ),
  17. 'view_item' => __( 'View Edition', 'tqe' ),
  18. 'separate_items_with_commas' => __( 'Separate editions with commas', 'tqe' ),
  19. 'add_or_remove_items' => __( 'Add or remove items', 'tqe' ),
  20. 'choose_from_most_used' => __( 'Choose from the most used', 'tqe' ),
  21. 'popular_items' => __( 'Popular Editions', 'tqe' ),
  22. 'search_items' => __( 'Search Editions', 'tqe' ),
  23. 'not_found' => __( 'Not Found', 'tqe' ),
  24. 'no_terms' => __( 'No editions', 'tqe' ),
  25. 'items_list' => __( 'Editions list', 'tqe' ),
  26. 'items_list_navigation' => __( 'Editions list navigation', 'tqe' ),
  27. );
  28. $args = array(
  29. 'labels' => $labels,
  30. 'hierarchical' => true,
  31. 'public' => true,
  32. 'show_ui' => true,
  33. 'show_admin_column' => true,
  34. 'show_in_nav_menus' => true,
  35. 'show_tagcloud' => true,
  36. );
  37. register_taxonomy( 'edition', array( 'post' ), $args );
  38.  
  39. }
  40. add_action( 'init', 'tqe_custom_taxonomy_edition', 0 );
  41.  
  42. }
  43.  
  44. /**
  45. * Register columns for our taxonomy
  46. */
  47. function tqe_register_category_columns( $columns ) {
  48.  
  49. $columns['first-appeared'] = __( 'First Appeared', 'tqe' );
  50.  
  51. return $columns;
  52. }
  53. add_filter( 'manage_edit-edition_columns', 'tqe_register_category_columns' );
  54.  
  55. /**
  56. * Retrieve value for our custom column
  57. *
  58. * @param string $string Blank string.
  59. * @param string $column_name Name of the column.
  60. * @param int $term_id Term ID.
  61. */
  62. function tqe_category_column_display( $string = '', $column_name, $term_id ) {
  63.  
  64. return esc_html( get_term_meta( $term_id, $column_name, true ) ); // XSS ok.
  65.  
  66. }
  67. add_filter( 'manage_edition_custom_column', 'tqe_category_column_display', 10, 3 );
  68.  
  69. // Prepare field markup for Quick Edit box & store user-input data
  70. /**
  71. * Display markup or template for custom field
  72. */
  73. function tqe_quick_edit_category_field( $column_name, $screen ) {
  74. // If we're not iterating over our custom column, then skip
  75. if ( $screen != 'edition' && $column_name != 'first-appeared' ) {
  76. return false;
  77. }
  78. ?>
  79. <fieldset>
  80. <div id="gwp-first-appeared" class="inline-edit-col">
  81. <label>
  82. <span class="title"><?php _e( 'First Appeared', 'tqe' ); ?></span>
  83. <span class="input-text-wrap"><input type="text" name="<?php echo esc_attr( $column_name ); ?>" class="ptitle" value=""></span>
  84. </label>
  85. </div>
  86. </fieldset>
  87. <?php
  88. }
  89. add_action( 'quick_edit_custom_box', 'tqe_quick_edit_category_field', 10, 2 );
  90.  
  91. /**
  92. * Callback runs when category is updated
  93. * Will save user-provided input into the wp_termmeta DB table
  94. */
  95. function tqe_quick_edit_save_category_field( $term_id ) {
  96. if ( isset( $_POST['first-appeared'] ) ) {
  97. // security tip: kses
  98. update_term_meta( $term_id, 'first-appeared', $_POST['first-appeared'] );
  99. }
  100. }
  101. add_action( 'edited_edition', 'tqe_quick_edit_save_category_field' );
  102.  
  103. // Display new Taxonomy custom column
  104. /**
  105. * Front-end stuff for pulling in user-input values dynamically
  106. * into our input field.
  107. */
  108. function tqe_quickedit_category_javascript() {
  109. $current_screen = get_current_screen();
  110.  
  111. if ( $current_screen->id != 'edit-edition' || $current_screen->taxonomy != 'edition' ) {
  112. return;
  113. }
  114.  
  115. // Ensure jQuery library is loaded
  116. wp_enqueue_script( 'jquery' );
  117. ?>
  118. <script type="text/javascript">
  119. /*global jQuery*/
  120. jQuery(function($) {
  121. $('#the-list').on( 'click', 'a.editinline', function( e ) {
  122. e.preventDefault();
  123. var $tr = $(this).closest('tr');
  124. var val = $tr.find('td.first-appeared').text();
  125. // Update field
  126. $('tr.inline-edit-row :input[name="first-appeared"]').val(val ? val : '');
  127. });
  128. });
  129. </script>
  130. <?php
  131. }
  132. add_action( 'admin_print_footer_scripts-edit-tags.php', 'tqe_quickedit_category_javascript' );
Add Comment
Please, Sign In to add comment