wordpress 后台添加菜单

有时候我们给网站增加了一些功能,比如在线充值,那么需要在后台能看到用户的充值记录,所以需要添加一个后台菜单。

add_action('admin_menu', 'credit_logs_page');
 function credit_logs_page() {
 add_menu_page('充值记录', '充值记录', 'manage_options', 'CREDIT_LOGS', 'credit_logs');
 add_submenu_page( 'CREDIT_LOGS', '购买记录', '购买记录','manage_options', 'ORDER_LOGS', 'order_logs');
 add_submenu_page( 'CREDIT_LOGS', '后台充值', '后台充值','manage_options', 'CREDIT_ADD', 'credit_add');
 }

function credit_logs(){

global $wpdb; 
$total   = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->credits WHERE status=1"); 
$perpage = 20; 
$pages = ceil($total / $perpage); 
$page=isset($_GET['paged']) ?intval($_GET['paged']) :1; 
$offset = $perpage*($page-1); 
$orders=$wpdb->get_results("SELECT * FROM $wpdb->credits where status=1 order by create_date DESC limit $offset,$perpage");
?> 
<div class="wrap"> 
<h1 class="wp-heading-inline">充值记录</h1> 
<table class="wp-list-table widefat fixed posts">            
<thead>            
<tr>             
<th width="20%">用户ID</th>                
<th width="30%">充值金额</th>                
<th width="50%">充值时间</th>            
</tr>            
</thead>            
<tbody>            
<?php             
if($orders){            
foreach ($orders as $order) {            
echo "<tr>\n";                    
echo "<td>".get_user_by("id",$order->user_id)->user_login."</td>";                    
echo "<td>".$order->price." 元</td>";                    
echo "<td>".$order->create_date."</td>";            
}            
}            
?>            
</tbody> 
</table> 
<?php echo MBThemes_admin_pagenavi($total,$perpage);?> 
</div>

<?php}