There are some existing questions that discuss how to add fields to the gallery dialog box and get those into the short code.

What I want to be able to do is facilitate editing an existing short code by pulling the current value from the short code and that value appear in the right field. My code so far is

( function( $ ) {
    var media = wp.media;
    // Wrap the render() function to append controls
    media.view.Settings.Gallery = media.view.Settings.Gallery.extend({
        render: function() {
            media.view.Settings.prototype.render.apply( this, arguments );

            // Append the custom template
            this.$el.append( media.template( 'lf-advanced-gallery-setting' ) );
            media.gallery.defaults.cellPosition = 'left';

            this.update.apply( this, ['cellPosition'] );
            return this;
    } );
} )( jQuery );

And the template is

<script type="text/html" id="tmpl-lf-advanced-gallery-setting">
    <h3>Advanced Gallery Settings</h3>
    <label class="setting">
            <span>Cell Position</span>
            <select class='cellPosition' data-setting='cellPosition' name='cellPosition'>debugger;
                <option value="center" <#if( 'center' == wp.media.galleryDefaults.cellPosition) {#>selected='selected'<#}#>>center</option>
                <option value="left" <# if( 'left' == wp.media.galleryDefaults.cellPosition) {#>selected='selected'<#}#>>left</option>
                <option value="right" <# if( 'right' == wp.media.galleryDefaults.cellPosition) {#>selected='selected'<#}#>>right</option>
<?php //Silence is golden

These two chunks are added in the appropriate hooks (because I get `[gallery cellPosition-'left'] for instance) but I'm not sure how to get the right values back on edit.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.