2016-11-29 1 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'); 
} 

그런 다음 다음 클래스를 확장하고 대한 코드를 제공 : 내 플러그인 파일 내에서 클래스를 확장 한 (? I는이 작업을 수행하는 올바른 방법 인 경우 모르는)와 같은 WP_List_Table 포함 이 같은 내 테이블 클래스의 인스턴스 생성을 수행

<?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'))'from 생성자 –

+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

    직접 작동합니까 ?? 4.6.1에서 –

    관련 문제