Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Register Custom Taxonomy
- if ( ! function_exists( 'tqe_custom_taxonomy_edition' ) ) {
- function tqe_custom_taxonomy_edition() {
- $labels = array(
- 'name' => _x( 'Editions', 'Taxonomy General Name', 'tqe' ),
- 'singular_name' => _x( 'Edition', 'Taxonomy Singular Name', 'tqe' ),
- 'menu_name' => __( 'Edition', 'tqe' ),
- 'all_items' => __( 'All Editions', 'tqe' ),
- 'parent_item' => __( 'Parent Edition', 'tqe' ),
- 'parent_item_colon' => __( 'Parent Edition:', 'tqe' ),
- 'new_item_name' => __( 'New Edition Name', 'tqe' ),
- 'add_new_item' => __( 'Add New Edition', 'tqe' ),
- 'edit_item' => __( 'Edit Edition', 'tqe' ),
- 'update_item' => __( 'Update Edition', 'tqe' ),
- 'view_item' => __( 'View Edition', 'tqe' ),
- 'separate_items_with_commas' => __( 'Separate editions with commas', 'tqe' ),
- 'add_or_remove_items' => __( 'Add or remove items', 'tqe' ),
- 'choose_from_most_used' => __( 'Choose from the most used', 'tqe' ),
- 'popular_items' => __( 'Popular Editions', 'tqe' ),
- 'search_items' => __( 'Search Editions', 'tqe' ),
- 'not_found' => __( 'Not Found', 'tqe' ),
- 'no_terms' => __( 'No editions', 'tqe' ),
- 'items_list' => __( 'Editions list', 'tqe' ),
- 'items_list_navigation' => __( 'Editions list navigation', 'tqe' ),
- );
- $args = array(
- 'labels' => $labels,
- 'hierarchical' => true,
- 'public' => true,
- 'show_ui' => true,
- 'show_admin_column' => true,
- 'show_in_nav_menus' => true,
- 'show_tagcloud' => true,
- );
- register_taxonomy( 'edition', array( 'post' ), $args );
- }
- add_action( 'init', 'tqe_custom_taxonomy_edition', 0 );
- }
- /**
- * Register columns for our taxonomy
- */
- function tqe_register_category_columns( $columns ) {
- $columns['first-appeared'] = __( 'First Appeared', 'tqe' );
- return $columns;
- }
- add_filter( 'manage_edit-edition_columns', 'tqe_register_category_columns' );
- /**
- * Retrieve value for our custom column
- *
- * @param string $string Blank string.
- * @param string $column_name Name of the column.
- * @param int $term_id Term ID.
- */
- function tqe_category_column_display( $string = '', $column_name, $term_id ) {
- return esc_html( get_term_meta( $term_id, $column_name, true ) ); // XSS ok.
- }
- add_filter( 'manage_edition_custom_column', 'tqe_category_column_display', 10, 3 );
- // Prepare field markup for Quick Edit box & store user-input data
- /**
- * Display markup or template for custom field
- */
- function tqe_quick_edit_category_field( $column_name, $screen ) {
- // If we're not iterating over our custom column, then skip
- if ( $screen != 'edition' && $column_name != 'first-appeared' ) {
- return false;
- }
- ?>
- <fieldset>
- <div id="gwp-first-appeared" class="inline-edit-col">
- <label>
- <span class="title"><?php _e( 'First Appeared', 'tqe' ); ?></span>
- <span class="input-text-wrap"><input type="text" name="<?php echo esc_attr( $column_name ); ?>" class="ptitle" value=""></span>
- </label>
- </div>
- </fieldset>
- <?php
- }
- add_action( 'quick_edit_custom_box', 'tqe_quick_edit_category_field', 10, 2 );
- /**
- * Callback runs when category is updated
- * Will save user-provided input into the wp_termmeta DB table
- */
- function tqe_quick_edit_save_category_field( $term_id ) {
- if ( isset( $_POST['first-appeared'] ) ) {
- // security tip: kses
- update_term_meta( $term_id, 'first-appeared', $_POST['first-appeared'] );
- }
- }
- add_action( 'edited_edition', 'tqe_quick_edit_save_category_field' );
- // Display new Taxonomy custom column
- /**
- * Front-end stuff for pulling in user-input values dynamically
- * into our input field.
- */
- function tqe_quickedit_category_javascript() {
- $current_screen = get_current_screen();
- if ( $current_screen->id != 'edit-edition' || $current_screen->taxonomy != 'edition' ) {
- return;
- }
- // Ensure jQuery library is loaded
- wp_enqueue_script( 'jquery' );
- ?>
- <script type="text/javascript">
- /*global jQuery*/
- jQuery(function($) {
- $('#the-list').on( 'click', 'a.editinline', function( e ) {
- e.preventDefault();
- var $tr = $(this).closest('tr');
- var val = $tr.find('td.first-appeared').text();
- // Update field
- $('tr.inline-edit-row :input[name="first-appeared"]').val(val ? val : '');
- });
- });
- </script>
- <?php
- }
- add_action( 'admin_print_footer_scripts-edit-tags.php', 'tqe_quickedit_category_javascript' );
Add Comment
Please, Sign In to add comment