... | ... |
@@ -60,7 +60,7 @@ class admin_table_plugin { |
60 | 60 |
} |
61 | 61 |
|
62 | 62 |
public function admin_menu() { |
63 |
- $hook = add_menu_page('페이지 상단제목', '버튼이름2', 'manage_options', 'admintable', |
|
63 |
+ $hook = add_menu_page('관리자 리스트 테이블', '리스트 테이블', 'manage_options', 'admintable', |
|
64 | 64 |
array($this, 'admin_page'), 'dashicons-admin-post'); |
65 | 65 |
|
66 | 66 |
add_action("load-$hook", array($this, 'screen_option')); |
... | ... |
@@ -79,7 +79,7 @@ class admin_table_plugin { |
79 | 79 |
} |
80 | 80 |
|
81 | 81 |
public function admin_page() { |
82 |
- echo '<div class="wrap"><h2>My List Table Test</h2>'; |
|
82 |
+ echo '<div class="wrap"><h2>리스트 테이블 예제</h2>'; |
|
83 | 83 |
echo '<form method="post">'; |
84 | 84 |
|
85 | 85 |
$this->_tablelist->prepare_items(); |
... | ... |
@@ -7,8 +7,11 @@ |
7 | 7 |
* Author URI: https://hiseon.me/ |
8 | 8 |
*/ |
9 | 9 |
|
10 |
+include_once "table.php"; |
|
11 |
+ |
|
10 | 12 |
class admin_table_plugin { |
11 | 13 |
protected static $_instance = null; |
14 |
+ public $_tablelist; |
|
12 | 15 |
|
13 | 16 |
public static function instance() { |
14 | 17 |
if (is_null(self::$_instance)) { |
... | ... |
@@ -19,6 +22,7 @@ class admin_table_plugin { |
19 | 22 |
} |
20 | 23 |
|
21 | 24 |
protected function __construct() { |
25 |
+ $this->init(); |
|
22 | 26 |
} |
23 | 27 |
|
24 | 28 |
private function __clone() {} |
... | ... |
@@ -40,17 +44,58 @@ class admin_table_plugin { |
40 | 44 |
name text, |
41 | 45 |
address text, |
42 | 46 |
city text |
43 |
- ) ;"; |
|
44 |
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
45 |
- dbDelta( $sql ); |
|
47 |
+ );"; |
|
48 |
+ require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
49 |
+ dbDelta($sql); |
|
46 | 50 |
} |
47 | 51 |
} |
52 |
+ |
|
53 |
+ public function init() { |
|
54 |
+ add_filter('set-screen-option', array($this, 'set_screen'), 10, 3); |
|
55 |
+ add_action('admin_menu', array($this, 'admin_menu')); |
|
56 |
+ } |
|
57 |
+ |
|
58 |
+ public function set_screen($status, $option, $value) { |
|
59 |
+ return $value; |
|
60 |
+ } |
|
61 |
+ |
|
62 |
+ public function admin_menu() { |
|
63 |
+ $hook = add_menu_page('페이지 상단제목', '버튼이름2', 'manage_options', 'admintable', |
|
64 |
+ array($this, 'admin_page'), 'dashicons-admin-post'); |
|
65 |
+ |
|
66 |
+ add_action("load-$hook", array($this, 'screen_option')); |
|
67 |
+ } |
|
68 |
+ |
|
69 |
+ public function screen_option() { |
|
70 |
+ $option = 'per_page'; |
|
71 |
+ $args = array( |
|
72 |
+ 'label' => 'Customers', |
|
73 |
+ 'default' => 10, |
|
74 |
+ 'option' => 'customers_per_page' |
|
75 |
+ ); |
|
76 |
+ |
|
77 |
+ add_screen_option($option, $args); |
|
78 |
+ $this->_tablelist = new admin_list_table(); |
|
79 |
+ } |
|
80 |
+ |
|
81 |
+ public function admin_page() { |
|
82 |
+ echo '<div class="wrap"><h2>My List Table Test</h2>'; |
|
83 |
+ echo '<form method="post">'; |
|
84 |
+ |
|
85 |
+ $this->_tablelist->prepare_items(); |
|
86 |
+ $this->_tablelist->display(); |
|
87 |
+ |
|
88 |
+ echo '</form>'; |
|
89 |
+ echo '</div>'; |
|
90 |
+ } |
|
48 | 91 |
} |
49 | 92 |
|
50 | 93 |
function ATP() { |
51 | 94 |
return admin_table_plugin::instance(); |
52 | 95 |
} |
53 | 96 |
|
97 |
+ATP(); |
|
98 |
+ |
|
54 | 99 |
function admin_table_activate() { |
55 | 100 |
ATP()->install(); |
56 | 101 |
} |
... | ... |
@@ -27,7 +27,7 @@ class admin_table_plugin { |
27 | 27 |
|
28 | 28 |
public function get_table_name() { |
29 | 29 |
global $wpdb; |
30 |
- return $wpdb->prefix.'customers2'; |
|
30 |
+ return $wpdb->prefix.'customers'; |
|
31 | 31 |
} |
32 | 32 |
|
33 | 33 |
public function install() { |
... | ... |
@@ -36,10 +36,10 @@ class admin_table_plugin { |
36 | 36 |
|
37 | 37 |
if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) { |
38 | 38 |
$sql = "CREATE TABLE $table_name ( |
39 |
- id mediumint(9) NOT NULL AUTO_INCREMENT, |
|
40 |
- field_x text NOT NULL, |
|
41 |
- field_y text NOT NULL, |
|
42 |
- UNIQUE KEY id (id) |
|
39 |
+ ID int auto_increment primary key, |
|
40 |
+ name text, |
|
41 |
+ address text, |
|
42 |
+ city text |
|
43 | 43 |
) ;"; |
44 | 44 |
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
45 | 45 |
dbDelta( $sql ); |
... | ... |
@@ -25,7 +25,25 @@ class admin_table_plugin { |
25 | 25 |
private function __sleep() {} |
26 | 26 |
private function __wakeup() {} |
27 | 27 |
|
28 |
+ public function get_table_name() { |
|
29 |
+ global $wpdb; |
|
30 |
+ return $wpdb->prefix.'customers2'; |
|
31 |
+ } |
|
32 |
+ |
|
28 | 33 |
public function install() { |
34 |
+ global $wpdb; |
|
35 |
+ $table_name = $this->get_table_name(); |
|
36 |
+ |
|
37 |
+ if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) { |
|
38 |
+ $sql = "CREATE TABLE $table_name ( |
|
39 |
+ id mediumint(9) NOT NULL AUTO_INCREMENT, |
|
40 |
+ field_x text NOT NULL, |
|
41 |
+ field_y text NOT NULL, |
|
42 |
+ UNIQUE KEY id (id) |
|
43 |
+ ) ;"; |
|
44 |
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
45 |
+ dbDelta( $sql ); |
|
46 |
+ } |
|
29 | 47 |
} |
30 | 48 |
} |
31 | 49 |
|
... | ... |
@@ -7,7 +7,34 @@ |
7 | 7 |
* Author URI: https://hiseon.me/ |
8 | 8 |
*/ |
9 | 9 |
|
10 |
+class admin_table_plugin { |
|
11 |
+ protected static $_instance = null; |
|
12 |
+ |
|
13 |
+ public static function instance() { |
|
14 |
+ if (is_null(self::$_instance)) { |
|
15 |
+ self::$_instance = new self(); |
|
16 |
+ } |
|
17 |
+ |
|
18 |
+ return self::$_instance; |
|
19 |
+ } |
|
20 |
+ |
|
21 |
+ protected function __construct() { |
|
22 |
+ } |
|
23 |
+ |
|
24 |
+ private function __clone() {} |
|
25 |
+ private function __sleep() {} |
|
26 |
+ private function __wakeup() {} |
|
27 |
+ |
|
28 |
+ public function install() { |
|
29 |
+ } |
|
30 |
+} |
|
31 |
+ |
|
32 |
+function ATP() { |
|
33 |
+ return admin_table_plugin::instance(); |
|
34 |
+} |
|
35 |
+ |
|
10 | 36 |
function admin_table_activate() { |
37 |
+ ATP()->install(); |
|
11 | 38 |
} |
12 | 39 |
|
13 | 40 |
register_activation_hook(__FILE__, 'admin_table_activate'); |