[wp-trac] [WordPress Trac] #37281: Allow non-error notifications to be set for Customizer settings from PHP
WordPress Trac
noreply at wordpress.org
Mon Jul 4 22:46:30 UTC 2016
#37281: Allow non-error notifications to be set for Customizer settings from PHP
-------------------------+-----------------------------
Reporter: westonruter | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Customize | Version:
Severity: normal | Keywords:
Focuses: |
-------------------------+-----------------------------
An API adding notifications to Customizer settings was added in #34893. In
JS a notification can be added of type `error`, `warning`, `info`, and
custom. In PHP, however, only `error` notifications can be added to a
setting, and this is done by returning `WP_Error` from a validation
routing (or sanitization routine). It may be useful to allow other kinds
of notifications to be added via PHP as well. This would likely require
adding a `WP_Customize_Setting::$notifications` collection with a
`WP_Customize_Setting::add_notification()` and
`WP_Customize_Setting::remove_notification()` to provide a similar API in
PHP for the general notifications API in JS. It seems clear that non-error
notifications shouldn't be added by returning `WP_Error` instances from
validation routines, but that the notifications could be added inside of
such routines, for example:
{{{#!php
class My_Setting extends WP_Customize_Setting {
function validate( $value ) {
$validity = parent::validate( $value );
if ( strlen( $value ) > 20 ) {
$this->add_notification( array(
'type' => 'warning',
'code' => 'long_value',
'message' => __( 'This is a long value!' ),
) );
}
}
}
}}}
The non-error notifications could be sent back as part of full refresh and
selective refresh responses in a similar way that error notifications are
sent back and updated into the JS models.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/37281>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list