Duplicar columnas personalizadas en otro complemento

We have two plugins in a WordPress website

1) Plugin A has the code below

add_filter( 'manage_edit-book_columns', 'set_custom_edit_book_columns' );
add_action( 'manage_book_posts_custom_column' , 'custom_book_column', 10, 2 );

function set_custom_edit_book_columns($columns) {
     unset( $columns['author'] );
     $columns['book_author'] = __( 'Author', 'your_text_domain' );
     $columns['publisher'] = __( 'Publisher', 'your_text_domain' );

     return $columns;
}

function custom_book_column( $column, $post_id ) {
    switch ( $column ) {

     case 'book_author' :
        $terms = get_the_term_list( $post_id , 'book_author' , '' , ',' , '' );
        if ( is_string( $terms ) )
            echo $terms;
        else
            _e( 'Unable to get author(s)', 'your_text_domain' );
        break;

    case 'publisher' :
        echo get_post_meta( $post_id , 'publisher' , true ); 
        break;

    }
}

2) Now, I want to add one more column in this grid by adding code in plugin B , I don't want to edit plugin A to make fixes

3) Is it possible that we copy the code in plugin B? When I did so then there has double data in all columns. From plugin A and plugin B.

preguntado el 28 de mayo de 14 a las 12:05

1 Respuestas

You simply have to add different data, at least different column IDs.

<?php
/**
 * Plugin Name: Plugin B
 */
add_filter( 'manage_edit-book_columns', 'set_custom_edit_book_columns' );
add_action( 'manage_book_posts_custom_column' , 'custom_book_column', 10, 2 );

function set_custom_edit_book_columns($columns) {
    $columns['new_column'] = __( 'Brand new column' ); // <-- Column ID
    return $columns;
}

function custom_book_column( $column, $post_id ) {
    switch ( $column ) {
        case 'new_column' : // <-- Column ID
            echo "Anything you want";
        break;
    }
}

Respondido el 22 de junio de 14 a las 19:06

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.