質問編集履歴
1
ソースコード
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,268 +4,266 @@
|
|
4
4
|
|
5
5
|
おそらくarrayで配列をすると思います。
|
6
6
|
|
7
|
+
```PHP
|
8
|
+
|
9
|
+
/**
|
10
|
+
|
11
|
+
* Adds a box to the main column on the Post and Page edit screens.
|
12
|
+
|
13
|
+
*/
|
14
|
+
|
15
|
+
function myplugin_add_meta_box() {
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
$screens = array( 'circle' );
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
foreach ( $screens as $screen ) {
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
add_meta_box(
|
28
|
+
|
29
|
+
'myplugin_sectionid',
|
30
|
+
|
31
|
+
__( 'サークル情報', 'myplugin_textdomain' ),
|
32
|
+
|
33
|
+
'myplugin_meta_box_callback',
|
34
|
+
|
35
|
+
$screen
|
36
|
+
|
37
|
+
);
|
38
|
+
|
39
|
+
}
|
40
|
+
|
41
|
+
}
|
42
|
+
|
43
|
+
add_action( 'add_meta_boxes', 'myplugin_add_meta_box' );
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
/**
|
48
|
+
|
49
|
+
* Prints the box content.
|
50
|
+
|
51
|
+
*
|
52
|
+
|
53
|
+
* @param WP_Post $post The object for the current post/page.
|
54
|
+
|
55
|
+
*/
|
56
|
+
|
57
|
+
function myplugin_meta_box_callback( $post ) {
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
// Add a nonce field so we can check for it later.
|
62
|
+
|
63
|
+
wp_nonce_field( 'myplugin_save_meta_box_data', 'myplugin_meta_box_nonce' );
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
/*
|
68
|
+
|
69
|
+
* Use get_post_meta() to retrieve an existing value
|
70
|
+
|
71
|
+
* from the database and use the value for the form.
|
72
|
+
|
73
|
+
*/
|
74
|
+
|
75
|
+
$value = get_post_meta( $post->ID, 'circlename', true );
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
echo '<label for="circlename">';
|
80
|
+
|
81
|
+
_e( 'サークル名', 'myplugin_textdomain' );
|
82
|
+
|
83
|
+
echo '</label><br>';
|
84
|
+
|
85
|
+
echo '<input class="circlename" type="text" id="circlename" name="circlename" value="' . esc_attr( $value ) . '" size="25" /><br>';
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
$value = get_post_meta( $post->ID, 'penname', true );
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
echo '<label for="penname">';
|
94
|
+
|
95
|
+
_e( 'PN', 'myplugin_textdomain' );
|
96
|
+
|
97
|
+
echo '</label><br>';
|
98
|
+
|
99
|
+
echo '<input class="penname" type="text" id="penname" name="penname" value="' . esc_attr( $value ) . '" size="25" /><br>';
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
$value = get_post_meta( $post->ID, 'genre', true );
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
echo '<label for="genre">';
|
108
|
+
|
109
|
+
_e( 'ジャンル', 'myplugin_textdomain' );
|
110
|
+
|
111
|
+
echo '</label><br>';
|
112
|
+
|
113
|
+
echo '<input class="genre" type="text" id="genre" name="genre" value="' . esc_attr( $value ) . '" size="25" /><br>';
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
$value = get_post_meta( $post->ID, 'spacenumber', true );
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
echo '<label for="spacenumber">';
|
122
|
+
|
123
|
+
_e( 'スペースNO', 'myplugin_textdomain' );
|
124
|
+
|
125
|
+
echo '</label><br>';
|
126
|
+
|
127
|
+
echo '<input class="spacenumber" type="text" id="spacenumber" name="spacenumber" value="' . esc_attr( $value ) . '" size="25" />';
|
128
|
+
|
129
|
+
}
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
/**
|
134
|
+
|
135
|
+
* When the post is saved, saves our custom data.
|
136
|
+
|
137
|
+
*
|
138
|
+
|
139
|
+
* @param int $post_id The ID of the post being saved.
|
140
|
+
|
141
|
+
*/
|
142
|
+
|
143
|
+
function myplugin_save_meta_box_data( $post_id ) {
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
/*
|
148
|
+
|
149
|
+
* We need to verify this came from our screen and with proper authorization,
|
150
|
+
|
151
|
+
* because the save_post action can be triggered at other times.
|
152
|
+
|
153
|
+
*/
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
// Check if our nonce is set.
|
158
|
+
|
159
|
+
if ( ! isset( $_POST['myplugin_meta_box_nonce'] ) ) {
|
160
|
+
|
161
|
+
return;
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
// Verify that the nonce is valid.
|
168
|
+
|
169
|
+
if ( ! wp_verify_nonce( $_POST['myplugin_meta_box_nonce'], 'myplugin_save_meta_box_data' ) ) {
|
170
|
+
|
171
|
+
return;
|
172
|
+
|
173
|
+
}
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
// If this is an autosave, our form has not been submitted, so we don't want to do anything.
|
178
|
+
|
179
|
+
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
|
180
|
+
|
181
|
+
return;
|
182
|
+
|
183
|
+
}
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
// Check the user's permissions.
|
188
|
+
|
189
|
+
if ( isset( $_POST['post_type'] ) && 'page' == $_POST['post_type'] ) {
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
if ( ! current_user_can( 'edit_page', $post_id ) ) {
|
194
|
+
|
195
|
+
return;
|
196
|
+
|
197
|
+
}
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
} else {
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
if ( ! current_user_can( 'edit_post', $post_id ) ) {
|
206
|
+
|
207
|
+
return;
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
}
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
/* OK, it's safe for us to save the data now. */
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
if ( ! isset( $_POST['circlename'] ) ) {
|
220
|
+
|
221
|
+
return;
|
222
|
+
|
223
|
+
}
|
224
|
+
|
225
|
+
$my_data = sanitize_text_field( $_POST['circlename'] );
|
226
|
+
|
227
|
+
update_post_meta( $post_id, 'circlename', $my_data );
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
if ( ! isset( $_POST['penname'] ) ) {
|
232
|
+
|
233
|
+
return;
|
234
|
+
|
235
|
+
}
|
236
|
+
|
237
|
+
$my_data = sanitize_text_field( $_POST['penname'] );
|
238
|
+
|
239
|
+
update_post_meta( $post_id, 'penname', $my_data );
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
if ( ! isset( $_POST['genre'] ) ) {
|
244
|
+
|
245
|
+
return;
|
246
|
+
|
247
|
+
}
|
248
|
+
|
249
|
+
$my_data = sanitize_text_field( $_POST['genre'] );
|
250
|
+
|
251
|
+
update_post_meta( $post_id, 'genre', $my_data );
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
if ( ! isset( $_POST['spacenumber'] ) ) {
|
256
|
+
|
257
|
+
return;
|
258
|
+
|
259
|
+
}
|
260
|
+
|
261
|
+
$my_data = sanitize_text_field( $_POST['spacenumber'] );
|
262
|
+
|
263
|
+
update_post_meta( $post_id, 'spacenumber', $my_data );
|
264
|
+
|
265
|
+
}
|
266
|
+
|
267
|
+
add_action( 'save_post', 'myplugin_save_meta_box_data' );
|
268
|
+
|
7
269
|
```
|
8
|
-
|
9
|
-
/**
|
10
|
-
|
11
|
-
* Adds a box to the main column on the Post and Page edit screens.
|
12
|
-
|
13
|
-
*/
|
14
|
-
|
15
|
-
function myplugin_add_meta_box() {
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
$screens = array( 'circle' );
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
foreach ( $screens as $screen ) {
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
add_meta_box(
|
28
|
-
|
29
|
-
'myplugin_sectionid',
|
30
|
-
|
31
|
-
__( 'サークル情報', 'myplugin_textdomain' ),
|
32
|
-
|
33
|
-
'myplugin_meta_box_callback',
|
34
|
-
|
35
|
-
$screen
|
36
|
-
|
37
|
-
);
|
38
|
-
|
39
|
-
}
|
40
|
-
|
41
|
-
}
|
42
|
-
|
43
|
-
add_action( 'add_meta_boxes', 'myplugin_add_meta_box' );
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
/**
|
48
|
-
|
49
|
-
* Prints the box content.
|
50
|
-
|
51
|
-
*
|
52
|
-
|
53
|
-
* @param WP_Post $post The object for the current post/page.
|
54
|
-
|
55
|
-
*/
|
56
|
-
|
57
|
-
function myplugin_meta_box_callback( $post ) {
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
// Add a nonce field so we can check for it later.
|
62
|
-
|
63
|
-
wp_nonce_field( 'myplugin_save_meta_box_data', 'myplugin_meta_box_nonce' );
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
/*
|
68
|
-
|
69
|
-
* Use get_post_meta() to retrieve an existing value
|
70
|
-
|
71
|
-
* from the database and use the value for the form.
|
72
|
-
|
73
|
-
*/
|
74
|
-
|
75
|
-
$value = get_post_meta( $post->ID, 'circlename', true );
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
echo '<label for="circlename">';
|
80
|
-
|
81
|
-
_e( 'サークル名', 'myplugin_textdomain' );
|
82
|
-
|
83
|
-
echo '</label><br>';
|
84
|
-
|
85
|
-
echo '<input class="circlename" type="text" id="circlename" name="circlename" value="' . esc_attr( $value ) . '" size="25" /><br>';
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
$value = get_post_meta( $post->ID, 'penname', true );
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
echo '<label for="penname">';
|
94
|
-
|
95
|
-
_e( 'PN', 'myplugin_textdomain' );
|
96
|
-
|
97
|
-
echo '</label><br>';
|
98
|
-
|
99
|
-
echo '<input class="penname" type="text" id="penname" name="penname" value="' . esc_attr( $value ) . '" size="25" /><br>';
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
$value = get_post_meta( $post->ID, 'genre', true );
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
echo '<label for="genre">';
|
108
|
-
|
109
|
-
_e( 'ジャンル', 'myplugin_textdomain' );
|
110
|
-
|
111
|
-
echo '</label><br>';
|
112
|
-
|
113
|
-
echo '<input class="genre" type="text" id="genre" name="genre" value="' . esc_attr( $value ) . '" size="25" /><br>';
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
$value = get_post_meta( $post->ID, 'spacenumber', true );
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
echo '<label for="spacenumber">';
|
122
|
-
|
123
|
-
_e( 'スペースNO', 'myplugin_textdomain' );
|
124
|
-
|
125
|
-
echo '</label><br>';
|
126
|
-
|
127
|
-
echo '<input class="spacenumber" type="text" id="spacenumber" name="spacenumber" value="' . esc_attr( $value ) . '" size="25" />';
|
128
|
-
|
129
|
-
}
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
/**
|
134
|
-
|
135
|
-
* When the post is saved, saves our custom data.
|
136
|
-
|
137
|
-
*
|
138
|
-
|
139
|
-
* @param int $post_id The ID of the post being saved.
|
140
|
-
|
141
|
-
*/
|
142
|
-
|
143
|
-
function myplugin_save_meta_box_data( $post_id ) {
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
/*
|
148
|
-
|
149
|
-
* We need to verify this came from our screen and with proper authorization,
|
150
|
-
|
151
|
-
* because the save_post action can be triggered at other times.
|
152
|
-
|
153
|
-
*/
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
// Check if our nonce is set.
|
158
|
-
|
159
|
-
if ( ! isset( $_POST['myplugin_meta_box_nonce'] ) ) {
|
160
|
-
|
161
|
-
return;
|
162
|
-
|
163
|
-
}
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
// Verify that the nonce is valid.
|
168
|
-
|
169
|
-
if ( ! wp_verify_nonce( $_POST['myplugin_meta_box_nonce'], 'myplugin_save_meta_box_data' ) ) {
|
170
|
-
|
171
|
-
return;
|
172
|
-
|
173
|
-
}
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
// If this is an autosave, our form has not been submitted, so we don't want to do anything.
|
178
|
-
|
179
|
-
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
|
180
|
-
|
181
|
-
return;
|
182
|
-
|
183
|
-
}
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
// Check the user's permissions.
|
188
|
-
|
189
|
-
if ( isset( $_POST['post_type'] ) && 'page' == $_POST['post_type'] ) {
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
if ( ! current_user_can( 'edit_page', $post_id ) ) {
|
194
|
-
|
195
|
-
return;
|
196
|
-
|
197
|
-
}
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
} else {
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
if ( ! current_user_can( 'edit_post', $post_id ) ) {
|
206
|
-
|
207
|
-
return;
|
208
|
-
|
209
|
-
}
|
210
|
-
|
211
|
-
}
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
/* OK, it's safe for us to save the data now. */
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
if ( ! isset( $_POST['circlename'] ) ) {
|
220
|
-
|
221
|
-
return;
|
222
|
-
|
223
|
-
}
|
224
|
-
|
225
|
-
$my_data = sanitize_text_field( $_POST['circlename'] );
|
226
|
-
|
227
|
-
update_post_meta( $post_id, 'circlename', $my_data );
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
if ( ! isset( $_POST['penname'] ) ) {
|
232
|
-
|
233
|
-
return;
|
234
|
-
|
235
|
-
}
|
236
|
-
|
237
|
-
$my_data = sanitize_text_field( $_POST['penname'] );
|
238
|
-
|
239
|
-
update_post_meta( $post_id, 'penname', $my_data );
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
if ( ! isset( $_POST['genre'] ) ) {
|
244
|
-
|
245
|
-
return;
|
246
|
-
|
247
|
-
}
|
248
|
-
|
249
|
-
$my_data = sanitize_text_field( $_POST['genre'] );
|
250
|
-
|
251
|
-
update_post_meta( $post_id, 'genre', $my_data );
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
if ( ! isset( $_POST['spacenumber'] ) ) {
|
256
|
-
|
257
|
-
return;
|
258
|
-
|
259
|
-
}
|
260
|
-
|
261
|
-
$my_data = sanitize_text_field( $_POST['spacenumber'] );
|
262
|
-
|
263
|
-
update_post_meta( $post_id, 'spacenumber', $my_data );
|
264
|
-
|
265
|
-
}
|
266
|
-
|
267
|
-
add_action( 'save_post', 'myplugin_save_meta_box_data' );
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
```
|