在图像详细信息面板中添加控件

时间:2015-02-11 作者:Mika A.

我正在尝试在图像详细信息弹出窗口中添加复选框控件(在帖子中编辑图像时)。我在模板中添加了以下代码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\' );
enter image description here

1 个回复
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 );

结束

相关推荐

Admin Theme customization

我遵循wordpress codex网站上关于通过插件创建管理主题的说明。我激活了插件,但我的样式表没有包含在<head>.. 这是我的代码:add_action( \'admin_init\', \'kd_plugin_admin_init\' ); add_action( \'admin_menu\', \'kd_plugin_admin_menu\' ); function kd_plugin_admin_init() { /* Register