我创建了一个显示用户列表的自定义页面(角色=\'订阅者\')。我将此页面命名为“Reporting”(报告)(&;它基于wp\\U list\\U表格。现在我想显示用户详细信息(具有自定义布局和用户元)。我不知道如何创建用户详细信息页的链接或创建详细信息页。
下面是显示用户列表数据的代码。类别cisco connex core wp报告表。php
class WP_Reporting_Table
{
/**
* Constructor
*/
public function __construct()
{
// Hook - Registering Scripts
add_action( \'admin_menu\', array ( $this, \'reporting_users\' ) );
add_action( \'admin_head\', array( $this, \'admin_header\' ) );
}
/**
* reporting_users function.
*
* @access public
*/
public function reporting_users( $hook_suffix )
{
if ( isset ( $_GET[\'user_id\'] ) && !empty ( $_GET[\'user_id\'] ) ) {
add_action(\'edit_user_profile\', \'cc_reporting_detail\');
} else {
add_menu_page( \'Reporting\', \'Reporting\', \'manage_options\', \'wp-reporting-table-users\', array ( $this, \'cc_reporting\' ) );
}
}
public function cc_reporting()
{
$usersTable = new WP_Reporting_Table_Users();
$usersTable->prepare_items();
?>
Reporting Page
display(); ?>
\';
echo \'.wp-list-table .column-title { width: 30%; }\';
echo \'.wp-list-table .column-email { width: 30%; }\';
echo \'.wp-list-table .column-engagement_score { width: 20%; }\';
echo \'.wp-list-table .column-date { width: 20%; }\';
echo \'.wp-list-table .column-title img { float: left; margin-right: 10px; margin-top: 1px; }\';
echo \'\';
}
public function cc_reporting_detail()
{
echo $_GET[\'user_id\'];
}
}
new WP_Reporting_Table();
// WP_List_Table is not loaded automatically so we need to load it in our application
if( ! class_exists( \'WP_List_Table\' ) ) {
require_once( ABSPATH . \'wp-admin/includes/class-wp-list-table.php\' );
}
类别cisco connex核心用户。php
class WP_Reporting_Table_Users extends WP_List_Table
{
/**
* Prepare the items for the table to process
*
* @return Void
*/
public function prepare_items()
{
$columns = $this->get_columns();
$hidden = $this->get_hidden_columns();
$sortable = $this->get_sortable_columns();
$data_user = $this->table_data();
usort( $data_user, array( &$this, \'sort_data\' ) );
$perPage = 20;
$currentPage = $this->get_pagenum();
$totalItems = count($data_user);
$this->set_pagination_args( array(
\'total_items\' => $totalItems,
\'per_page\' => $perPage
) );
$data_user = array_slice($data_user,(($currentPage-1)*$perPage),$perPage);
$this->_column_headers = array($columns, $hidden, $sortable);
$this->items = $data_user;
}
/**
* Override the parent columns method. Defines the columns to use in your listing table
*
* @return Array
*/
public function get_columns()
{
$columns = array(
\'title\' => __(\'Name\', \'\'),
\'email\' => __(\'Email\', \'\'),
\'engagement_score\' => __(\'Engagement Score (Weekly Change)\', \'\'),
\'date\' => __(\'Date\', \'\')
);
return $columns;
}
/**
* Define which columns are hidden
*
* @return Array
*/
public function get_hidden_columns()
{
return array();
}
/**
* Define the sortable columns
*
* @return Array
*/
public function get_sortable_columns()
{
return array(\'email\' => array(\'email\', false));
}
/**
* Get the table data
*
* @return Array
*/
private function table_data()
{
$data = array();
$args = array(
\'role\' => \'Subscriber\'
);
$user_query = new WP_User_Query( $args );
if ( ! empty( $user_query->results ) ) {
foreach ( $user_query->results as $user ) {
$user_picture = get_user_meta($user->ID, \'rdp_ll_picture_url\', TRUE);
$user_detail_link = \'Detail\';
$data[] = array(
\'title\' => \'display_name .\'" style="width: 32px;">\' . $user->display_name . $user_detail_link,
\'email\' => $user->user_email,
\'engagement_score\' => \'10\',
\'date\' => date(\'m/d/Y\',strtotime( $user->user_registered ))
);
}
}
return $data;
}
/**
* Define what data to show on each column of the table
*
* @param Array $item Data
* @param String $column_name - Current column name
*
* @return Mixed
*/
public function column_default( $item, $column_name )
{
switch( $column_name ) {
case \'title\':
case \'email\':
case \'engagement_score\':
case \'date\':
return $item[ $column_name ];
default:
return print_r( $item, true ) ;
}
}
/**
* Allows you to sort the data by the variables set in the $_GET
*
* @return Mixed
*/
private function sort_data( $a, $b )
{
// Set defaults
$orderby = \'title\';
$order = \'asc\';
// If orderby is set, use this as the sort column
if(!empty($_GET[\'orderby\']))
{
$orderby = $_GET[\'orderby\'];
}
// If order is set use this as the order
if(!empty($_GET[\'order\']))
{
$order = $_GET[\'order\'];
}
$result = strnatcmp( $a[$orderby], $b[$orderby] );
if($order === \'asc\')
{
return $result;
}
return -$result;
}
}
如能及时答复,我们将不胜感激。
谢谢