我正在寻找一种方法来添加<select>
媒体上传程序的菜单,有两个选项:普通图像,它不会做任何事情;配置文件图像,如果选中它,它会向图像添加CSS类。
我已经将选择菜单添加到上载程序中,但我不知道如何:
根据所选选项对图像应用一个类确保所选选项保持选中状态确保所选选项以后可以更改
function my_profile_image_select( $form_fields, $post ) {
$form_fields[\'image-type\'] = array(
\'label\' => \'Image Type\',
\'input\' => \'html\',
\'helps\' => \'Enter "profile-image" to enable profile image caption\',
);
$profile_image = \'profile-image\';
$normal_image = \'normal-image\';
$form_fields[\'image-type\'][\'html\'] = \'<select name="Profile Image Select" id="Profile Image Select">\';
$form_fields[\'image-type\'][\'html\'] .= \'<option value="\' . $normal_image . \'">Normal Image</option>\';
$form_fields[\'image-type\'][\'html\'] .= \'<option value="\' . $profile_image . \'">Profile Image</option>\';
$form_fields[\'image-type\'][\'html\'] .= \'</select>\';
return $form_fields;
}
add_filter( \'attachment_fields_to_edit\', \'my_profile_image_select\', 10, 2 );
SO网友:Firsh - justifiedgrid.com
要应用该类,您需要一个自定义函数来处理设置的值。
要确保选定的保持选中状态,请使用WP selected() function
$form_fields[\'image-type\'][\'html\'] = "<select name=\'attachments[{$post->ID}][profile_image_select]\'>";
$form_fields[\'image-type\'][\'html\'] .= \'<option \'.selected(get_post_meta($post->ID, "_profile_image_select", true), \'default\',false).\' value="\' . $normal_image . \'">Normal Image</option>\';
$form_fields[\'image-type\'][\'html\'] .= \'<option \'.selected(get_post_meta($post->ID, "_profile_image_select", true), \'default\',false).\' value="\' . $profile_image . \'">Profile Image</option>\';
$form_fields[\'image-type\'][\'html\'] .= \'</select>\';