2016-11-29 13 views
3

私はWP_List_Tableクラスを拡張する必要があるプラグインを開発しています。その後、未定義関数を呼び出すconvert_to_screen()

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

その後、クラスを拡張するためのコードが来ると:私は私のプラグイン・ファイル内のクラスを拡張(これは、これを行うための正しい方法であれば、私は知らないのか?)、このようWP_List_Tableが含まれていますIこのような私のテーブルクラスのインスタンスを作成し実行します。

<?php 

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


Class Wp_Ban_User extends WP_List_Table 
{ 

    public function __construct() 
    { 
      add_action('admin_menu',array($this,'WBU_adminMenu')); 
      parent::__construct(array(
        'singular'=> 'wp_list_text_link', //Singular label 
        'plural' => 'wp_list_test_links', //plural label, also this well be one of the table css class 
        'ajax' => false //We won't support Ajax for this table 
       ));  
      $this->prepare_items(); 
      $this->display();   

    } 
    function get_columns() { 
     $columns = array(
      'id' => 'ID', 
      'user_login'  => 'User Name', 
      'user_email' => 'User Email'    
     ); 
     return $columns; 
    } 


    function column_default($item, $column_name) { 
     switch($column_name) { 
      case 'id': 
      case 'user_login': 
      case 'user_email': 

       return $item[ $column_name ]; 
      default: 
       return print_r($item, true) ; 
     } 
    } 
    function prepare_items() { 

     $example_data = array(
       array(
         'id'  => 1, 
         'user_login'  => 'vasim', 
         'user_email' => '[email protected]'       
       ), 
       array(
         'id'  => 2, 
         'user_login'  => 'Asma', 
         'user_email' => '[email protected]'       
       ), 
       array(
         'id'  => 3, 
         'user_login'  => 'Nehal', 
         'user_email' => '[email protected]'       
       ), 
      ); 

     $columns = $this->get_columns(); 
     $hidden = array(); 
     $sortable = $this->get_sortable_columns(); 
     $this->_column_headers = array($columns, $hidden, $sortable); 
     $this->items = $example_data; 
    } 

    public function WBU_adminMenu() 
    { 
      add_menu_page('Currently Logged In User', 'Banned User', 'manage_options', 'ban_admin_init', array($this,'ban_admin_init')); 
    } 
function ban_admin_init(){ 
     global $wpdb; 

     $sql="SELECT * from {$wpdb->prefix}users"; 
     $sql_result=$wpdb->get_results($sql,'ARRAY_A'); 
     print_r($sql_result); 
     //$this->items=$sql_result;  
    } 

} 

global $Obj_Wp_Ban_User; 

$Obj_Wp_Ban_User=new Wp_Ban_User(); 

をしかし、私はこれを行うとき、私はこのエラーを取得する実行します。

Fatal error: Call to undefined function convert_to_screen() in D:\xampp\htdocs\developplugin\wp-admin\includes\class-wp-list-table.php on line 143

私はいくつかの研究をしましたが、それを修正する方法を理解していませんでした。

これを修正する方法を知っている人はいますか?

ありがとうございました!

よろしくお願いいたします。

+0

コンストラクタから 'add_action( 'admin_menu'、array($ this、 'WBU_adminMenu'));'を削除してみてください –

+0

Wordpressが必要なライブラリをロードする前にクラスがインスタンス化されています。 – Devon

+0

@ShravanShrama同じエラーを削除しました –

答えて

1

私の悪い英語のために申し訳ありません、私はフランス語です。

私はこの問題を発見しました。修正あなたのクラス(コードの下にある参照してください)。

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


Class Wp_Ban_User extends WP_List_Table 
{ 

    public function __construct() 
    { 
      parent::__construct(array(
        'singular'=> 'wp_list_text_link', //Singular label 
        'plural' => 'wp_list_test_links', //plural label, also this well be one of the table css class 
        'ajax' => false //We won't support Ajax for this table 
       ));  
      $this->prepare_items(); 
      $this->display();   

    } 

    function get_columns() { 
     $columns = array(
      'id' => 'ID', 
      'user_login'  => 'User Name', 
      'user_email' => 'User Email'    
     ); 
     return $columns; 
    } 

    function column_default($item, $column_name) { 
     switch($column_name) { 
      case 'id': 
      case 'user_login': 
      case 'user_email': 

       return $item[ $column_name ]; 
      default: 
       return print_r($item, true) ; 
     } 
    } 

    function prepare_items() { 

     $example_data = array(
       array(
         'id'  => 1, 
         'user_login'  => 'vasim', 
         'user_email' => '[email protected]'       
       ), 
       array(
         'id'  => 2, 
         'user_login'  => 'Asma', 
         'user_email' => '[email protected]'       
       ), 
       array(
         'id'  => 3, 
         'user_login'  => 'Nehal', 
         'user_email' => '[email protected]'       
       ), 
      ); 

     $columns = $this->get_columns(); 
     $hidden = array(); 
     $sortable = $this->get_sortable_columns(); 
     $this->_column_headers = array($columns, $hidden, $sortable); 
     $this->items = $example_data; 
    } 

} 


// Render your admin menu outside the class 
public function WBU_adminMenu() 
{ 
    add_menu_page('Currently Logged In User', 'Banned User', 'manage_options', 'render_admin_page', 'render_admin_page'); 
} 

// Create your menu outside the class 
add_action('admin_menu','WBU_adminMenu'); 

// Render your page outside the class 
function render_admin_page(){ 
    global $wpdb; 

    $Obj_Wp_Ban_User=new Wp_Ban_User(); 
    $Obj_Wp_Ban_User->prepare_items(); 

    $sql="SELECT * from {$wpdb->prefix}users"; 
    $sql_result=$wpdb->get_results($sql,'ARRAY_A'); 
    print_r($sql_result);  
} 

このシンプル:

  • がadmin_menuアクションを追加

    • はクラスの外のメニューを追加します。エラーを解決するためにCall to undefined function convert_to_screen()あなたがする必要がありますクラス外
    • は3の後、クラス

    外で管理ページをレンダリング日、それは私のための仕事です!

  • +0

    それも私のために働く。訂正ありがとう。 –

    0

    私はそれがI want a pagination to my options page of wordpress plugin?

    は、あなたが任意の混乱を持っている場合は、私に教えてください、このリンクをチェックしてください、あなたの問題を解決したと思います。このリンクを使用して、私の新鮮なワードプレスを使用してコードをチェックしています。

    +0

    それは直接働いていますか? In 4.6.1 –

    関連する問題