Make WordPress Core


Ignore:
Timestamp:
09/12/2017 07:02:49 AM (7 years ago)
Author:
westonruter
Message:

Customize: Add global notifications area.

  • Displays an error notification in the global area when a save attempt is rejected due to invalid settings. An error notification is also displayed when saving fails due to a network error or server error.
  • Introduces wp.customize.Notifications subclass of wp.customize.Values to contain instances of wp.customize.Notification and manage their rendering into a container.
  • Exposes the global notification area as wp.customize.notifications collection instance.
  • Updates the notifications object on Control to use Notifications rather than Values and to re-use the rendering logic from the former. The old Control#renderNotifications method is deprecated.
  • Allows notifications to be dismissed by instantiating them with a dismissible property.
  • Allows wp.customize.Notification to be extended with custom templates and render functions.
  • Triggers a removed event on wp.customize.Values instances _after_ a value has been removed from the collection.

Props delawski, westonruter, karmatosed, celloexpressions, Fab1en, melchoyce, Kelderic, afercia, adamsilverstein.
See #34893, #39896.
Fixes #35210, #31582, #37727, #37269.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-customize-manager.php

    r41372 r41374  
    349349        add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_control_scripts' ) );
    350350
    351         // Render Panel, Section, and Control templates.
     351        // Render Common, Panel, Section, and Control templates.
    352352        add_action( 'customize_controls_print_footer_scripts', array( $this, 'render_panel_templates' ), 1 );
    353353        add_action( 'customize_controls_print_footer_scripts', array( $this, 'render_section_templates' ), 1 );
     
    23562356            $response = array(
    23572357                'setting_validities' => $setting_validities,
    2358                 'message' => sprintf( _n( 'There is %s invalid setting.', 'There are %s invalid settings.', $invalid_setting_count ), number_format_i18n( $invalid_setting_count ) ),
     2358                /* translators: placeholder is number of invalid settings */
     2359                'message' => sprintf( _n( 'Unable to save due to %s invalid setting.', 'Unable to save due to %s invalid settings.', $invalid_setting_count ), number_format_i18n( $invalid_setting_count ) ),
    23592360            );
    23602361            return new WP_Error( 'transaction_fail', '', $response );
     
    31843185            $control->print_template();
    31853186        }
     3187
     3188        ?>
     3189        <script type="text/html" id="tmpl-customize-notification">
     3190            <li class="notice notice-{{ data.type || 'info' }} {{ data.alt ? 'notice-alt' : '' }} {{ data.dismissible ? 'is-dismissible' : '' }}" data-code="{{ data.code }}" data-type="{{ data.type }}">
     3191                {{{ data.message || data.code }}}
     3192                <# if ( data.dismissible ) { #>
     3193                    <button type="button" class="notice-dismiss"><span class="screen-reader-text"><?php _e( 'Dismiss' ); ?></span></button>
     3194                <# } #>
     3195            </li>
     3196        </script>
     3197
     3198        <?php
     3199        /* The following template is obsolete in core but retained for plugins. */
    31863200        ?>
    31873201        <script type="text/html" id="tmpl-customize-control-notifications">
Note: See TracChangeset for help on using the changeset viewer.