get_columns(); $sortable = $this->get_sortable_columns(); $data = GDK_Points::get_points(null, null, null, ARRAY_A); usort( $data, array( &$this, 'sort_data' ) ); $perPage = 30; //每页30个数据 $currentPage = $this->get_pagenum(); $totalItems = count($data); $this->set_pagination_args([ 'total_items' => $totalItems, 'per_page' => $perPage, ]); $data = array_slice($data, (($currentPage - 1) * $perPage), $perPage); $this->_column_headers = [ $columns, $sortable, ]; $this->items = $data; } /** * Override the parent columns method. * Defines the columns to use in your listing table * * @return Array */ public function get_columns() { $columns = [ 'point_id' => 'ID', 'user_id' => '用户ID', 'points' => '金币', 'description' => '描述', 'datetime' => '日期&时间', 'status' => '状态', 'actions' => '操作', ]; return $columns; } /** * Define the sortable columns * * @return Array */ public function get_sortable_columns() { return [ 'point_id' => [ 'point_id', false, ], 'user_id' => [ 'user_id', false, ], 'points' => [ 'points', false, ], 'description' => [ 'description', false, ], 'datetime' => [ 'datetime', false, ], 'status' => [ 'status', false, ], ]; } /** * 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 'point_id': case 'user_id': case 'description': case 'points': case 'datetime': case 'status': return $item[$column_name]; break; case 'actions': $actions = [ 'edit' => sprintf('编辑', $_REQUEST['page'], 'edit', $item['point_id']), 'delete' => sprintf('删除', $_REQUEST['page'], 'delete', $item['point_id']), ]; //Return the title contents return sprintf('%1$s%2$s', $item[$column_name] ?? "", $this->row_actions($actions, true) ); break; 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 = 'point_id'; $order = 'desc';//desc 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; } } /** * GDK_Points Admin class */ class GDK_Points_Admin { public static function init() { add_action('admin_notices', [__CLASS__, 'admin_notices']); add_action('admin_menu', [__CLASS__, 'admin_menu'], 'manage_options'); } public static function admin_notices() { if (!empty(self::$notices)) { foreach (self::$notices as $notice) { echo $notice; } } } /** * Adds the admin section. */ public static function admin_menu() { $admin_page = add_menu_page('金币', '金币', 'manage_options', 'points', [__CLASS__, 'points_menu'], 'dashicons-awards'); } public static function points_menu() { $alert = ""; if (isset($_POST['psearch'])) { $sdata = trim($_POST['psearch']); if (preg_match('/E20/', $sdata) ) { //order id global $wpdb; $point_id = $wpdb->get_row("SELECT point_id FROM " . GDK_Points_Database::points_get_table("users") . " WHERE description = '{$sdata}'", ARRAY_A)['point_id']; $points = GDK_Points::get_point($point_id); }elseif (preg_match('/(D|d)/', $sdata)){// description $data = substr($sdata,1); global $wpdb; $points = $wpdb->get_results("SELECT * FROM " . GDK_Points_Database::points_get_table("users") . " WHERE description = '{$data}'"); //var_dump($points); $k[] = '
您的金币金额被管理员调整,请查收!
如果您的金币金额有异常,请您在第一时间和我们取得联系哦,联系邮箱:' . get_bloginfo('admin_email') . '
'; $message = mail_temp($mail_title, $mail_cotent, home_url(), get_bloginfo('name')); $headers = "Content-Type:text/html;charset=UTF-8\n"; wp_mail($usermail, 'Hi,' . $username . ',金币账户金额变动通知!', $message, $headers); } } $alert = "金币已更新"; } if (isset($_GET["action"])) { $action = $_GET["action"]; if ($action !== null) { switch ($action) { case 'edit': if (isset($_GET['point_id']) && ($_GET['point_id'] !== null)) { return self::points_admin_points_edit(intval($_GET['point_id'])); } else { return self::points_admin_points_edit(); } break; case 'delete': if ($_GET['point_id'] !== null) { if (current_user_can('administrator')) { GDK_Points::remove_points($_GET['point_id']); global $wpdb; $wcu_sql = "DELETE FROM " . GDK_Points_Database::points_get_table("users") . " WHERE status = 'removed'"; $wpdb->query($wcu_sql); $alert = "金币已删除"; } } break; } } } if ($alert != "") { echo '