我正在尝试在图像详细信息弹出窗口中添加复选框控件(在帖子中编辑图像时)。我在模板中添加了以下代码function.php
但我无法在弹出窗口中显示复选框。我错过了什么?
function bluesolutions_customize_register($wp_customize) {
$wp_customize->add_section(\'bluesolutions_use_lighbox_section\', array(
\'title\' => __(\'Lightbox\', \'mytheme\'),
\'description\' => \'\',
\'priority\' => 120,
));
$wp_customize->add_setting(\'mytheme_use_lighbox_setting\', array(
\'default\' => 0,
\'capability\' => \'\',
\'type\' => \'checkbox\',
));
$wp_customize->add_control(new WP_Customize_Image_Control(
$wp_customize, \'use_lighbox\', array(
\'label\' => __(\'Usen lightbox\', \'mytheme\'),
\'section\' => \'advanced\',
\'settings\' => \'mytheme_use_lighbox_setting\',
\'priority\' => 1,
\'type\' => \'checkbox\',
)
));
}
add_action( \'customize_register\', \'bluesolutions_customize_register\' );
SO网友:Nhat Quang
您可以使用此代码
function your_slug_edit_media_custom_checkbox( $form_fields, $post ) {
$form_fields[\'custom_field\'] = array(
\'label\' => \'Custom Field\',
\'input\' => \'text\',
\'value\' => get_post_meta( $post->ID, \'_custom_field\', true )
);
return $form_fields;
}
function your_slug_save_media_custom_field( $post, $attachment ) {
update_post_meta( $post[\'ID\'], \'_custom_field\', $attachment[\'custom_field\'] );
return $post;
}
add_filter( \'attachment_fields_to_edit\', \'edit_media_custom_checkbox\', 11, 2 );
add_filter( \'attachment_fields_to_save\', \'save_media_custom_checkbox\', 11, 2 );