我要修改的函数中有一个循环:
foreach ( $form_fields as $key => $val ) {
if ( 'menu_order' == $key ) {
if ( $gallery )
$order = "<div class='menu_order'> <input class='menu_order_input' type='text' id='attachments[$attachment_id][menu_order]' name='attachments[$attachment_id][menu_order]' value='" . esc_attr( $val['value'] ). "' /></div>";
else
$order = "<input type='hidden' name='attachments[$attachment_id][menu_order]' value='" . esc_attr( $val['value'] ) . "' />";
unset( $form_fields['menu_order'] );
break;
}
}
此循环循环通过 $form_fields 数组。如果“menu_order”是关键,那么,做一些事情并打破。现在我想再添加一个键来完成上述操作。所以,我修改如下:
foreach ( $form_fields as $key => $val ) {
if ( 'menu_order' == $key ) {
if ( $gallery )
$order = "<div class='menu_order'> <input class='menu_order_input' type='text' id='attachments[$attachment_id][menu_order]' name='attachments[$attachment_id][menu_order]' value='" . esc_attr( $val['value'] ). "' /></div>";
else
$order = "<input type='hidden' name='attachments[$attachment_id][menu_order]' value='" . esc_attr( $val['value'] ) . "' />";
unset( $form_fields['menu_order'] );
}
if ( 'post_status' == $key ) {
if ( $gallery )
$status = "<div class='post_status'> <input class='post_status_input' type='text' id='attachments[$attachment_id][post_status]' name='attachments[$attachment_id][post_status]' value='" . esc_attr( $val['value'] ). "' /></div>";
else
$status = "<input type='hidden' name='attachments[$attachment_id][post_status]' value='" . esc_attr( $val['value'] ) . "' />";
unset( $form_fields['post_status'] );
break;
}
}
请注意,我删除了原始代码中的中断,在循环末尾添加了中断。我认为这应该使循环直到完成我新添加的块。但是这段代码没有按预期打印 post_status 输入框。我在循环中哪里出错了?