dongmai6666 2019-05-07 18:13
浏览 231

WordPress问题 - 致命错误:未捕获错误:调用未定义函数convert_to_screen()/ wp-admin/includes/class-wp-list-table.php:149

When I include class-wp-list-table.php then i can see an error .

i am using composer auto load psr-4 , and also declare a namespeace

Fatal error: Uncaught Error: Call to undefined function convert_to_screen() in /var/www/html/wordpress/building/wp-admin/includes/class-wp-list-table.php:149

   <?php
  /**
   *
   */

  namespace ems\apps\admin;

  if(!class_exists('\WP_List_Table')){
     require_once( ABSPATH.'wp-admin/includes/class-wp-list-table.php' ); 
  }

  class EmsListTable extends \WP_List_Table{


    public function prepare_items(){

      $orderby = isset($_GET['orderby']) ? trim($_GET['orderby']):"" ;
      $order =  isset($_GET['order']) ? trim($_GET['order']):""  ;
      $search_data = isset($_POST['s']) ? $_POST['s']:"";

      $datas = $this->wp_list_table_data_sample($orderby,$order,$search_data);

      $perpage = 2 ;
      $curent_page = $this->get_pagenum();
      $totalitems = count($datas);
      $this->set_pagination_args(array(
        'total_items' => $totalitems,
        'per_page' => $perpage
      ));
      $this->items = array_slice($datas,(($curent_page - 1) * $perpage),$perpage); // $datas;

      $columns = $this->get_columns();
      $hidden = $this->get_hidden_columns();
      $shortable = $this->get_sortable_columns();
      $this->_column_headers =  array($columns,$hidden,$shortable);
    }
    /*
    * all data process
    */
    public function wp_list_table_data_sample($orderby='',$order='',$search_data=''){
      global $wpdb;
      if (!empty($search_data)) {
        $allpost = $wpdb->get_results(
            "SELECT * FROM {$wpdb->posts}
            WHERE post_type='ems_events'
            AND post_status='publish'
            AND ( post_title LIKE '%$search_data%' OR post_content LIKE '%$search_data%' )"
        );
      }else{
        $allpost = get_posts(
          array(
            'post_type'   => 'ems_events',
            'post_status' => 'publish',
            'orderby'     => $orderby,
            'order'       => $order,
          )
        );
      }

      $post_array = array();

      if (count($allpost) > 0) {
        foreach ($allpost as $post) {
          // echo "<br>";
          // print_r($post);
          $post_array[] = array(
            "id"=>$post->ID,
            "title"=>$post->post_title,
            "content"=>$post->post_content,
            "name"=>$post->post_name,
          );
        }
      }

      return $post_array ;
    }
    /*hide some columns*/
    public function get_hidden_columns(){
      // return array('id');
    }

    public function get_sortable_columns(){
      return array(
        "title"=>array("title",false),
        "name"=>array("name",false)
      );
    }

    public function get_bulk_actions(){
      $actions = array(
        "delete"=> "Delete",
        "edit"=> "Edit"
      );
      return   $actions;
    }


    /*register columns*/
    public function get_columns(){
      $columns = array(
        "cb" => "<input type='checkbox' />",
        "id"=>"ID",
        "title"=>"Title",
        "content"=>"content",
        "name"=>"designation"
      );
      return $columns;
    }
    public function column_cb($id){
      return sprintf("<input type='checkbox' name='post[]' value='%s' />" , $id);
    }
    // show columns
    public function column_default($item,$column_name){
      switch ($column_name) {
        case 'id':
        case 'title':
        case 'content':
        case 'name':
          return $item[$column_name];
        default:
          return "No Value";
      }
    }

    public function column_title($item){
      $action = array(
        "edit" => sprintf('<a href="?page=%s&action=%s&post_id=%s">Edit</a>',$_GET['page'],'edit-koro',$item['id']),
        "delete" => sprintf('<a href="?page=%s&action=%s&post_id=%s">Delete</a>',$_GET['page'],'delete-holo',$item['id']),
      );
      return sprintf('%1$s %2$s',$item['title'],$this->row_actions($action));
    }

  }
  • 写回答

1条回答 默认 最新

  • dongyou8087 2019-05-07 19:58
    关注

    i solved the issue by using this code

        public function functuon_hooking()
    {
    
        add_action( 'wp', [$this,'after_load_wordpress'] ); 
    }
    
    function after_load_wordpress(){
        new EventListTable(); 
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!