mirror of
https://github.com/WordPress/WordPress.git
synced 2026-06-19 07:37:07 +00:00
Icons: Enforce strict name validation in the register method.
Reject icon names that use uppercase letters, that lack a namespace prefix, or that have already been registered. Add tests covering these cases. Props im3dabasia1, mukesh27, wildworks. See #64847. Built from https://develop.svn.wordpress.org/trunk@62515 git-svn-id: http://core.svn.wordpress.org/trunk@61796 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -115,6 +115,34 @@ class WP_Icons_Registry {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( preg_match( '/[A-Z]/', $icon_name ) ) {
|
||||
_doing_it_wrong(
|
||||
__METHOD__,
|
||||
__( 'Icon names must not contain uppercase characters.' ),
|
||||
'7.1.0'
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
$name_matcher = '/^[a-z][a-z0-9-]*\/[a-z][a-z0-9-]*$/';
|
||||
if ( ! preg_match( $name_matcher, $icon_name ) ) {
|
||||
_doing_it_wrong(
|
||||
__METHOD__,
|
||||
__( 'Icon names must contain a namespace prefix. Example: my-plugin/my-custom-icon' ),
|
||||
'7.1.0'
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $this->is_registered( $icon_name ) ) {
|
||||
_doing_it_wrong(
|
||||
__METHOD__,
|
||||
__( 'Icon is already registered.' ),
|
||||
'7.1.0'
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
$allowed_keys = array_fill_keys( array( 'label', 'content', 'filePath' ), 1 );
|
||||
foreach ( array_keys( $icon_properties ) as $key ) {
|
||||
if ( ! array_key_exists( $key, $allowed_keys ) ) {
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '7.1-alpha-62514';
|
||||
$wp_version = '7.1-alpha-62515';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
||||
Reference in New Issue
Block a user