michaeluno / admin-page-framework

Facilitates WordPress plugin and theme development.
http://admin-page-framework.michaeluno.jp/
Other
338 stars 71 forks source link

Wordpress 4.0: Image-Select-Field Problem #125

Closed patrickf0 closed 10 years ago

patrickf0 commented 10 years ago

Hi there,

with the new WP 4.0 version the image select button is not working.

So far I do not found any other problems...

michaeluno commented 10 years ago

Thanks for the report! I'll see how it can be fixed.

patrickf0 commented 10 years ago

Same for File Selection fields...

michaeluno commented 10 years ago

It seems it causes the error "Uncaught TypeError: Cannot read property 'metadata' of undefined" when the button is pressed.

uncaught typeerror

I don't know what causes it. Maybe the order of jQuery related files has changed or something. I haven't looked into it yet.

The link custom field type does not cause this error so I may change it to the way like the button of the link custom field does.

michaeluno commented 10 years ago

It seems it is nothing to do with how the framework handles the button press event.

After enabling SCRIPT_DEBUG, I've found the part that causes the error in .../wp-includes/js/media-views.js in WordPress v4.0.

uncaught_typeerror_02

The initialize() method of the media.controller.Embed object has changed and it seem to be the cause.

In WordPress v4.0, https://github.com/WordPress/WordPress/blob/4.0/wp-includes/js/media-views.js#L1413-L1419

        initialize: function(options) {
            this.metadata = options.metadata;
            this.debouncedScan = _.debounce( _.bind( this.scan, this ), this.sensitivity );
            this.props = new Backbone.Model( this.metadata || { url: '' });
            this.props.on( 'change:url', this.debouncedScan, this );
            this.props.on( 'change:url', this.refresh, this );
            this.on( 'scan', this.scanImage, this );
        },

In WordPress 3.9.2, https://github.com/WordPress/WordPress/blob/3.9.2/wp-includes/js/media-views.js#L1344-L1350

        initialize: function() {
            this.debouncedScan = _.debounce( _.bind( this.scan, this ), this.sensitivity );
            this.props = new Backbone.Model({ url: '' });
            this.props.on( 'change:url', this.debouncedScan, this );
            this.props.on( 'change:url', this.refresh, this );
            this.on( 'scan', this.scanImage, this );
        },
michaeluno commented 10 years ago

It seems this is the part which needs to be modified: https://github.com/michaeluno/admin-page-framework/blob/3.1.5/development/_view/AdminPageFramework_FieldType/AdminPageFramework_FieldType_Base.php#L314-L363, especially the following line,

 // Embed states.
new wp.media.controller.Embed(),
michaeluno commented 10 years ago

Updated the 3.1.6b branch: https://github.com/michaeluno/admin-page-framework/tree/3.1.6b Download. https://github.com/michaeluno/admin-page-framework/archive/3.1.6b.zip

It includes an update for another issue (https://github.com/michaeluno/admin-page-framework/issues/100) that affects the behavior of repeating form sections. So anybody using repeatable sections, please test if it does not break anything.