-
Notifications
You must be signed in to change notification settings - Fork 0
/
singledown-meta-box.php
191 lines (191 loc) · 6.89 KB
/
singledown-meta-box.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<?php
if ( !defined('ABSPATH') ) {exit;}
add_action( 'admin_menu', 'singledown_create_down_box' );
add_action( 'save_post', 'singledown_save_down_data' );
function singledown_create_down_box() {
add_meta_box( 'singledown_-post-meta-boxes','开启下载(请根据实际开启其中一种下载模式)', 'singledown_post_down_info', 'post', 'normal', 'high' );
}
function singledown_down_post_boxes() { //资源名称、资源大小、更新时间、适用版本、作者信息
$meta_boxes = array(
array(
"name" => "singledown_start",
"title" => "启用下载",
"desc" => "启用下载",
"type" => "checkbox",
"capability" => "manage_options"
),
array(
"name" => "singledown_name",
"title" => "资源名称",
"desc" => "",
"type" => "text",
"capability" => "manage_options"
),
array(
"name" => "singledown_size",
"title" => "资源大小",
"desc" => "",
"type" => "text",
"capability" => "manage_options"
),
array(
"name" => "singledown_date",
"title" => "更新时间",
"desc" => "",
"type" => "text",
"capability" => "manage_options"
),
array(
"name" => "singledown_version",
"title" => "适用版本",
"desc" => "",
"type" => "text",
"capability" => "manage_options"
),
array(
"name" => "singledown_author",
"title" => "作者信息",
"desc" => "",
"type" => "text",
"capability" => "manage_options"
),
array(
"name" => "singledown_guanfang",
"title" => "官方下载",
"desc" => "",
"type" => "text",
"capability" => "manage_options"
),
array(
"name" => "singledown_tianyi",
"title" => "天翼云盘",
"desc" => "",
"type" => "text",
"capability" => "manage_options"
),
array(
"name" => "singledown_tianyikey",
"title" => "提取码",
"desc" => "",
"type" => "text",
"capability" => "manage_options"
),
array(
"name" => "singledown_lanzouyun",
"title" => "蓝奏云",
"desc" => "",
"type" => "text",
"capability" => "manage_options"
),
array(
"name" => "singledown_lanzoukey",
"title" => "提取码",
"desc" => "",
"type" => "text",
"capability" => "manage_options"
),
array(
"name" => "singledown_chengtong",
"title" => "诚通网盘",
"desc" => "",
"type" => "text",
"capability" => "manage_options"
),
array(
"name" => "singledown_baidu",
"title" => "百度云盘",
"desc" => "",
"type" => "text",
"capability" => "manage_options"
),
array(
"name" => "singledown_baidukey",
"title" => "提取码",
"desc" => "",
"type" => "text",
"capability" => "manage_options"
),
array(
"name" => "singledown_demourl",
"title" => "在线演示",
"desc" => "",
"type" => "text",
"capability" => "manage_options"
)
);
return apply_filters( 'singledown_post_boxes', $meta_boxes );
}
function singledown_post_down_info() {
global $post;
$meta_boxes = singledown_down_post_boxes();
?>
<table class="form-table">
<?php foreach ( $meta_boxes as $meta ) :
$value = get_post_meta( $post->ID, $meta['name'], true );
if ( $meta['type'] == 'text' )
singledown_show_text_input( $meta, $value );
elseif ( $meta['type'] == 'textarea' )
singledown_show_textarea( $meta, $value );
elseif ( $meta['type'] == 'checkbox' )
singledown_show_checkbox( $meta, $value );
endforeach; ?>
</table>
<?php
}
function singledown_show_text_input( $args = array(), $value = false ) {
extract( $args ); ?>
<tr>
<th style="width:15%;">
<label for="<?php echo $name; ?>"><?php echo $title; ?></label>
</th>
<td>
<input type="text" name="<?php echo $name; ?>" id="<?php echo $name; ?>" value="<?php echo wp_specialchars( $value, 1 ); ?>" size="30" tabindex="30" style="width: 97%;" />
<input type="hidden" name="<?php echo $name; ?>_input_name" id="<?php echo $name; ?>_input_name" value="<?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?>" />
</td>
</tr>
<?php
}
function singledown_show_textarea( $args = array(), $value = false ) {
extract( $args ); ?>
<tr>
<th style="width:10%;">
<label for="<?php echo $name; ?>"><?php echo $title; ?></label>
</th>
<td>
<textarea name="<?php echo $name; ?>" id="<?php echo $name; ?>" cols="60" rows="4" tabindex="30" style="width: 97%;"><?php echo wp_specialchars( $value, 1 ); ?></textarea>
<input type="hidden" name="<?php echo $name; ?>_input_name" id="<?php echo $name; ?>_input_name" value="<?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?>" /> </td>
</tr>
<?php
}
function singledown_show_checkbox( $args = array(), $value = false ) {
extract( $args ); ?>
<tr>
<th style="width:10%;">
<label for="<?php echo $name; ?>"><?php echo $title; ?></label> </th>
<td>
<input type="checkbox" name="<?php echo $name; ?>" id="<?php echo $name; ?>" value="yes"
<?php if ( htmlentities( $value, 1 ) == 'yes' ) echo ' checked="checked"'; ?>
style="width: auto;" />
<input type="hidden" name="<?php echo $name; ?>_input_name" id="<?php echo $name; ?>_input_name" value="<?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?>" />
</td>
</tr>
<?php }
function singledown_save_down_data( $post_id ) {
$meta_boxes = array_merge( singledown_down_post_boxes() );
foreach ( $meta_boxes as $meta_box ) :
if ( !wp_verify_nonce( $_POST[$meta_box['name'] . '_input_name'], plugin_basename( __FILE__ ) ) )
return $post_id;
if ( 'page' == $_POST['post_type'] && !current_user_can( 'edit_page', $post_id ) )
return $post_id;
elseif ( 'post' == $_POST['post_type'] && !current_user_can( 'edit_post', $post_id ) )
return $post_id;
$data = stripslashes( $_POST[$meta_box['name']] );
if ( get_post_meta( $post_id, $meta_box['name'] ) == '' )
add_post_meta( $post_id, $meta_box['name'], $data, true );
elseif ( $data != get_post_meta( $post_id, $meta_box['name'], true ) )
update_post_meta( $post_id, $meta_box['name'], $data );
elseif ( $data == '' )
delete_post_meta( $post_id, $meta_box['name'], get_post_meta( $post_id, $meta_box['name'], true ) );
endforeach;
}
?>