我当前正在尝试将WP\\U List\\U表添加到自定义类型的编辑页面中的元框中。代码当前为
class Post_Table extends WP_List_Table {
public function __construct()
{
parent::__construct([
\'singular\' => __( \'Post\', \'sp\' ),
\'plural\' => __( \'Posts\', \'sp\' ),
\'ajax\' => false
]);
}
function get_columns(){
$columns = array(
\'cb\' => \'<input type="checkbox" />\',
\'title\' => \'Title\',
);
return $columns;
}
function prepare_items() {
$columns = $this->get_columns();
$hidden = array();
$sortable = array();
$this->_column_headers = array($columns, $hidden, $sortable);
$this->items = array();
}
function add_item($item)
{
array_push($this->items, $item);
}
function column_default( $item, $column_name ) {
switch( $column_name ) {
case \'title\':
return $item[ $column_name ];
default:
return print_r( $item, true ) ;
}
}
function column_title($item) {
$actions = array(
\'delete\' => sprintf(\'<a >Delete</a>\',$_REQUEST[\'page\'],\'delete\',$item[\'ID\']),
);
return sprintf(\'%1$s %2$s\', $item[\'title\'], $this->row_actions($actions) );
}
function get_bulk_actions() {
$actions = array(
\'delete\' => \'Delete\'
);
return $actions;
}
function process_bulk_action() {
if( \'delete\'===$this->current_action() )
{
update_post_meta($post->ID, \'_page_list\', array());
}
}
function column_cb($item) {
return sprintf(
\'<input type="checkbox" name="post[]" value="%s" />\', $item[\'ID\']
);
}
}
$postTable = new Post_Table();
$postTable->prepare_items();
$n = 1;
foreach($page_list as $page)
{
$postTable->add_item(array(
\'ID\' => $n,
\'title\' => get_the_title(get_post($page))
));
$n++;
}
//$postTable->display();
如果我取消注释$postTable->display(),编辑页面的更新按钮将停止正常工作。它不再保存更改,而是将我重定向到wp admin/edit。php,所有帖子的列表。如果我注释掉Post\\u Table类中所有与操作相关的方法,这种行为仍然存在。
是什么导致这种行为以及如何避免这种行为?