WordPress 媒体上传额外字段

发布于 2024-10-03 12:50:18 字数 173 浏览 4 评论 0原文

如何在 WordPress 媒体面板中启用另一个字段?

目前您已拥有所有必需的字段,尽管我需要添加一个额外的字段来捕获一些额外的详细信息。

我正在使用一个 Flash 播放器来查找一组字段,理想情况下我想要一个名为 video_url 的字段

有什么想法吗?

How do I make another field available in the wordpress media panel?

Currently you have all your necesary fields, although I need to add one extra to capture some extra details.

I am using a flash player that looks for a set of fields, ideally I would like to a field called video_url

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

纵性 2024-10-10 12:50:18

我不确定如何在媒体面板内添加额外字段...但您可以使用 Magic Field 创建媒体上传器和一个包含额外详细信息的额外字段...在此处了解有关 Magic Field 插件的更多信息: http://wordpress.org/extend/plugins/magic-fields/

I'm not sure how to add an extra field inside the media panel... but you could use Magic Field to create a media uploader and an extra field which will contain your extra details... Learn more about Magic Field Plugin here : http://wordpress.org/extend/plugins/magic-fields/

黑凤梨 2024-10-10 12:50:18

想出了这个解决方案。

function rt_image_attachment_fields_to_edit($form_fields, $post) {
    // $form_fields is a an array of fields to include in the attachment form
    // $post is nothing but attachment record in the database
    //     $post->post_type == 'attachment'
    // attachments are considered as posts in WordPress. So value of post_type in wp_posts table will be attachment
    // now add our custom field to the $form_fields array
    // input type="text" name/id="attachments[$attachment->ID][custom1]"
    $form_fields["rt-image-link"] = array(
        "label" => __("Video URL"),
        "input" => "text", // this is default if "input" is omitted
        "value" => get_post_meta($post->ID, "_rt-image-link", true),
            "helps" => __(""),
    );

    $form_fields["rt-video-link"] = array(
        "label" => __("Library Ref"),
        "input" => "text", // this is default if "input" is omitted
        "value" => get_post_meta($post->ID, "_rt-video-link", true),
            "helps" => __(""),
    );
    return $form_fields;
}
// now attach our function to the hook
add_filter("attachment_fields_to_edit", "rt_image_attachment_fields_to_edit", null, 2);

function rt_image_attachment_fields_to_save($post, $attachment) {
    // $attachment part of the form $_POST ($_POST[attachments][postID])
    // $post['post_type'] == 'attachment'
    if( isset($attachment['rt-image-link']) ){
        // update_post_meta(postID, meta_key, meta_value);
        update_post_meta($post['ID'], '_rt-image-link', $attachment['rt-image-link']);
    }

    if( isset($attachment['rt-video-link']) ){
        // update_post_meta(postID, meta_key, meta_value);
        update_post_meta($post['ID'], '_rt-video-link', $attachment['rt-video-link']);
    }
    return $post;
}
// now attach our function to the hook.
add_filter("attachment_fields_to_save", "rt_image_attachment_fields_to_save", null , 2);

Came up with this solution.

function rt_image_attachment_fields_to_edit($form_fields, $post) {
    // $form_fields is a an array of fields to include in the attachment form
    // $post is nothing but attachment record in the database
    //     $post->post_type == 'attachment'
    // attachments are considered as posts in WordPress. So value of post_type in wp_posts table will be attachment
    // now add our custom field to the $form_fields array
    // input type="text" name/id="attachments[$attachment->ID][custom1]"
    $form_fields["rt-image-link"] = array(
        "label" => __("Video URL"),
        "input" => "text", // this is default if "input" is omitted
        "value" => get_post_meta($post->ID, "_rt-image-link", true),
            "helps" => __(""),
    );

    $form_fields["rt-video-link"] = array(
        "label" => __("Library Ref"),
        "input" => "text", // this is default if "input" is omitted
        "value" => get_post_meta($post->ID, "_rt-video-link", true),
            "helps" => __(""),
    );
    return $form_fields;
}
// now attach our function to the hook
add_filter("attachment_fields_to_edit", "rt_image_attachment_fields_to_edit", null, 2);

function rt_image_attachment_fields_to_save($post, $attachment) {
    // $attachment part of the form $_POST ($_POST[attachments][postID])
    // $post['post_type'] == 'attachment'
    if( isset($attachment['rt-image-link']) ){
        // update_post_meta(postID, meta_key, meta_value);
        update_post_meta($post['ID'], '_rt-image-link', $attachment['rt-image-link']);
    }

    if( isset($attachment['rt-video-link']) ){
        // update_post_meta(postID, meta_key, meta_value);
        update_post_meta($post['ID'], '_rt-video-link', $attachment['rt-video-link']);
    }
    return $post;
}
// now attach our function to the hook.
add_filter("attachment_fields_to_save", "rt_image_attachment_fields_to_save", null , 2);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文