【发布时间】:2014-04-17 18:54:59
【问题描述】:
我在实现 WP List Table 时收到以下错误消息
致命错误:调用未定义的函数 convert_to_screen() .../wp-admin/includes/class-wp-list-table.php 在第 88 行
我已经通过添加以下行解决了这个问题
require_once(ABSPATH . 'wp-admin/includes/template.php' );
在这个 WP 列表在我的插件中运行良好之后。但是我在激活我的插件时收到了通知。
注意:convert_to_screen()、add_meta_box() 调用不正确。 可能直接包含 wp-admin/includes/template.php 以便 使用 add_meta_box()。这是非常错误的。挂钩 add_meta_box() 调用 改为 add_meta_boxes 操作。请参阅调试 WordPress 了解更多信息。 (此消息是在版本中添加的 3.3.) 在 /var/www/wordpress_RND/wordpress3.8.1/wp-includes/functions.php 上 第 3049 行
有没有人知道这个通知。我正在使用 Wordpress 版本 3.8.1
以下是要求的最小代码。
define('FRM_PLUGIN_DIR_PATH_INC', trailingslashit( plugin_dir_path( __FILE__ ) ) .'../inc');
if( ! class_exists( 'WP_List_Table' ) ) {
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
}
// Commenting below line result in error.
require_once(ABSPATH . 'wp-admin/includes/template.php' );
class Any_Forms_Funtions extends WP_List_Table{
public function listForm(){
echo "<div class='wrap'><form>";
$this->prepare_items();
$this->display();
echo "</form></div>";
}
function get_columns(){
$columns = array(
//'cb' => '<input type="checkbox" />',
'booktitle' => 'Title',
'author' => 'Author',
'isbn' => 'ISBN',
);
return $columns;
}
function column_default( $item, $column_name ) {
switch( $column_name ) {
case 'booktitle':
case 'author':
case 'isbn':
return $item[ $column_name ];
default:
return print_r( $item, true ) ; //Show the whole array for troubleshooting purposes
}
}
function prepare_items() {
$example_data = array(
array('ID' => 1,'booktitle' => 'Quarter Share', 'author' => 'Rakesh','isbn' => '978-0982514542')
,array('ID' => 2,'booktitle' => 'Quarter Share', 'author' => 'Rakesh','isbn' => '978-0982514542')
);
$columns = $this->get_columns();
$hidden = array();
$sortable = $this->get_sortable_columns();
$this->_column_headers = array($columns, $hidden, $sortable);
$this->items = $example_data;
}
}
如果还有其他需要,请告诉我。
【问题讨论】:
-
我正在研究 WP List Table 并找到了这篇文章...你有没有尝试过我的解决方案?