最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Remove the 'Attachment Details' section of the wordpress media manager

programmeradmin1浏览0评论

I'm using the new WP media manager for a branding plugin (well, new from 3.5), and it is working well.

My only issue is that I have an 'Attachment Details' area on the right, allowing users to edit, delete and generally mess with images.

Is there a way to remove this area? Thanks.

Here is an image showing which area I want to eliminate -

Here is my JS to invoke the media manager -

$(document).ready(function(){

    var dd_media_frame,     // The custom dd_media frame
        clicked_parent = 0; // The parent element of the button that was clicked

    /** Open the media manager when the any button with the class 'open-media-manager' is clicked*/
    $('#dd-custom-branding-metabox').on('click', '.manage-images-button', function(e){

        e.preventDefault();

        clicked_parent = $(this).parent();

        /** Ensure the 'dd_media_frame' media manager instance already exists (i.e. if it's already been used since the page was loaded) */
        if(!dd_media_frame){

            dd_media_frame = wp.media.frames.dd_media_frame = wp.media({

                /** Set the parameters for the media uploader */
                button: { text: 'Select image' },                           // Set the text of the button.
                className: 'media-frame custom-admin-branding-media-frame', // The class to use for this instance of the media manager
                library: { type: 'image' },                                 // Ensure only images are allowed
                multiple: false,                                            // Disable multiple selections
                title: 'Select a custom admin header image'                 // The tile to show in the media uploader
            });

            dd_media_frame.on('select', function(){

                /** Grab the attachment selection and construct a JSON representation of the model */
                var media_attachment = dd_media_frame.state().get('selection').first().toJSON();

                /** Update the hidden 'branding[header_logo]' field with the ID of the selected logo */
                clicked_parent.find('input[name="branding[header_logo]"]', '#dd-custom-branding-metabox').val(media_attachment.id);

            });

        }

        /** Finally, open the media manager */
        dd_media_frame.open();

    });

});

I'm using the new WP media manager for a branding plugin (well, new from 3.5), and it is working well.

My only issue is that I have an 'Attachment Details' area on the right, allowing users to edit, delete and generally mess with images.

Is there a way to remove this area? Thanks.

Here is an image showing which area I want to eliminate -

Here is my JS to invoke the media manager -

$(document).ready(function(){

    var dd_media_frame,     // The custom dd_media frame
        clicked_parent = 0; // The parent element of the button that was clicked

    /** Open the media manager when the any button with the class 'open-media-manager' is clicked*/
    $('#dd-custom-branding-metabox').on('click', '.manage-images-button', function(e){

        e.preventDefault();

        clicked_parent = $(this).parent();

        /** Ensure the 'dd_media_frame' media manager instance already exists (i.e. if it's already been used since the page was loaded) */
        if(!dd_media_frame){

            dd_media_frame = wp.media.frames.dd_media_frame = wp.media({

                /** Set the parameters for the media uploader */
                button: { text: 'Select image' },                           // Set the text of the button.
                className: 'media-frame custom-admin-branding-media-frame', // The class to use for this instance of the media manager
                library: { type: 'image' },                                 // Ensure only images are allowed
                multiple: false,                                            // Disable multiple selections
                title: 'Select a custom admin header image'                 // The tile to show in the media uploader
            });

            dd_media_frame.on('select', function(){

                /** Grab the attachment selection and construct a JSON representation of the model */
                var media_attachment = dd_media_frame.state().get('selection').first().toJSON();

                /** Update the hidden 'branding[header_logo]' field with the ID of the selected logo */
                clicked_parent.find('input[name="branding[header_logo]"]', '#dd-custom-branding-metabox').val(media_attachment.id);

            });

        }

        /** Finally, open the media manager */
        dd_media_frame.open();

    });

});
Share Improve this question asked Nov 1, 2013 at 10:39 David GardDavid Gard 3,3105 gold badges26 silver badges39 bronze badges 1
  • Je recherche la même solution pour mon site et ce code ne marche pas Aidez-moi svp – herm lemoine Commented Dec 17, 2020 at 10:58
Add a comment  | 

2 Answers 2

Reset to default 4

I use CSS for that:

add_action('admin_head-post.php', 'hide_media_stuff_wpse_120894' );
add_action('admin_head-post-new.php', 'hide_media_stuff_wpse_120894' );

function hide_media_stuff_wpse_120894(){
    ?>
    <style type="text/css">
        .attachment-details [data-setting="title"],
        .attachment-details [data-setting="caption"],
        .attachment-details [data-setting="alt"],
        .attachment-details [data-setting="description"],
        div.attachment-display-settings
        {
            display:none
        }
    </style>
    <?php
}

Have you tried to remove it with js before opening the manager?

$(document).ready(function(){

    var dd_media_frame,     // The custom dd_media frame
        clicked_parent = 0; // The parent element of the button that was clicked

    /** Open the media manager when the any button with the class 'open-media-manager' is clicked*/
    $('#dd-custom-branding-metabox').on('click', '.manage-images-button', function(e){

        e.preventDefault();

        clicked_parent = $(this).parent();

        /** Ensure the 'dd_media_frame' media manager instance already exists (i.e. if it's already been used since the page was loaded) */
        if(!dd_media_frame){

            dd_media_frame = wp.media.frames.dd_media_frame = wp.media({

                /** Set the parameters for the media uploader */
                button: { text: 'Select image' },                           // Set the text of the button.
                className: 'media-frame custom-admin-branding-media-frame', // The class to use for this instance of the media manager
                library: { type: 'image' },                                 // Ensure only images are allowed
                multiple: false,                                            // Disable multiple selections
                title: 'Select a custom admin header image'                 // The tile to show in the media uploader
            });

            dd_media_frame.on('select', function(){

                /** Grab the attachment selection and construct a JSON representation of the model */
                var media_attachment = dd_media_frame.state().get('selection').first().toJSON();

                /** Update the hidden 'branding[header_logo]' field with the ID of the selected logo */
                clicked_parent.find('input[name="branding[header_logo]"]', '#dd-custom-branding-metabox').val(media_attachment.id);

            });

        }

        /** Finally, open the media manager */
        $('.attachment-details').remove(); /* or .hide(), there might be hidden inputs */
        dd_media_frame.open();

    });

});

Another option is to find in your files attachment-details and coment/remove the container

发布评论

评论列表(0)

  1. 暂无评论