WordPress.org

Make WordPress Core

Changeset 38166


Ignore:
Timestamp:
07/27/2016 04:26:22 PM (4 years ago)
Author:
westonruter
Message:

Customize: Prevent customize-preview-widgets JS errors in preview if a sidebar is registered with empty before_widget/after_widget params.

Selective refresh will not be available for widgets when they lack these params, so previewing will fallback to full page refreshes. Sidebars registered as such should be rare so this accounts for an edge case.

Fixes #37478.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/js/customize-preview-widgets.js

    r37322 r38166  
    377377                );
    378378
     379                // Handle rare case where before_widget and after_widget are empty.
     380                if ( ! widgetContainerElement[0] ) {
     381                    return;
     382                }
     383
    379384                widgetContainerElement.attr( 'data-customize-partial-id', widgetPartial.id );
    380385                widgetContainerElement.attr( 'data-customize-partial-type', 'widget' );
     
    522527
    523528            emptyWidget = $( widgetTpl );
    524             widgetSelector = emptyWidget.prop( 'tagName' );
    525             widgetClasses = emptyWidget.prop( 'className' );
     529            widgetSelector = emptyWidget.prop( 'tagName' ) || '';
     530            widgetClasses = emptyWidget.prop( 'className' ) || '';
     531
     532            // Prevent a rare case when before_widget, before_title, after_title and after_widget is empty.
     533            if ( ! widgetClasses ) {
     534                return;
     535            }
    526536
    527537            // Remove class names that incorporate the string formatting placeholders %1$s and %2$s.
    528538            widgetClasses = widgetClasses.replace( /\S*%[12]\$s\S*/g, '' );
    529539            widgetClasses = widgetClasses.replace( /^\s+|\s+$/g, '' );
    530 
    531             // Prevent a rare case when before_widget, before_title, after_title and after_widget is empty.
    532             if ( ! widgetClasses ) {
    533                 return;
    534             }
    535 
    536             if ( widgetClasses ) {
    537                 widgetSelector += '.' + widgetClasses.split( /\s+/ ).join( '.' );
    538             }
     540            widgetSelector += '.' + widgetClasses.split( /\s+/ ).join( '.' );
    539541            self.widgetSelectors.push( widgetSelector );
    540542        });
Note: See TracChangeset for help on using the changeset viewer.