附件元数据不保存时,使用单选按钮


Attachment Meta Data Not Saving When Using Radio Buttons

我已经为我的图像附件创建了以下元数据选项。基本上,用户选择一个单选按钮-然后将适当的类添加到div中,该div包裹在附件周围。由于某种原因,没有保存所选的单选按钮值。然而,我注意到,如果我将输入切换为常规文本字段,一切都工作得很好。

function add_attachment_classes_field( $form_fields, $post ) {
$field_value = get_post_meta( $post->ID, 'classes', true );
  $form_fields['classes'] = array(
    'value' => $field_value ? $field_value : '',
    'label' => __( 'Classes' ),
    'input' => 'html',
    'html' => "<div><input checked='checked' style='width: initial' type='radio' name='border-style' value=''> None</div>
                <div><input style='width: initial' type='radio' name='border-style' value='green-border'> Green</div>
                <div><input style='width: initial' type='radio' name='border-style' value='red-border'> Red</div>
                <div><input style='width: initial' type='radio' name='border-style' value='jagged-border'> Jagged</div>
                <div><input style='width: initial' type='radio' name='border-style' value='purple-border'> Purple</div>",
  );  
 return $form_fields;
}
function save_attachment_classes( $attachment_id ) {
  if ( isset( $_REQUEST['attachments'][$attachment_id]['classes'] ) ) {
    $classes = $_REQUEST['attachments'][$attachment_id]['classes'];
    update_post_meta( $attachment_id, 'classes', $classes );
  }
}
function wrap_my_div($html, $id, $caption, $title, $align, $url, $size, $alt) {
    $field_value = get_post_meta( $id, 'classes', true );
    return '<div class="'.$field_value.'">'.$html.'</div>';
}
add_action( 'edit_attachment', 'save_attachment_classes' );
add_filter( 'attachment_fields_to_edit', 'add_attachment_classes_field', 10, 2 );
add_filter( 'image_send_to_editor', 'wrap_my_div', 10, 8 );

问题似乎出在单选按钮的name属性上。

我把每一个改成下面的,它解决了问题:

name='attachments[{$post->ID}][classes]'