programing

wp.mce.views gallery 재정의 기본 'slot-slot' 템플릿

codeshow 2023. 9. 14. 23:44
반응형

wp.mce.views gallery 재정의 기본 'slot-slot' 템플릿

4.2 이전 버전에서는 다음 코드로 기본 MCE 갤러리 템플릿을 재정의할 수 있었습니다.

var galleryview = wp.mce.views.get('gallery');
galleryview.getContent = function(){
  this.template = media.template( 'editor-gallery-dtbaker-flexslider' );
  return this.template(this.shortcode.attrs.named);
}

이것은 더이상 작동하지 않습니다.기본 '갤러리' 보기를 재등록하지 않고 무시할 수 있는 방법이 있습니까?이것은 (mce-view.js에서 기본 코드를 복사하고 수정함으로써) 작동하지만 전체 뷰를 다시 등록하는 것보다 더 나은 방법이 있을 것이라고 생각합니다.

이것은 mce view rewrite 후에 가능합니까?https://core.trac.wordpress.org/ticket/31412

4.2에서 작동하는 코드는 다음과 같습니다.

add_action( 'admin_print_footer_scripts', 'my_admin_footer_scripts', 100 );
function my_admin_footer_scripts(){ ?>
<script type="text/javascript">
( function( $ ) {
// start code copied from mce-view.js
var postID = $( '#post_ID' ).val() || 0;
var custom_gallery = _.extend( {}, {

    edit: function( text, update ) {
        var media = wp.media[ this.type ],
            frame = media.edit( text );

        this.pausePlayers && this.pausePlayers();

        _.each( this.state, function( state ) {
            frame.state( state ).on( 'update', function( selection ) {
                update( media.shortcode( selection ).string() );
            } );
        } );

        frame.on( 'close', function() {
            frame.detach();
        } );

        frame.open();
    },
    state: [ 'gallery-edit' ],
    template: wp.media.template( 'editor-gallery' ),

    initialize: function() {
        var attachments = wp.media.gallery.attachments( this.shortcode, postID ),
            attrs = this.shortcode.attrs.named,
            self = this;

        if(typeof attrs.slider != 'undefined'){
            switch(attrs.slider){
                case 'flexslider':
                    this.template = wp.media.template( 'editor-gallery-dtbaker-flexslider' );
                    break;
                case 'flex':
                    this.template = wp.media.template( 'editor-gallery-dtbaker-flex' );
                    break;
                default:
                // leave the existing template (editor-gallery)
            }
        }
        attachments.more()
            .done( function() {
                attachments = attachments.toJSON();
                _.each( attachments, function( attachment ) {
                    if ( attachment.sizes ) {
                        if ( attrs.size && attachment.sizes[ attrs.size ] ) {
                            attachment.thumbnail = attachment.sizes[ attrs.size ];
                        } else if ( attachment.sizes.thumbnail ) {
                            attachment.thumbnail = attachment.sizes.thumbnail;
                        } else if ( attachment.sizes.full ) {
                            attachment.thumbnail = attachment.sizes.full;
                        }
                    }
                } );
                self.render( self.template( {
                    attachments: attachments,
                    columns: attrs.columns ? parseInt( attrs.columns, 10 ) : wp.media.galleryDefaults.columns
                } ) );
            } )
            .fail( function( jqXHR, textStatus ) {
                self.setError( textStatus );
            } );
    }
} );
wp.mce.views.unregister('gallery');
wp.mce.views.register('gallery',custom_gallery);
})(jQuery);
<?php }

저도 이것을 시도해 보았지만, 할 수 없었습니다.

            var dtbaker_gallery = wp.mce.views.get('gallery');
            dtbaker_gallery = dtbaker_gallery.extend({
                template: wp.media.template( 'editor-gallery-dtbaker-flexslider' )
            });

언급URL : https://stackoverflow.com/questions/31552084/wp-mce-views-gallery-override-default-editor-gallery-template

반응형