[wp-trac] [WordPress Trac] #33521: manage_${post_type}_posts_columns parameters shifted
WordPress Trac
noreply at wordpress.org
Sun Aug 23 21:28:07 UTC 2015
#33521: manage_${post_type}_posts_columns parameters shifted
----------------------------+-----------------------------
Reporter: Cybr | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Taxonomy | Version: 4.3
Severity: normal | Keywords:
Focuses: administration |
----------------------------+-----------------------------
Hello,
manage_${post_type}_posts_columns requires three parameters, however, as
shown in the link below, it only uses 2.
https://core.trac.wordpress.org/browser/tags/4.2.2/src/wp-admin/includes
/class-wp-posts-list-table.php#L978
The paremeters are also shifted.
The example below shows the var dump outputs in render_column_with_bug():
{{{
<?php
class Example_Class {
public function __construct() {
add_action( 'admin_init', array( $this, 'init_columns') );
}
public function init_columns() {
$supported_post_types = array(
'posts' => 'posts',
'pages' => 'pages',
'category' => 'edit-category',
'post_tag' => 'edit-post_tag',
);
foreach ( $supported_post_types as $slug => $type ) {
add_action( "manage_{$type}_columns", array( $this,
'add_column'), 10, 1 );
// Add 3rd parameter because of bug
add_action( "manage_{$slug}_custom_column", array( $this,
'render_column_with_bug'), 10, 3 );
}
}
// Add new column name here
public function add_column( $columns ) {
$columns = array_merge( array(
'my_column_name' => 'column_slug',
), $columns );
return $columns;
}
// Output column contents here here
public function render_column_with_bug( $column, $post_id, $tax_id =
'' ) {
$status = '';
var_dump ( $column );
/*
Outputs: column name on posts/pages
Outputs: empty string on taxonomies
*/
var_dump ( $post_id );
/*
Outputs: post id posts/pages
Outputs: column name taxonomies
*/
var_dump ( $tax_id );
/*
Outputs: empty string on posts/pages
Outputs: taxonomy id on taxonomies
*/
if ( $column == 'my_column_name' )
$status = $this->post_status();
echo $status;
}
// Output column contents here here
public function render_column_bug_fixed( $column, $post_id, $tax_id =
'' ) {
$status = '';
$type = get_post_type( $post_id );
if ( !empty ( $tax_id ) && ! $type ) {
$column = $post_id;
$screen = get_current_screen();
$type = $screen->id;
}
if ( $column == 'my_column_name' )
$status = $this->post_status();
echo $status;
}
public function post_status() {
// render output
}
}
new Example_Class();
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/33521>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list