Mã dưới đây thêm trường nhập tùy chỉnh vào trình chỉnh sửa tệp đính kèm. Làm cách nào tôi có thể chuyển đổi văn bản nhập thành hộp kiểm và nhận / đặt giá trị của hộp kiểm khi tải và lưu?
Lưu ý: "input" => "checkbox"
không không làm việc :(
function image_attachment_fields_to_edit($form_fields, $post) {
$form_fields["imageLinksTo"] = array(
"label" => __("Image Links To"),
"input" => "text",
"value" => get_post_meta($post->ID, "_imageLinksTo", true)
);
return $form_fields;
}
function image_attachment_fields_to_save($post, $attachment) {
if( isset($attachment['imageLinksTo']) ){
update_post_meta($post['ID'], '_imageLinksTo', $attachment['imageLinksTo']);
}
return $post;
}
add_filter("attachment_fields_to_edit", "image_attachment_fields_to_edit", null, 2);
add_filter("attachment_fields_to_save", "image_attachment_fields_to_save", null, 2);