How to setup a [add media] button, with:
- proper wordpress [media] UI 
- has size and alignments UI in popup right hand side 
- can custom popup title and button 
- size and alignments arguments can send back to be use 
How to setup a [add media] button, with:
proper wordpress [media] UI
has size and alignments UI in popup right hand side
can custom popup title and button
size and alignments arguments can send back to be use
 On
                        
                            
                        
                        
                            On
                            
                                                    
                    
                This way you can call the new media uploader with custom title and button and right side bar.
var custom_uploader;
jQuery('#fileform').on('click','.select-files', function(e) {
    var button = jQuery(this);
    custom_uploader = wp.media.frames.file_frame = wp.media({
        title: 'Choose File',
        library: {
            author: userSettings.uid // specific user-posted attachment
        },
        button: {
            text: 'Choose File'
        },
        multiple: false
    });
    //When a file is selected, grab the URL and set it as the text field's value
    custom_uploader.on('select', function() {
        attachment = custom_uploader.state().get('selection').first().toJSON();
        console.log(attachment.url);
        console.log(attachment.id); // use them the way you want
    });
    //Open the uploader dialog
    // Set post id
    wp.media.model.settings.post.id = jQuery('#post_ID').val();
    custom_uploader.open();
});
 On
                        
                            
                        
                        
                            On
                            
                                                    
                    
                I would like to add to ZAC's option 4 because when I used his code, the image src="" was missing.
Here is the fix
                if ( 'image' === obj_attachment.type ) {
                html = wp.media.string.image( display );
                _.each({
                align: 'align',
                size:  'image-size',
                alt:   'image_alt'
                }, function( option, prop ) {
                if ( display[ prop ] )
                    options[ option ] = display[ prop ];
                });
                html = wp.media.string.image( display, obj_attachment );
            } 
 On
                        
                            
                        
                        
                            On
                            
                                                    
                    
                Check this link -> https://github.com/phpcodingmaster/WordPress-Media-Modal-Image-Uploads
It will show you how to:
Tested with WordPress Version 6.0
Just try to cover most solutions:
use
tb_show("", "media-upload.php?type=image&TB_iframe=true");andwindow.send_to_editorproblem: has no standard wp.media UI
in js code:
use
wp.media({frame: 'post'})problem: cannot custom UI elements, such as: title, button
in js code:
use
wp.media.editorwithwp.media.editor.open( editor_id )problem: cannot custom UI elements, such as: title, button
in js code: https://wordpress.stackexchange.com/questions/75808/using-wordpress-3-5-media-uploader-in-meta-box#75823
use
wp.mediawith rewritewp.media.controller.Libraryand retrieveattachmentinselectproblem: complicated ..., but once you understand it, it all make sense, and it is my finial solution
in js code: